Class: PDK::Template::Renderer::AbstractRenderer Abstract Private

Inherits:
Object
  • Object
show all
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.

This class is abstract.

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:

  1. Create a new class which subclasses AbstractRenderer and implements the public methods (has_single_item?, render and render_single_item)

  2. 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

  3. 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

V1::Renderer

Instance Attribute Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • template_root (String)

    The path to where the template exists on disk

  • template_uri (PDK::Util::TemplateUri)

    A URI which points to the source location of the Template

  • context (PDK::Context)

    The context in which the redering will occur in



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

#contextObject (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_rootString (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.

Returns:

  • (String)

    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_uriPDK::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.

Returns:



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.

This method is abstract.

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.

Parameters:

  • item_path (String)

    The path to the item to check

Returns:

  • (Boolean)

    Whether the renderer can render the item



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 is abstract.

This method returns an undefined value.

Loop through the files in the template type, yielding each rendered file to the supplied block.

Parameters:

  • template_type (PDK::Template::*_TEMPLATE_TYPE)

    The type of template to render

  • name (String)

    The name to use in the rendering process

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

    A list of options to pass through to the renderer. See PDK::Template::TemplateDir helper methods for other options

Options Hash (options):

  • :include_first_time (Boolean)

    Whether to include “first time” items when rendering the project. While it is up to the renderer to implement this the expected behavior is that if the item already exists, it will not be rendererd again. Unlike normal items which are always rendered to keep them in-sync

Yield Parameters:

  • dest_path (String)

    The path of the destination file, relative to the root of the context.

  • dest_content (String)

    The rendered content of the destination file.

  • dest_status (Symbol)

    :unmanage, :delete, :init, :manage

See Also:

  • TemplateDir.render


82
# File 'lib/pdk/template/renderer.rb', line 82

def render(template_type, name, options = {}); 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.

This method is abstract.

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?

Parameters:

  • item_path (String)

    The path of the single item to render

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

    A hash of information which will be used in the rendering process

Returns:

  • (String, Nil)

    The rendered content, or nil of the file could not be rendered



93
# File 'lib/pdk/template/renderer.rb', line 93

def render_single_item(item_path, template_data_hash = {}); end