Class: PDK::Template::Renderer::AbstractRenderer Abstract Private
- Inherits:
-
Object
- Object
- PDK::Template::Renderer::AbstractRenderer
- Defined in:
- lib/pdk/template/renderer.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
An abstract class which all Template Renderers should subclass and implement. This class is responsible for rendering a template or a single item within a template directory
To implement a new renderer:
-
Create a new class which subclasses AbstractRenderer and implements the public methods (has_single_item?, render and render_single_item)
-
Add class methods .compatible? and .instance which are used to detect if a template is compatible with the new renderer and create an instance of the new renderer respectively
-
Update the PDK::Template::Renderer.instance method to detect and create an instance of the new renderer (using the .compatible? and .instance methods created in step 2).
See the PDK::Template::Renderer::V1 module and classes for an example on how to to this.
Direct Known Subclasses
Instance Attribute Summary collapse
- #context ⇒ Object readonly private
-
#template_root ⇒ String
readonly
private
The path to where the template exists on disk.
-
#template_uri ⇒ PDK::Util::TemplateURI
readonly
private
The URI which points to the source location of the Template.
Instance Method Summary collapse
-
#has_single_item?(_item_path) ⇒ Boolean
abstract
private
Whether the renderer supports rendering the a single item called ‘item_path’.
-
#initialize(template_root, template_uri, context) ⇒ AbstractRenderer
constructor
private
A new instance of AbstractRenderer.
-
#render(template_type, name, options = {}) {|dest_path, dest_content, dest_status| ... } ⇒ void
abstract
private
Loop through the files in the template type, yielding each rendered file to the supplied block.
-
#render_single_item(item_path, template_data_hash = {}) ⇒ String, Nil
abstract
private
Render a single item and return the resulting string.
Constructor Details
#initialize(template_root, template_uri, context) ⇒ AbstractRenderer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of AbstractRenderer.
48 49 50 51 52 |
# File 'lib/pdk/template/renderer.rb', line 48 def initialize(template_root, template_uri, context) @template_root = template_root @template_uri = template_uri @context = context end |
Instance Attribute Details
#context ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
43 44 45 |
# File 'lib/pdk/template/renderer.rb', line 43 def context @context end |
#template_root ⇒ String (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The path to where the template exists on disk.
37 38 39 |
# File 'lib/pdk/template/renderer.rb', line 37 def template_root @template_root end |
#template_uri ⇒ PDK::Util::TemplateURI (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The URI which points to the source location of the Template.
40 41 42 |
# File 'lib/pdk/template/renderer.rb', line 40 def template_uri @template_uri end |
Instance Method Details
#has_single_item?(_item_path) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Whether the renderer supports rendering the a single item called ‘item_path’. This is used when rendering things like a new Task or a new Puppet Classes. Rendering a single item is different than redering an entire project, like a entire Puppet Module or Control Repo.
61 62 63 |
# File 'lib/pdk/template/renderer.rb', line 61 def has_single_item?(_item_path) # rubocop:disable Naming/PredicateName Changing the method name to `single_item?` will convey the wrong intent false end |
#render(template_type, name, options = {}) {|dest_path, dest_content, dest_status| ... } ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Loop through the files in the template type, yielding each rendered file to the supplied block.
82 |
# File 'lib/pdk/template/renderer.rb', line 82 def render(template_type, name, = {}); end |
#render_single_item(item_path, template_data_hash = {}) ⇒ String, Nil
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Render a single item and return the resulting string. This is used when rendering things like a new Task or a new Puppet Classes. Rendering a single item is different than redering an entire project, like a entire Puppet Module or Control Repo. This method is used in conjunction with .has_single_item?
93 |
# File 'lib/pdk/template/renderer.rb', line 93 def render_single_item(item_path, template_data_hash = {}); end |