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



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
   = {}

  @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}



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

def 
  
end

#pathString



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

def path
  @path
end

#uriPDK::Util::TemplateURI



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