Class: SilkLayout::CSS::Parser
- Inherits:
-
Object
- Object
- SilkLayout::CSS::Parser
- Defined in:
- lib/silk_layout/css/parser.rb
Instance Attribute Summary collapse
-
#page_rules ⇒ Object
readonly
Returns the value of attribute page_rules.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Class Method Summary collapse
- .parse_all(stylesheets, media: :print) ⇒ Object
- .parse_page_rules(stylesheets, media: :print) ⇒ Object
- .parse_stylesheets(stylesheets, media: :print) ⇒ Object
Instance Method Summary collapse
-
#initialize(media:) ⇒ Parser
constructor
A new instance of Parser.
- #parse_nodes(nodes) ⇒ Object
Constructor Details
#initialize(media:) ⇒ Parser
Returns a new instance of Parser.
28 29 30 31 32 33 34 |
# File 'lib/silk_layout/css/parser.rb', line 28 def initialize(media:) @media = media.to_s.downcase @rules = [] @page_rules = [] @order = 0 @page_order = 0 end |
Instance Attribute Details
#page_rules ⇒ Object (readonly)
Returns the value of attribute page_rules.
8 9 10 |
# File 'lib/silk_layout/css/parser.rb', line 8 def page_rules @page_rules end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
8 9 10 |
# File 'lib/silk_layout/css/parser.rb', line 8 def rules @rules end |
Class Method Details
.parse_all(stylesheets, media: :print) ⇒ Object
10 11 12 |
# File 'lib/silk_layout/css/parser.rb', line 10 def self.parse_all(stylesheets, media: :print) parse_stylesheets(stylesheets, media: media).rules end |
.parse_page_rules(stylesheets, media: :print) ⇒ Object
14 15 16 |
# File 'lib/silk_layout/css/parser.rb', line 14 def self.parse_page_rules(stylesheets, media: :print) parse_stylesheets(stylesheets, media: media).page_rules end |
.parse_stylesheets(stylesheets, media: :print) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/silk_layout/css/parser.rb', line 18 def self.parse_stylesheets(stylesheets, media: :print) parser = new(media: media) stylesheets.each do |css| parser.parse_nodes(Crass.parse(css)) end parser end |
Instance Method Details
#parse_nodes(nodes) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/silk_layout/css/parser.rb', line 36 def parse_nodes(nodes) nodes.each do |node| case node[:node] when :style_rule append_style_rules(node) when :at_rule append_at_rule(node) end end end |