Module: CSS::Element
- Defined in:
- lib/html_css_decorator.rb
Instance Attribute Summary collapse
-
#declarations ⇒ Object
Returns the value of attribute declarations.
-
#parser ⇒ Object
Returns the value of attribute parser.
-
#rules ⇒ Object
Returns the value of attribute rules.
-
#ruleset ⇒ Object
Returns the value of attribute ruleset.
Instance Method Summary collapse
- #add_declaration!(declaration) ⇒ Object (also: #[]=)
- #add_rule!(rule) ⇒ Object
- #duplicate?(decl) ⇒ Boolean
- #merge_declarations(selector) ⇒ Object
-
#merge_declarations! ⇒ Object
merge declarations by specificity.
- #merge_style! ⇒ Object
Instance Attribute Details
#declarations ⇒ Object
Returns the value of attribute declarations.
11 12 13 |
# File 'lib/html_css_decorator.rb', line 11 def declarations @declarations end |
#parser ⇒ Object
Returns the value of attribute parser.
8 9 10 |
# File 'lib/html_css_decorator.rb', line 8 def parser @parser end |
#rules ⇒ Object
Returns the value of attribute rules.
10 11 12 |
# File 'lib/html_css_decorator.rb', line 10 def rules @rules end |
#ruleset ⇒ Object
Returns the value of attribute ruleset.
9 10 11 |
# File 'lib/html_css_decorator.rb', line 9 def ruleset @ruleset end |
Instance Method Details
#add_declaration!(declaration) ⇒ Object Also known as: []=
20 21 22 23 24 25 |
# File 'lib/html_css_decorator.rb', line 20 def add_declaration!(declaration) return if !declaration @declarations ||= {} dec = declaration.kind_of?(Array) ? declaration[1] : declaration declarations[dec.property] = dec end |
#add_rule!(rule) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/html_css_decorator.rb', line 13 def add_rule!(rule) @parser ||= CssParserMaster::Parser.new @declarations = {} parser.add_block! rule end |
#duplicate?(decl) ⇒ Boolean
57 58 59 |
# File 'lib/html_css_decorator.rb', line 57 def duplicate?(decl) declarations.select{|d| d.property == decl.property}.empty? end |
#merge_declarations(selector) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/html_css_decorator.rb', line 28 def merge_declarations(selector) @order = 0 selector.each_declaration do |decl| add_declaration!(decl) end end |
#merge_declarations! ⇒ Object
merge declarations by specificity
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/html_css_decorator.rb', line 46 def merge_declarations! !parser and return @order = 0 @declarations ||= {} parser.selector_declarations do |sel, decl| add_declaration!(decl) end end |
#merge_style! ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/html_css_decorator.rb', line 36 def merge_style! style = attribute('style') if style s = style.to_s + ';' selector = CssParserMaster::Selector.new(name, s, 99999) merge_declarations(selector) end end |