Class: PDK::Template::Renderer::V1::TemplateFile

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/pdk/template/renderer/v1/template_file.rb

Instance Method Summary collapse

Constructor Details

#initialize(template_file, data = {}) ⇒ TemplateFile

Initialises the TemplateFile object with the path to the template file and the data to be used when rendering the template.

the template when rendering. the template as an instance variable ‘@configs` in order to maintain compatibility with modulesync.

Parameters:

  • template_file (String)

    The path on disk to the template file.

  • data (Hash{Symbol => Object}) (defaults to: {})

    The data that should be provided to

Options Hash (data):

  • :configs (Object)

    The value of this key will be provided to



20
21
22
23
24
25
26
27
28
# File 'lib/pdk/template/renderer/v1/template_file.rb', line 20

def initialize(template_file, data = {})
  @template_file = template_file

  if data.key?(:configs)
    @configs = data[:configs]
  end

  super(data)
end

Instance Method Details

#config_for(path) ⇒ Object



51
52
53
54
55
# File 'lib/pdk/template/renderer/v1/template_file.rb', line 51

def config_for(path)
  return unless respond_to?(:template_dir)

  template_dir.config_for(path)
end

#renderString

Renders the template by calling the appropriate engine based on the file extension.

If the template has an ‘.erb` extension, the content of the template file will be treated as an ERB template. All other extensions are treated as plain text.

Returns:

  • (String)

    The rendered template

Raises:

  • (ArgumentError)

    If the template file does not exist or can not be



42
43
44
45
46
47
48
49
# File 'lib/pdk/template/renderer/v1/template_file.rb', line 42

def render
  case File.extname(@template_file)
  when '.erb'
    render_erb
  else
    render_plain
  end
end