Builds a new template.
generator<Object> |
Context for rendering |
name<Symbol> |
The name of this template |
source<String> |
Full path to the source of this template |
destination<String> |
Full path to the destination of this template |
options<Hash{Symbol=>Symbol} |
Options, including callbacks. |
# File lib/templater/actions/template.rb, line 13 def initialize(generator, name, source, destination, options={}) self.generator = generator self.name = name self.source = source self.destination = destination self.options = options end
Checks if the destination file already exists.
Boolean |
true if the file exists, false otherwise. |
# File lib/templater/actions/template.rb, line 34 def exists? ::File.exists?(destination) end
Checks if the content of the file at the destination is identical to the rendered result.
Boolean |
true if it is identical, false otherwise. |
# File lib/templater/actions/template.rb, line 42 def identical? ::File.read(destination) == render if ::File.exists?(destination) end
Renders the template and copies it to the destination.
# File lib/templater/actions/template.rb, line 47 def invoke! callback(:before) ::FileUtils.mkdir_p(::File.dirname(destination)) ::File.open(destination, 'w') {|f| f.write render } callback(:after) end
Generated with the Darkfish Rdoc Generator 2.