Class: AutomateIt::TemplateManager

Inherits:
Plugin::Manager show all
Defined in:
lib/automateit/template_manager.rb

Overview

TemplateManager

TemplateManager renders templates to files.

See the #render method for details.

Defined Under Namespace

Classes: BaseDriver, ERB

Constant Summary

Constants included from Constants

Constants::HELPERS_DIR, Constants::INSTALL_DIR, Constants::PERROR, Constants::PEXEC, Constants::PNOTE, Constants::WARNING_BOILERPLATE

Instance Attribute Summary

Attributes inherited from Plugin::Manager

#drivers

Attributes inherited from Common

#interpreter

Instance Method Summary collapse

Methods inherited from Plugin::Manager

#[], abstract_manager, alias_methods, #available?, #default, #default=, #dispatch, #dispatch_safely, #dispatch_safely_to, #dispatch_to, driver_classes, #driver_for, #driver_suitability_levels_for, inherited, #instantiate_drivers, #setup

Methods inherited from Plugin::Base

#setup, #token, token

Methods inherited from Common

#initialize, #log, #nitpick, #noop, #noop=, #noop?, #preview, #preview=, #preview?, #preview_for, #setup, #superuser?, #writing, #writing=, #writing?

Constructor Details

This class inherits a constructor from AutomateIt::Common

Instance Method Details

#default_checkObject

Get name of default algorithm for performing checks.



47
# File 'lib/automateit/template_manager.rb', line 47

def default_check() dispatch() end

#default_check=(value) ⇒ Object

Set name of default algorithms to perform checks, e.g., :compare. See the #render :check option for list of check algorithms.



51
# File 'lib/automateit/template_manager.rb', line 51

def default_check=(value) dispatch(value) end

#render(*options) ⇒ Object

Render a template.

You may specify the source and target as arguments or options. For example, render(:file => "input", :to => "output") is the same as render("input", "output").

Options:

  • :file – Read the template from this file.

  • :text – Read the template from this string.

  • :to – Render to a file, otherwise returns the rendered string.

  • :locals – Hash of variables passed to template as local variables.

  • :dependencies – Array of filenames to check timestamps on, only used when :check is :timestamp.

  • :backup – Make a backup? Default is true.

  • :force – Render without making a check. Default is false.

  • :check – Determines when to render, otherwise uses value of default_check, possible values:

    • :compare – Only render if rendered template is different than the target’s contents or if the target doesn’t exist.

    • :timestamp – Only render if the target is older than the template and dependencies.

    • :exists – Only render if the target doesn’t exist.

For example, if the file my_template_file contains:

Hello <%=entity%>!

You could then execute:

render("my_template_file", "/tmp/out", :check => :compare,
       :locals => {:entity => "world"})

And this will create a /tmp/out file with:

Hello world!


44
# File 'lib/automateit/template_manager.rb', line 44

def render(*options) dispatch(*options) end