Class: Deadfire::CssGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/deadfire/css_generator.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(tree) ⇒ CssGenerator

Returns a new instance of CssGenerator.



6
7
8
9
# File 'lib/deadfire/css_generator.rb', line 6

def initialize(tree)
  @tree = tree
  @output = StringIO.new # TODO: write to file instead of string buffer in temp folder
end

Instance Method Details

#generateObject



11
12
13
14
# File 'lib/deadfire/css_generator.rb', line 11

def generate
  @tree.accept(self)
  @output.string
end

#visit_apply_node(node) ⇒ Object



57
58
59
# File 'lib/deadfire/css_generator.rb', line 57

def visit_apply_node(node)
  @output << node.node.lexeme
end

#visit_at_rule_node(node) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/deadfire/css_generator.rb', line 20

def visit_at_rule_node(node)
  @output << node.at_keyword.lexeme
  node.value.each do |value|
    @output << value.lexeme
  end

  if node.block
    visit_block_node(node.block)
  end
end

#visit_block_node(node) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/deadfire/css_generator.rb', line 38

def visit_block_node(node)
  node.declarations.each do |declaration|
    case declaration
    when ApplyNode
      visit_apply_node(declaration)
    when FrontEnd::BlockNode
      visit_block_node(declaration)
    when FrontEnd::AtRuleNode
      visit_at_rule_node(declaration)
    else
      @output << declaration.lexeme
    end
  end
end

#visit_comment_node(node) ⇒ Object



61
62
63
# File 'lib/deadfire/css_generator.rb', line 61

def visit_comment_node(node)
  @output << node.comment.lexeme unless Deadfire.configuration.compressed
end

#visit_newline_node(node) ⇒ Object



53
54
55
# File 'lib/deadfire/css_generator.rb', line 53

def visit_newline_node(node)
  @output << node.text
end

#visit_ruleset_node(node) ⇒ Object



31
32
33
34
35
36
# File 'lib/deadfire/css_generator.rb', line 31

def visit_ruleset_node(node)
  @output << node.selector.selector
  @output << " "

  visit_block_node(node.block)
end

#visit_stylesheet_node(node) ⇒ Object



16
17
18
# File 'lib/deadfire/css_generator.rb', line 16

def visit_stylesheet_node(node)
  node.statements.each { |child| child.accept(self) }.join("\n")
end