Class: Rundoc::CodeCommand::PreErbRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/rundoc/code_command/pre/erb.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_args:, render_command:, render_result:, io:, contents: nil) ⇒ PreErbRunner

Returns a new instance of PreErbRunner.



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rundoc/code_command/pre/erb.rb', line 17

def initialize(user_args:, render_command:, render_result:, io:, contents: nil)
  @line = user_args.line
  @binding = RUNDOC_ERB_BINDINGS[RUNDOC_DEFAULT_ERB_BINDING]
  @code = nil
  @command = nil
  @template = nil
  @render_command = render_command
  @render_result = render_result
  @io = io
  @contents = contents.dup if contents && !contents.empty?
end

Instance Attribute Details

#contentsObject (readonly)

Returns the value of attribute contents.



15
16
17
# File 'lib/rundoc/code_command/pre/erb.rb', line 15

def contents
  @contents
end

#ioObject (readonly)

Returns the value of attribute io.



15
16
17
# File 'lib/rundoc/code_command/pre/erb.rb', line 15

def io
  @io
end

Instance Method Details

#call(env = {}) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/rundoc/code_command/pre/erb.rb', line 64

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



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rundoc/code_command/pre/erb.rb', line 37

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

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

#commandObject



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

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

#render_command?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/rundoc/code_command/pre/erb.rb', line 29

def render_command?
  @render_command
end

#render_result?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/rundoc/code_command/pre/erb.rb', line 33

def render_result?
  @render_result
end

#to_md(env = {}) ⇒ Object



60
61
62
# File 'lib/rundoc/code_command/pre/erb.rb', line 60

def to_md(env = {})
  ""
end