Class: PDK::Template::TemplateDir

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/pdk/template/template_dir.rb

Overview

A helper class representing an already fetched template on disk, with an appropriate renderer instance.

See Also:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, path, context, renderer = nil) ⇒ TemplateDir

Returns a new instance of TemplateDir.

Parameters:

  • template_uri (PDK::Util::TemplateUri)

    A URI which points to the source location of the Template

  • path (String)

    The path to where the template exists on disk

  • context (PDK::Context)

    The context in which the redering will occur in

  • renderer (PDK::Template::Renderer::AbstractRenderer) (defaults to: nil)

    The an instance of a rendering class. If nil, a renderer will be created that’s appropriate for the template and context



33
34
35
36
37
38
39
40
# File 'lib/pdk/template/template_dir.rb', line 33

def initialize(uri, path, context, renderer = nil)
  @uri = uri
  @path = path
  @metadata = {}

  @renderer = renderer.nil? ? Renderer.instance(uri, path, context) : renderer
  raise format('Could not find a compatible template renderer for %{path}', path: path) if @renderer.nil?
end

Instance Attribute Details

#metadataHash{String => String}

Returns A hash of information about the template.

Returns:

  • (Hash{String => String})

    A hash of information about the template



27
28
29
# File 'lib/pdk/template/template_dir.rb', line 27

def 
  @metadata
end

#pathString

Returns The path to where the template exists on disk.

Returns:

  • (String)

    The path to where the template exists on disk



24
25
26
# File 'lib/pdk/template/template_dir.rb', line 24

def path
  @path
end

#uriPDK::Util::TemplateURI

Returns The URI which points to the source location of the Template.

Returns:



21
22
23
# File 'lib/pdk/template/template_dir.rb', line 21

def uri
  @uri
end

Class Method Details

.instance(uri, path, context, renderer = nil) ⇒ Object

Creates an instance of TemplateDir object

See Also:

  • TemplateDir.new


11
12
13
# File 'lib/pdk/template/template_dir.rb', line 11

def self.instance(uri, path, context, renderer = nil)
  new(uri, path, context, renderer)
end

Instance Method Details

#render_module(module_name, options = {}) ⇒ Object

Render an existing module

See Also:

  • Renderer::AbstractRenderer.render


55
56
57
# File 'lib/pdk/template/template_dir.rb', line 55

def render_module(module_name, options = {})
  @renderer.render(MODULE_TEMPLATE_TYPE, module_name, options.merge(include_first_time: false)) { |*args| yield(*args) }
end

#render_new_module(module_name, module_metadata = {}, options = {}) ⇒ Object

Render a new module

See Also:

  • Renderer::AbstractRenderer.render


61
62
63
# File 'lib/pdk/template/template_dir.rb', line 61

def render_new_module(module_name,  = {}, options = {})
  @renderer.render(MODULE_TEMPLATE_TYPE, module_name, options.merge(include_first_time: true, module_metadata: )) { |*args| yield(*args) }
end