| Class | CssParser::Parser |
| In: |
lib/css_parser/parser.rb
|
| Parent: | Object |
All CSS is converted to UTF-8.
When calling Parser#new there are some configuaration options:
| USER_AGENT | = | "Ruby CSS Parser/#{CssParser::VERSION} (https://github.com/premailer/css_parser)" | ||
| STRIP_CSS_COMMENTS_RX | = | /\/\*.*?\*\//m | ||
| STRIP_HTML_COMMENTS_RX | = | /\<\!\-\-|\-\-\>/m | ||
| RE_AT_IMPORT_RULE | = | /\@import\s*(?:url\s*)?(?:\()?(?:\s*)["']?([^'"\s\)]*)["']?\)?([\w\s\,^\]\(\)]*)\)?[;\n]?/ | Initial parsing | |
| MAX_REDIRECTS | = | 3 |
| folded_declaration_cache | [R] | |
| loaded_uris | [R] | Array of CSS files that have been loaded. |
Add a raw block of CSS.
In order to follow +@import+ rules you must supply either a +:base_dir+ or +:base_uri+ option.
Use the +:media_types+ option to set the media type(s) for this block. Takes an array of symbols.
Use the +:only_media_types+ option to selectively follow +@import+ rules. Takes an array of symbols.
css = <<-EOT
body { font-size: 10pt }
p { margin: 0px; }
@media screen, print {
body { line-height: 1.2 }
}
EOT
parser = CssParser::Parser.new
parser.add_block!(css)
Add a CSS rule by setting the selectors, declarations and media_types.
media_types can be a symbol or an array of symbols.
Add a CSS rule by setting the selectors, declarations, filename, offset and media_types.
filename can be a string or uri pointing to the file or url location. offset should be Range object representing the start and end byte locations where the rule was found in the file. media_types can be a symbol or an array of symbols.
Iterate through RuleSet objects.
media_types can be a symbol or an array of symbols.
Iterate through CSS selectors.
media_types can be a symbol or an array of symbols. See RuleSet#each_selector for options.
Get declarations by selector.
media_types are optional, and can be a symbol or an array of symbols. The default value is :all.
find_by_selector('#content')
=> 'font-size: 13px; line-height: 1.2;'
find_by_selector('#content', [:screen, :handheld])
=> 'font-size: 13px; line-height: 1.2;'
find_by_selector('#content', :print)
=> 'font-size: 11pt; line-height: 1.2;'
Returns an array of declarations.
Load a remote CSS file.
You can also pass in file://test.css
See add_block! for options.
Deprecated: originally accepted three params: `uri`, `base_uri` and `media_types`
Check that a path hasn‘t been loaded already
Raises a CircularReferenceError exception if io_exceptions are on, otherwise returns true/false.