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.
31 32 33 34 35 36 37 |
# File 'lib/rundoc/code_command/print/erb.rb', line 31 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.
29 30 31 |
# File 'lib/rundoc/code_command/print/erb.rb', line 29 def contents @contents end |
Instance Method Details
#call(env = {}) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/rundoc/code_command/print/erb.rb', line 59 def call(env = {}) if render_before? "" else render end end |
#render ⇒ Object
55 56 57 |
# File 'lib/rundoc/code_command/print/erb.rb', line 55 def render @render ||= ERB.new([@line, contents].compact.join("\n")).result(@binding) end |
#render_before? ⇒ Boolean
67 68 69 |
# File 'lib/rundoc/code_command/print/erb.rb', line 67 def render_before? !render_command? && render_result? end |
#render_command? ⇒ Boolean
39 40 41 |
# File 'lib/rundoc/code_command/print/erb.rb', line 39 def render_command? @render_command end |
#render_result? ⇒ Boolean
43 44 45 |
# File 'lib/rundoc/code_command/print/erb.rb', line 43 def render_result? @render_result end |
#to_md(env) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/rundoc/code_command/print/erb.rb', line 47 def to_md(env) if render_before? env[:before] << render end "" end |