Class: Stylish::Declaration
- Inherits:
-
Object
- Object
- Stylish::Declaration
- Includes:
- Formattable
- Defined in:
- lib/stylish/core.rb
Overview
Each Rule may have one or more Declaration objects, and usually has more than one. In a sense, declarations are the business end of stylesheets: they are where the set of elements specified by a rule’s selectors are given their various attributes.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(name, value) ⇒ Declaration
constructor
Each Declaration has a property name and a value.
-
#name ⇒ Object
The property name of the Declaration.
-
#name=(name) ⇒ Object
Property names are CSS identifiers.
-
#to_s(symbols = {}) ⇒ Object
Serialising a declaration produces a name-value pair separated by a colon and terminating with a semicolon, for instance.
Methods included from Formattable
Constructor Details
#initialize(name, value) ⇒ Declaration
Each Declaration has a property name and a value.
260 261 262 263 |
# File 'lib/stylish/core.rb', line 260 def initialize(name, value) self.value = value self.name = name end |
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value.
256 257 258 |
# File 'lib/stylish/core.rb', line 256 def value @value end |
Instance Method Details
#name ⇒ Object
The property name of the Declaration.
266 267 268 |
# File 'lib/stylish/core.rb', line 266 def name @property_name end |
#name=(name) ⇒ Object
Property names are CSS identifiers.
271 272 273 |
# File 'lib/stylish/core.rb', line 271 def name=(name) @property_name = name.to_s end |
#to_s(symbols = {}) ⇒ Object
Serialising a declaration produces a name-value pair separated by a colon and terminating with a semicolon, for instance
declaration = Declaration.new("font-style", "italic")
declaration.to_s # => "font-style:italic;"
Since the formatting can be adjusted via the #format= accessor, the exact spacing of the declaration can be controlled if desired.
288 289 290 291 292 293 294 295 296 |
# File 'lib/stylish/core.rb', line 288 def to_s(symbols = {}) if @value.is_a?(Generate::Variable) || @value.is_a?(Color) value = @value.to_s(symbols) else value = @value.to_s end sprintf(self.class.format, @property_name.to_s, value) end |