Class CssParser::RuleSet
In: lib/css_parser/rule_set.rb
Parent: Object

Methods

Constants

RE_ELEMENTS_AND_PSEUDO_ELEMENTS = /((^|[\s\+\>]+)[\w]+|\:(first\-line|first\-letter|before|after))/i   Patterns for specificity calculations
RE_NON_ID_ATTRIBUTES_AND_PSEUDO_CLASSES = /(\.[\w]+)|(\[[\w]+)|(\:(link|first\-child|lang))/i
BACKGROUND_PROPERTIES = ['background-color', 'background-image', 'background-repeat', 'background-position', 'background-size', 'background-attachment']
LIST_STYLE_PROPERTIES = ['list-style-type', 'list-style-position', 'list-style-image']
FONT_STYLE_PROPERTIES = ['font-style', 'font-variant', 'font-weight', 'font-size', 'line-height', 'font-family']
BORDER_STYLE_PROPERTIES = ['border-width', 'border-style', 'border-color']
BORDER_PROPERTIES = ['border', 'border-left', 'border-right', 'border-top', 'border-bottom']
NUMBER_OF_DIMENSIONS = 4
DIMENSIONS = [ ['margin', %w(margin-top margin-right margin-bottom margin-left)], ['padding', %w(padding-top padding-right padding-bottom padding-left)], ['border-color', %w(border-top-color border-right-color border-bottom-color border-left-color)], ['border-style', %w(border-top-style border-right-style border-bottom-style border-left-style)], ['border-width', %w(border-top-width border-right-width border-bottom-width border-left-width)], ]

Attributes

selectors  [R]  Array of selector strings.
specificity  [RW]  Integer with the specificity to use for this RuleSet.

Public Class methods

Public Instance methods

[](property)

Alias for get_value

[]=(property, value)

Alias for add_declaration!

Add a CSS declaration to the current RuleSet.

 rule_set.add_declaration!('color', 'blue')

 puts rule_set['color']
 => 'blue;'

 rule_set.add_declaration!('margin', '0px auto !important')

 puts rule_set['margin']
 => '0px auto !important;'

If the property already exists its value will be over-written.

Create shorthand declarations (e.g. margin or font) whenever possible.

Return all declarations as a string.

Iterate through selectors.

Options

  • force_important — boolean

Example

  ruleset.each_selector do |sel, dec, spec|
    ...
  end

Split shorthand declarations (e.g. margin or font) into their constituent parts.

Get the value of a property

Remove CSS declaration from the current RuleSet.

 rule_set.remove_declaration!('color')

Return the CSS rule set as a string.

[Validate]