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, RUNDOC_DEFAULT_ERB_BINDING, RUNDOC_ERB_BINDINGS

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: RUNDOC_DEFAULT_ERB_BINDING) ⇒ PrintERB

Returns a new instance of PrintERB.



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

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

Instance Method Details

#call(env = {}) ⇒ Object



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

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

#renderObject



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

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

#render_before?Boolean

Returns:

  • (Boolean)


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

def render_before?
  !render_command? && render_result?
end

#to_md(env) ⇒ Object



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

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

  ""
end