Class: Hamlit::Block::SilentScriptCompiler

Inherits:
Compiler::SilentScriptCompiler
  • Object
show all
Defined in:
lib/hamlit/block/silent_script_compiler.rb

Overview

Suppress block’s internal rendering result and pass it to [:capture, …] if the silent script is ‘do .. end` block

Constant Summary collapse

BLOCK_REGEX =
/do(\s*\|\s*[^\|]*\s*\|)?\s*\z/

Instance Method Summary collapse

Constructor Details

#initialize(identity) ⇒ SilentScriptCompiler

Returns a new instance of SilentScriptCompiler.



6
7
8
# File 'lib/hamlit/block/silent_script_compiler.rb', line 6

def initialize(identity)
  @identity = identity
end

Instance Method Details

#compile_with_children(node, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/hamlit/block/silent_script_compiler.rb', line 12

def compile_with_children(node, &block)
  if node.value[:text] =~ BLOCK_REGEX
    [:multi,
     [:block, node.value[:text],
      [:multi,
       [:newline],
       [:capture, @identity.generate, yield(node)],
      ],
     ]
    ]
  else
    super
  end
end