Module: Foreman::Renderer

Included in:
Api::V2::TemplateInputsController
Defined in:
lib/foreman/renderer.rb,
lib/foreman/renderer/scope.rb,
lib/foreman/renderer/errors.rb,
lib/foreman/renderer/source.rb,
lib/foreman/renderer/scope/base.rb,
lib/foreman/renderer/source/base.rb,
lib/foreman/renderer/scope/macros.rb,
lib/foreman/renderer/scope/report.rb,
lib/foreman/renderer/base_renderer.rb,
lib/foreman/renderer/configuration.rb,
lib/foreman/renderer/source/string.rb,
lib/foreman/renderer/scope/template.rb,
lib/foreman/renderer/scope/partition.rb,
lib/foreman/renderer/scope/variables.rb,
lib/foreman/renderer/source/database.rb,
lib/foreman/renderer/source/snapshot.rb,
lib/foreman/renderer/source/directory.rb,
lib/foreman/renderer/scope/macros/base.rb,
lib/foreman/renderer/safe_mode_renderer.rb,
lib/foreman/renderer/scope/provisioning.rb,
lib/foreman/renderer/scope/macros/inputs.rb,
lib/foreman/renderer/scope/macros/loaders.rb,
lib/foreman/renderer/scope/variables/base.rb,
lib/foreman/renderer/unsafe_mode_renderer.rb,
lib/foreman/renderer/scope/macros/host_template.rb,
lib/foreman/renderer/scope/template_input_values.rb,
lib/foreman/renderer/scope/macros/template_logging.rb,
lib/foreman/renderer/scope/macros/snippet_rendering.rb,
lib/foreman/renderer/doc_templates/basic_ruby_methods.rb

Defined Under Namespace

Modules: DocTemplates, Errors, Scope, Source Classes: BaseRenderer, Configuration, SafeModeRenderer, UnsafeModeRenderer

Constant Summary collapse

PREVIEW_MODE =
'preview'
REAL_MODE =
'real'
AVAILABLE_RENDERING_MODES =
[PREVIEW_MODE, REAL_MODE]

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configObject


10
11
12
# File 'lib/foreman/renderer.rb', line 10

def config
  @config ||= Foreman::Renderer::Configuration.new
end

Class Method Details

.configure {|config| ... } ⇒ Object

Yields:


14
15
16
# File 'lib/foreman/renderer.rb', line 14

def configure
  yield config
end

.get_scope(source: nil, klass: nil, host: nil, params: {}, variables: {}, mode: REAL_MODE, template: nil, template_input_values: {}) ⇒ Object


36
37
38
39
40
# File 'lib/foreman/renderer.rb', line 36

def get_scope(source: nil, klass: nil, host: nil, params: {}, variables: {}, mode: REAL_MODE, template: nil, template_input_values: {})
  source ||= get_source(template: template)
  klass ||= template&.default_render_scope_class || Foreman::Renderer::Scope::Provisioning
  klass.new(source: source, host: host, params: params, variables: variables, mode: mode, template_input_values: template_input_values)
end

.get_source(klass: nil, template:, **args) ⇒ Object


31
32
33
34
# File 'lib/foreman/renderer.rb', line 31

def get_source(klass: nil, template:, **args)
  klass ||= Foreman::Renderer::Source::Database
  klass.new(template)
end

.render_template_to_tempfile(template:, prefix:, host: nil, params: {}, variables: {}, options: {}) ⇒ Object


18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/foreman/renderer.rb', line 18

def render_template_to_tempfile(template:, prefix:, host: nil, params: {}, variables: {}, options: {})
  file = ''
  source = get_source(template: template, host: host)
  scope = get_scope(host: host, params: params, variables: variables)
  Tempfile.open(prefix, Rails.root.join('tmp')) do |f|
    f.print render(source, scope)
    f.flush
    f.chmod options[:mode] if options[:mode]
    file = f
  end
  file
end

.rendererObject


42
43
44
# File 'lib/foreman/renderer.rb', line 42

def renderer
  Setting[:safemode_render] ? Foreman::Renderer::SafeModeRenderer : Foreman::Renderer::UnsafeModeRenderer
end