Class: Rundoc::CodeCommand::PreErb

Inherits:
Rundoc::CodeCommand show all
Defined in:
lib/rundoc/code_command/pre/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

#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) ⇒ PreErb

Returns a new instance of PreErb.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/rundoc/code_command/pre/erb.rb', line 5

def initialize(line)
  @line = line
  @binding = RUNDOC_ERB_BINDINGS[RUNDOC_DEFAULT_ERB_BINDING]
  @code = nil
  @command = nil
  @template = nil
  @render_delegate_result = nil
  @render_delegate_command = nil
  # Hide self, pass visibility onto delegate
  @render_result = false
  @render_command = false
end

Instance Method Details

#call(env = {}) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/rundoc/code_command/pre/erb.rb', line 54

def call(env = {})
  # Defer running ERB until as late as possible
  delegate = command
  # Delegate will be executed by the caller working through the stack
  env[:stack].push(delegate)
  ""
end

#codeObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rundoc/code_command/pre/erb.rb', line 27

def code
  @code ||= begin
    vis = +""
    vis += @render_delegate_command ? ">" : "-"
    vis += @render_delegate_result ? ">" : "-"
    code = [@line, @contents]
      .compact
      .reject(&:empty?)
      .join("\n")
    @template = ":::#{vis} #{code}"

    puts "pre.erb: Applying ERB, template:\n#{@template}"
    result = ERB.new(@template).result(@binding)
    puts "pre.erb: ERB result:\n#{result}"
    puts "pre.erb: done, ready to delegate"
    result
  end
end

#commandObject



46
47
48
# File 'lib/rundoc/code_command/pre/erb.rb', line 46

def command
  @command ||= Rundoc::FencedCodeBlock.parse_code_commands(code).first
end

#render_command=(value) ⇒ Object



23
24
25
# File 'lib/rundoc/code_command/pre/erb.rb', line 23

def render_command=(value)
  @render_delegate_command = value
end

#render_result=(value) ⇒ Object

Visibility is injected by the parser, capture it and pass it to the delegate



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

def render_result=(value)
  @render_delegate_result = value
end

#to_md(env = {}) ⇒ Object



50
51
52
# File 'lib/rundoc/code_command/pre/erb.rb', line 50

def to_md(env = {})
  ""
end