Class: Precssious::Rule
- Inherits:
-
Struct
- Object
- Struct
- Precssious::Rule
- Defined in:
- lib/precssious/rule.rb,
lib/precssious/rule.rb
Instance Attribute Summary collapse
-
#selector ⇒ Object
Returns the value of attribute selector.
-
#values ⇒ Object
Returns the value of attribute values.
Instance Method Summary collapse
- #is_hack? ⇒ Boolean
- #raw_selector_string ⇒ Object
- #selector_string ⇒ Object
- #selectors ⇒ Object
- #to_s(context = nil) ⇒ Object
Instance Attribute Details
#selector ⇒ Object
Returns the value of attribute selector
4 5 6 |
# File 'lib/precssious/rule.rb', line 4 def selector @selector end |
#values ⇒ Object
Returns the value of attribute values
4 5 6 |
# File 'lib/precssious/rule.rb', line 4 def values @values end |
Instance Method Details
#is_hack? ⇒ Boolean
21 22 23 |
# File 'lib/precssious/rule.rb', line 21 def is_hack? raw_selector_string =~ /\[[a-z0-9]*\]/ end |
#raw_selector_string ⇒ Object
29 30 31 |
# File 'lib/precssious/rule.rb', line 29 def raw_selector_string selectors.join(', ').gsub(/\s+-/, '') end |
#selector_string ⇒ Object
25 26 27 |
# File 'lib/precssious/rule.rb', line 25 def selector_string raw_selector_string.gsub /\[[a-z0-9]*\] /, '' end |
#selectors ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/precssious/rule.rb', line 33 def selectors reverse, current = selector.split(',').map { |x| x.strip }.partition { |s| s =~ /<>/ } return current unless @context result = [] @context.selectors.map do |cs| current.map { |s| result << "#{cs} #{s}" } end reverse.map do |rs| @context.selectors.map { |cs| result << "#{rs.gsub('<>', '').strip} #{cs}" } end result end |
#to_s(context = nil) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/precssious/rule.rb', line 7 def to_s(context = nil) @context = context r, v = values.partition { |x| Rule === x } result = [] result << "#{selector_string} { #{v.map { |x| x.to_s }.join ' '} }" if v.length > 0 r.each do |nested| result << nested.to_s(self) end result.join "\n" end |