Created
May 14, 2013 00:41
-
-
Save clee704/5572740 to your computer and use it in GitHub Desktop.
Convert CSS URI values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Parse CSS URI values according to http://www.w3.org/TR/CSS21/syndata.html#uri | |
URI_PATTERN = / | |
url\( # 'url(' | |
[ \t\n\r\f]* # optional white space | |
( | |
# double quoted URI | |
( | |
(?<quote>") # an optional double quote | |
(?<str>([^"\\]|\\.)*?) # URI | |
" | |
) | |
# or single quoted | |
| ( | |
(?<quote>') # an optional single quote | |
(?<str>([^'\\]|\\.)*?) # URI | |
' | |
) | |
# or unquoted | |
| (?<str> | |
([^() \t\n\r\f'"\\]|\\.)* # parentheses, white space characters, | |
# single quotes, and double quotes must be | |
# escaped | |
) | |
) | |
[ \t\n\r\f]* # optional white space | |
\) # ')' | |
/x | |
data = 'load css file here' | |
data.gsub! URI_PATTERN do |match| | |
# TODO do something here | |
puts $~[:quote], $~[:str] | |
'url([PUT SOMETHING HERE])' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment