Class: Stylish::Declarations
- Inherits:
-
Array
- Object
- Array
- Stylish::Declarations
- Includes:
- Formattable
- Defined in:
- lib/stylish/core.rb
Overview
Declarations subclasses Array so that whenever #join is called, the instance’s format attribute will be used as the join string, rather than the empty string.
Instance Attribute Summary
Attributes included from Formattable
Instance Method Summary collapse
-
#initialize(*args) ⇒ Declarations
constructor
The allowed format is any string consisting only of whitespace characters, including newline.
-
#join ⇒ Object
The format attribute is always used as the separator when joining the elements of a Declarations object.
-
#to_s(symbols = {}) ⇒ Object
Returns a string by converting each element to a string, separated by the format attribute.
Constructor Details
#initialize(*args) ⇒ Declarations
The allowed format is any string consisting only of whitespace characters, including newline. The default format string is a single space, which is probably the most common choice in hand-written CSS.
287 288 289 290 |
# File 'lib/stylish/core.rb', line 287 def initialize(*args) accept_format(/^\s*$/m, " ") super end |
Instance Method Details
#join ⇒ Object
The format attribute is always used as the separator when joining the elements of a Declarations object.
294 295 296 |
# File 'lib/stylish/core.rb', line 294 def join super(@format) end |
#to_s(symbols = {}) ⇒ Object
Returns a string by converting each element to a string, separated by the format attribute. Assuming that its contents are indeed Declaration objects, this will invoke their own #to_s method and generating correct CSS code.
302 303 304 305 306 |
# File 'lib/stylish/core.rb', line 302 def to_s(symbols = {}) self.inject("") do |a, o| a << (a.empty? ? "" : @format) << o.to_s(symbols) end end |