Class: InputTemplateRenderer
- Inherits:
-
Object
- Object
- InputTemplateRenderer
- Defined in:
- app/models/input_template_renderer.rb
Defined Under Namespace
Classes: RenderError, UndefinedInput
Instance Attribute Summary collapse
-
#current_user ⇒ Object
Returns the value of attribute current_user.
-
#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.
-
#template_input_values ⇒ Object
Returns the value of attribute template_input_values.
-
#templates_stack ⇒ Object
Returns the value of attribute templates_stack.
Instance Method Summary collapse
-
#initialize(template, host = nil, invocation = nil, input_values = nil, preview = false, templates_stack = []) ⇒ 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.
- #preview ⇒ Object
- #render ⇒ Object
Constructor Details
#initialize(template, host = nil, invocation = nil, input_values = nil, preview = false, templates_stack = []) ⇒ 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
15 16 17 18 19 20 21 22 23 24 |
# File 'app/models/input_template_renderer.rb', line 15 def initialize(template, host = nil, invocation = nil, input_values = nil, preview = false, templates_stack = []) raise Foreman::Exception, N_('Recursive rendering of templates detected') if templates_stack.include?(template) @host = host @template = template @invocation = invocation @template_input_values = input_values @preview = preview @templates_stack = templates_stack + [template] end |
Instance Attribute Details
#current_user ⇒ Object
Returns the value of attribute current_user.
10 11 12 |
# File 'app/models/input_template_renderer.rb', line 10 def current_user @current_user end |
#error_message ⇒ Object
Returns the value of attribute error_message.
10 11 12 |
# File 'app/models/input_template_renderer.rb', line 10 def @error_message end |
#host ⇒ Object
Returns the value of attribute host.
10 11 12 |
# File 'app/models/input_template_renderer.rb', line 10 def host @host end |
#invocation ⇒ Object
Returns the value of attribute invocation.
10 11 12 |
# File 'app/models/input_template_renderer.rb', line 10 def invocation @invocation end |
#template ⇒ Object
Returns the value of attribute template.
10 11 12 |
# File 'app/models/input_template_renderer.rb', line 10 def template @template end |
#template_input_values ⇒ Object
Returns the value of attribute template_input_values.
10 11 12 |
# File 'app/models/input_template_renderer.rb', line 10 def template_input_values @template_input_values end |
#templates_stack ⇒ Object
Returns the value of attribute templates_stack.
10 11 12 |
# File 'app/models/input_template_renderer.rb', line 10 def templates_stack @templates_stack end |
Instance Method Details
#preview ⇒ Object
56 57 58 59 60 61 62 |
# File 'app/models/input_template_renderer.rb', line 56 def preview old_preview = @preview @preview = true render ensure @preview = old_preview end |
#render ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/models/input_template_renderer.rb', line 26 def render @template_input_values ||= values_from_invocation @template.validate_unique_inputs! source = Foreman::Renderer.get_source( template: template, host: host ) @scope = Foreman::Renderer.get_scope( source: source, host: host, klass: renderer_scope, template_input_values: @template_input_values, variables: { host: host, template: template, preview: @preview, invocation: invocation, input_values: @template_input_values, templates_stack: templates_stack, input_template_instance: self, current_user: User.current.try(:login), } ) Foreman::Renderer.render(source, @scope) rescue => e self. ||= _('error during rendering: %s') % e. Foreman::Logging.exception('Error during rendering of a job template', e) false end |