Class: InputTemplateRenderer
- Inherits:
-
Object
- Object
- InputTemplateRenderer
- Includes:
- UnattendedHelper
- Defined in:
- app/models/input_template_renderer.rb
Defined Under Namespace
Classes: UndefinedInput
Instance Attribute Summary collapse
-
#error_message ⇒ Object
Returns the value of attribute error_message.
-
#host ⇒ Object
Returns the value of attribute host.
-
#invocation ⇒ Object
Returns the value of attribute invocation.
-
#template ⇒ Object
Returns the value of attribute template.
Instance Method Summary collapse
-
#initialize(template, host = nil, invocation = nil) ⇒ InputTemplateRenderer
constructor
takes template object that should be rendered host and template invocation arguments are optional so we can render values based on parameters, facts or user inputs.
- #input(name) ⇒ Object
- #preview ⇒ Object
- #render ⇒ Object
Constructor Details
#initialize(template, host = nil, invocation = nil) ⇒ InputTemplateRenderer
takes template object that should be rendered host and template invocation arguments are optional so we can render values based on parameters, facts or user inputs
12 13 14 15 16 |
# File 'app/models/input_template_renderer.rb', line 12 def initialize(template, host = nil, invocation = nil) @host = host @invocation = invocation @template = template end |
Instance Attribute Details
#error_message ⇒ Object
Returns the value of attribute error_message.
7 8 9 |
# File 'app/models/input_template_renderer.rb', line 7 def @error_message end |
#host ⇒ Object
Returns the value of attribute host.
7 8 9 |
# File 'app/models/input_template_renderer.rb', line 7 def host @host end |
#invocation ⇒ Object
Returns the value of attribute invocation.
7 8 9 |
# File 'app/models/input_template_renderer.rb', line 7 def invocation @invocation end |
#template ⇒ Object
Returns the value of attribute template.
7 8 9 |
# File 'app/models/input_template_renderer.rb', line 7 def template @template end |
Instance Method Details
#input(name) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'app/models/input_template_renderer.rb', line 33 def input(name) input = @template.template_inputs.where(:name => name.to_s).first || @template.template_inputs.detect { |i| i.name == name.to_s } if input @preview ? input.preview(self) : input.value(self) else self. = _('input macro with name \'%s\' used, but no input with such name defined for this template') % name raise UndefinedInput, "Rendering failed, no input with name #{name} for input macro found" end end |
#preview ⇒ Object
26 27 28 29 30 31 |
# File 'app/models/input_template_renderer.rb', line 26 def preview @preview = true output = render @preview = false output end |
#render ⇒ Object
18 19 20 21 22 23 24 |
# File 'app/models/input_template_renderer.rb', line 18 def render render_safe(@template.template, [ :input ], :host => @host) rescue => e self. ||= _('error during rendering: %s') % e. Rails.logger.debug e.to_s + "\n" + e.backtrace.join("\n") return false end |