Module: CSS

Defined in:
lib/css.rb,
lib/css.rb,
lib/css/nodes.rb,
lib/css/token.rb,
lib/css/escape.rb,
lib/css/parser.rb,
lib/css/urange.rb,
lib/css/cascade.rb,
lib/css/nesting.rb,
lib/css/version.rb,
lib/css/selectors.rb,
lib/css/tokenizer.rb,
lib/css/serializer.rb,
lib/css/code_points.rb,
lib/css/token_cursor.rb,
lib/css/media_queries.rb,
lib/css/selectors/nodes.rb,
lib/css/selectors/parser.rb,
lib/css/selectors/matcher.rb,
lib/css/media_queries/nodes.rb,
lib/css/media_queries/parser.rb,
lib/css/selectors/anb_parser.rb,
lib/css/selectors/serializer.rb,
lib/css/media_queries/context.rb,
lib/css/selectors/specificity.rb,
lib/css/media_queries/evaluator.rb

Defined Under Namespace

Modules: CodePoints, Escape, MediaQueries, Nesting, Nodes, Selectors, Serializer, TokenCursor, Urange Classes: Cascade, ParseError, Parser, Position, Token, Tokenizer

Constant Summary collapse

BRACKET_OPEN_CHAR =

Bracket information for the three “simple block” pairs. Indexed both by opening token type (for the parser) and by opening character (for the serializer).

{lbrace: '{', lbracket: '[', lparen: '('}.freeze
BRACKET_CLOSE_TYPE =
{lbrace: :rbrace, lbracket: :rbracket, lparen: :rparen}.freeze
BRACKET_PAIRS =
{'{' => '}', '[' => ']', '(' => ')'}.freeze
VERSION =
'0.1.4'

Class Method Summary collapse

Class Method Details

.cascade(stylesheet, context: MediaQueries::Context.default) ⇒ Object



63
64
65
# File 'lib/css.rb', line 63

def cascade(stylesheet, context: MediaQueries::Context.default)
  Cascade.new(stylesheet, context:)
end

.desugar(stylesheet) ⇒ Object



67
# File 'lib/css.rb', line 67

def desugar(stylesheet) = Nesting.desugar(stylesheet)

.matches?(element, selector) ⇒ Boolean

Returns:

  • (Boolean)


53
# File 'lib/css.rb', line 53

def matches?(element, selector) = Selectors::Matcher.matches?(element, selector)

.media_matches?(query_list, context) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
60
61
# File 'lib/css.rb', line 57

def media_matches?(query_list, context)
  ql = query_list.is_a?(String) ? MediaQueries::Parser.parse(query_list) : query_list
  ctx = context.is_a?(MediaQueries::Context) ? context : MediaQueries::Context.default(**context.to_h)
  MediaQueries::Evaluator.evaluate(ql, ctx)
end

.parse_anb(input) ⇒ Object



49
# File 'lib/css.rb', line 49

def parse_anb(input)           = Selectors::AnBParser.parse(input)

.parse_block_contents(input, **opts) ⇒ Object



40
# File 'lib/css.rb', line 40

def parse_block_contents(input, **opts)        = Parser.parse_block_contents(input, **opts)

.parse_comma_separated_values(input, **opts) ⇒ Object



43
# File 'lib/css.rb', line 43

def parse_comma_separated_values(input, **opts) = Parser.parse_comma_separated_values(input, **opts)

.parse_component_value(input, **opts) ⇒ Object



41
# File 'lib/css.rb', line 41

def parse_component_value(input, **opts)       = Parser.parse_component_value(input, **opts)

.parse_component_values(input, **opts) ⇒ Object



42
# File 'lib/css.rb', line 42

def parse_component_values(input, **opts)      = Parser.parse_component_values(input, **opts)

.parse_declaration(input, **opts) ⇒ Object



39
# File 'lib/css.rb', line 39

def parse_declaration(input, **opts)           = Parser.parse_declaration(input, **opts)

.parse_media_query_list(input) ⇒ Object



55
# File 'lib/css.rb', line 55

def parse_media_query_list(input) = MediaQueries::Parser.parse(input)

.parse_rule(input, **opts) ⇒ Object



38
# File 'lib/css.rb', line 38

def parse_rule(input, **opts)                  = Parser.parse_rule(input, **opts)

.parse_selector(input) ⇒ Object



48
# File 'lib/css.rb', line 48

def parse_selector(input)      = Selectors::Parser.parse_selector(input)

.parse_selector_list(input) ⇒ Object



47
# File 'lib/css.rb', line 47

def parse_selector_list(input) = Selectors::Parser.parse_selector_list(input)

.parse_stylesheet(input, **opts) ⇒ Object Also known as: parse



37
# File 'lib/css.rb', line 37

def parse_stylesheet(input, **opts)            = Parser.parse_stylesheet(input, **opts)

.parse_urange(input) ⇒ Object



45
# File 'lib/css.rb', line 45

def parse_urange(input) = Urange.parse(input)

.serialize(node) ⇒ Object



69
# File 'lib/css.rb', line 69

def serialize(node) = Serializer.serialize(node)

.specificity(selector) ⇒ Object



51
# File 'lib/css.rb', line 51

def specificity(selector) = Selectors::SpecificityCalculator.calculate(selector)

.tokenize(input, **opts) ⇒ Object



36
# File 'lib/css.rb', line 36

def tokenize(input, **opts)                    = Tokenizer.new(input, **opts).tokenize