Class: Rundoc::CodeCommand::PrintERB

Inherits:
Rundoc::CodeCommand show all
Defined in:
lib/rundoc/code_command/print/erb.rb

Constant Summary

Constants inherited from Rundoc::CodeCommand

NEWLINE

Instance Attribute Summary

Attributes inherited from Rundoc::CodeCommand

#command, #contents, #keyword, #original_args, #render_command, #render_result

Instance Method Summary collapse

Methods inherited from Rundoc::CodeCommand

#hidden?, #not_hidden?, #push

Constructor Details

#initialize(line = nil, binding: "default") ⇒ PrintERB

Returns a new instance of PrintERB.



17
18
19
20
# File 'lib/rundoc/code_command/print/erb.rb', line 17

def initialize(line = nil, binding: "default")
  @line = line
  @binding = RUNDOC_ERB_BINDINGS[binding]
end

Instance Method Details

#call(erb = {}) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/rundoc/code_command/print/erb.rb', line 34

def call(erb = {})
  if render_before?
    ""
  else
    render
  end
end

#renderObject



30
31
32
# File 'lib/rundoc/code_command/print/erb.rb', line 30

def render
  @render ||= ERB.new([@line, contents].compact.join("\n")).result(@binding)
end

#render_before?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/rundoc/code_command/print/erb.rb', line 42

def render_before?
  !render_command? && render_result?
end

#to_md(env) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/rundoc/code_command/print/erb.rb', line 22

def to_md(env)
  if render_before?
    env[:before] << render
  end

  ""
end