class AutomateIt::TemplateManager

TemplateManager

TemplateManager renders templates to files.

See the render method for details.

Public Instance Methods

default_check() click to toggle source

Get name of default algorithm for performing checks.

# File lib/automateit/template_manager.rb, line 47
def default_check() dispatch() end
default_check=(value) click to toggle source

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

# File lib/automateit/template_manager.rb, line 51
def default_check=(value) dispatch(value) end
render(*options) click to toggle source

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!
# File lib/automateit/template_manager.rb, line 44
def render(*options) dispatch(*options) end