Class: Hamlit::Compiler::ChildrenCompiler

Inherits:
Object
  • Object
show all
Defined in:
lib/hamlit/compiler/children_compiler.rb

Instance Method Summary collapse

Constructor Details

#initializeChildrenCompiler

Returns a new instance of ChildrenCompiler.


5
6
7
# File 'lib/hamlit/compiler/children_compiler.rb', line 5

def initialize
  @lineno = 1
end

Instance Method Details

#compile(node, &block) ⇒ Object


9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/hamlit/compiler/children_compiler.rb', line 9

def compile(node, &block)
  temple = [:multi]
  return temple if node.children.empty?

  temple << :whitespace if prepend_whitespace?(node)
  node.children.each do |n|
    rstrip_whitespace!(temple) if nuke_prev_whitespace?(n)
    insert_newlines!(temple, n)
    temple << yield(n)
    temple << :whitespace if insert_whitespace?(n)
  end
  rstrip_whitespace!(temple) if nuke_inner_whitespace?(node)
  confirm_whitespace(temple)
end