Class: Rundoc::CodeCommand::PrintERBRunner
- Inherits:
-
Object
- Object
- Rundoc::CodeCommand::PrintERBRunner
- Defined in:
- lib/rundoc/code_command/print/erb.rb
Instance Attribute Summary collapse
-
#contents ⇒ Object
readonly
Returns the value of attribute contents.
Instance Method Summary collapse
- #call(env = {}) ⇒ Object
-
#initialize(user_args:, render_command:, render_result:, io: nil, contents: nil) ⇒ PrintERBRunner
constructor
A new instance of PrintERBRunner.
- #render ⇒ Object
- #render_before? ⇒ Boolean
- #render_command? ⇒ Boolean
- #render_result? ⇒ Boolean
- #to_md(env) ⇒ Object
Constructor Details
#initialize(user_args:, render_command:, render_result:, io: nil, contents: nil) ⇒ PrintERBRunner
Returns a new instance of PrintERBRunner.
18 19 20 21 22 23 24 |
# File 'lib/rundoc/code_command/print/erb.rb', line 18 def initialize(user_args:, render_command:, render_result:, io: nil, contents: nil) @line = user_args.line @binding = RUNDOC_ERB_BINDINGS[user_args.binding_name] @render_command = render_command @render_result = render_result @contents = contents.dup if contents && !contents.empty? end |
Instance Attribute Details
#contents ⇒ Object (readonly)
Returns the value of attribute contents.
16 17 18 |
# File 'lib/rundoc/code_command/print/erb.rb', line 16 def contents @contents end |
Instance Method Details
#call(env = {}) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/rundoc/code_command/print/erb.rb', line 46 def call(env = {}) if render_before? "" else render end end |
#render ⇒ Object
42 43 44 |
# File 'lib/rundoc/code_command/print/erb.rb', line 42 def render @render ||= ERB.new([@line, contents].compact.join("\n")).result(@binding) end |
#render_before? ⇒ Boolean
54 55 56 |
# File 'lib/rundoc/code_command/print/erb.rb', line 54 def render_before? !render_command? && render_result? end |
#render_command? ⇒ Boolean
26 27 28 |
# File 'lib/rundoc/code_command/print/erb.rb', line 26 def render_command? @render_command end |
#render_result? ⇒ Boolean
30 31 32 |
# File 'lib/rundoc/code_command/print/erb.rb', line 30 def render_result? @render_result end |
#to_md(env) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/rundoc/code_command/print/erb.rb', line 34 def to_md(env) if render_before? env[:before] << render end "" end |