Module: Cataract
- Defined in:
- lib/cataract.rb,
lib/cataract.rb,
lib/cataract/pure.rb,
lib/cataract/rule.rb,
lib/cataract/error.rb,
lib/cataract/at_rule.rb,
lib/cataract/version.rb,
lib/cataract/constants.rb,
lib/cataract/stylesheet.rb,
lib/cataract/declaration.rb,
lib/cataract/media_query.rb,
lib/cataract/pure/parser.rb,
lib/cataract/declarations.rb,
lib/cataract/pure/flatten.rb,
lib/cataract/import_resolver.rb,
lib/cataract/pure/serializer.rb,
lib/cataract/import_statement.rb,
lib/cataract/pure/specificity.rb,
lib/cataract/stylesheet_scope.rb,
lib/cataract/pure/declarations.rb,
lib/cataract/pure/byte_constants.rb,
ext/cataract/cataract.c
Overview
Pure Ruby CSS parser - Byte constants for fast parsing Using getbyte() instead of String#[] to avoid allocating millions of string objects
Defined Under Namespace
Modules: Backends, ImportResolver Classes: AtRule, ColorConversionError, Declaration, Declarations, DepthError, Error, ImportError, ImportStatement, MediaQuery, ParseError, Rule, SizeError, Stylesheet, StylesheetScope
Constant Summary collapse
- IMPLEMENTATION =
backend_const_holder::IMPLEMENTATION
- COMPILE_FLAGS =
backend_const_holder::COMPILE_FLAGS
- NATIVE_EXTENSION_LOADED =
true- PURE_RUBY_LOADED =
true- VERSION =
'0.4.0'- DEFAULT_URI_RESOLVER =
Default URI resolver proc for converting relative URLs to absolute Uses Ruby's URI stdlib to merge base and relative URIs
lambda { |base, relative| require 'uri' URI.parse(base).merge(relative).to_s }.freeze
Class Method Summary collapse
-
.flatten(stylesheet_or_css) ⇒ Stylesheet
Flatten CSS rules according to CSS cascade rules.
-
.parse_css(css, **options) ⇒ Stylesheet
Parse a CSS string into a Stylesheet object.
Class Method Details
.flatten(stylesheet_or_css) ⇒ Stylesheet
This is a module-level convenience method. The same functionality is available
as an instance method: stylesheet.flatten
Flatten CSS rules according to CSS cascade rules.
Takes a Stylesheet or CSS string and flattens all rules according to CSS cascade precedence rules. Returns a new Stylesheet with flattened rules containing the final computed declarations.
Flatten rules (in order of precedence):
- !important declarations win over non-important
- Higher specificity wins
- Later declarations with same specificity and importance win
- Shorthand properties are created from longhand when possible (e.g., margin-* -> margin)
127 128 129 130 |
# File 'lib/cataract.rb', line 127 def flatten(stylesheet_or_css) stylesheet_or_css = Stylesheet.parse(stylesheet_or_css) if stylesheet_or_css.is_a?(String) stylesheet_or_css.flatten end |
.parse_css(css, **options) ⇒ Stylesheet
Parse a CSS string into a Stylesheet object.
This is the main entry point for parsing CSS. It returns a Stylesheet object that can be queried, modified, and serialized.
89 90 91 |
# File 'lib/cataract.rb', line 89 def parse_css(css, **) Stylesheet.parse(css, **) end |