Templater::Actions::Template

Public Class Methods

new(generator, name, source, destination, options={}) click to toggle source

Builds a new template.

Parameters

generator

Context for rendering

name

The name of this template

source

Full path to the source of this template

destination

Full path to the destination of this template

optionsSymbol}

Options, including callbacks.

    # File lib/templater/actions/template.rb, line 13
13:       def initialize(generator, name, source, destination, options={})
14:         self.generator = generator
15:         self.name = name
16:         self.source = source
17:         self.destination = destination
18:         self.options = options
19:       end

Public Instance Methods

exists?() click to toggle source

Checks if the destination file already exists.

Returns

Boolean

true if the file exists, false otherwise.

    # File lib/templater/actions/template.rb, line 34
34:       def exists?
35:         ::File.exists?(destination)
36:       end
identical?() click to toggle source

Checks if the content of the file at the destination is identical to the rendered result.

Returns

Boolean

true if it is identical, false otherwise.

    # File lib/templater/actions/template.rb, line 42
42:       def identical?
43:         ::File.read(destination) == render if ::File.exists?(destination)
44:       end
invoke!() click to toggle source

Renders the template and copies it to the destination.

    # File lib/templater/actions/template.rb, line 47
47:       def invoke!
48:         callback(:before)
49:         ::FileUtils.mkdir_p(::File.dirname(destination))
50:         ::File.open(destination, 'w') {|f| f.write render }
51:         callback(:after)
52:       end
render() click to toggle source

Renders the template using ERB and returns the result as a String.

Returns

String

The rendered template.

    # File lib/templater/actions/template.rb, line 25
25:       def render
26:         context = generator.instance_eval 'binding'
27:         ERB.new(::File.read(source), nil, '-').result(context)
28:       end
revoke!() click to toggle source

removes the destination file

    # File lib/templater/actions/template.rb, line 55
55:       def revoke!
56:         ::FileUtils.rm(destination, :force => true)
57:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.