Class: Stylesheet::CssStyleDeclaration
- Inherits:
-
Object
- Object
- Stylesheet::CssStyleDeclaration
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/stylesheet/css_style_declaration.rb
Instance Attribute Summary collapse
-
#declarations ⇒ Object
readonly
Returns the value of attribute declarations.
-
#parent_rule ⇒ Object
readonly
Returns the value of attribute parent_rule.
Instance Method Summary collapse
- #css_text ⇒ Object (also: #to_s)
- #css_text=(css_text) ⇒ Object
-
#initialize(options = {}) ⇒ CssStyleDeclaration
constructor
A new instance of CssStyleDeclaration.
- #method_missing(name, *args) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ CssStyleDeclaration
Returns a new instance of CssStyleDeclaration.
9 10 11 12 13 |
# File 'lib/stylesheet/css_style_declaration.rb', line 9 def initialize(={}) @declarations = Hash.new("") @parent_rule = [:parent_rule] self.css_text = [:css_text] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
Instance Attribute Details
#declarations ⇒ Object (readonly)
Returns the value of attribute declarations.
7 8 9 |
# File 'lib/stylesheet/css_style_declaration.rb', line 7 def declarations @declarations end |
#parent_rule ⇒ Object (readonly)
Returns the value of attribute parent_rule.
7 8 9 |
# File 'lib/stylesheet/css_style_declaration.rb', line 7 def parent_rule @parent_rule end |
Instance Method Details
#css_text ⇒ Object Also known as: to_s
28 29 30 31 |
# File 'lib/stylesheet/css_style_declaration.rb', line 28 def css_text css_text = @declarations_list.join("; ") css_text += ";" if css_text != "" end |
#css_text=(css_text) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/stylesheet/css_style_declaration.rb', line 15 def css_text=(css_text) @declarations_list = [] re = /((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^\)]*?\)|[^};])+)\s*/ css_text.to_s.strip.chomp(";").scan(re).flatten.each do |declaration| next unless declaration.include?(":") property, value = declaration.split(":", 2) @declarations_list << declaration.strip @declarations[property.strip] = parse_value(value.strip) end end |