Class: PDK::Template::TemplateDir
- Inherits:
-
Object
- Object
- PDK::Template::TemplateDir
- 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.
Instance Attribute Summary collapse
-
#metadata ⇒ Hash{String => String}
A hash of information about the template.
-
#path ⇒ String
The path to where the template exists on disk.
-
#uri ⇒ PDK::Util::TemplateURI
The URI which points to the source location of the Template.
Class Method Summary collapse
-
.instance(uri, path, context, renderer = nil) ⇒ Object
Creates an instance of TemplateDir object.
Instance Method Summary collapse
-
#initialize(uri, path, context, renderer = nil) ⇒ TemplateDir
constructor
A new instance of TemplateDir.
-
#render_module(module_name, options = {}) ⇒ Object
Render an existing module.
-
#render_new_module(module_name, module_metadata = {}, options = {}) ⇒ Object
Render a new module.
Constructor Details
#initialize(uri, path, context, renderer = nil) ⇒ TemplateDir
Returns a new instance of 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 @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
#metadata ⇒ Hash{String => String}
Returns A hash of information about the template.
27 28 29 |
# File 'lib/pdk/template/template_dir.rb', line 27 def @metadata end |
#path ⇒ String
Returns 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 |
#uri ⇒ PDK::Util::TemplateURI
Returns The URI which points to the source location of the Template.
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
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
55 56 57 |
# File 'lib/pdk/template/template_dir.rb', line 55 def render_module(module_name, = {}) @renderer.render(MODULE_TEMPLATE_TYPE, module_name, .merge(include_first_time: false)) { |*args| yield(*args) } end |
#render_new_module(module_name, module_metadata = {}, options = {}) ⇒ Object
Render a new module
61 62 63 |
# File 'lib/pdk/template/template_dir.rb', line 61 def render_new_module(module_name, = {}, = {}) @renderer.render(MODULE_TEMPLATE_TYPE, module_name, .merge(include_first_time: true, module_metadata: )) { |*args| yield(*args) } end |