Class: Wright::Util::FileRenderer Private

Inherits:
Object
  • Object
show all
Defined in:
lib/wright/util/file_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.

File renderer.

Examples:

filename = 'template.erb'
template = "foo is <%= foo %>."
hash = { foo: :bar }
File.write(filename, template)
renderer = Wright::Util::FileRenderer.new(hash)
renderer.render(filename)
# => "foo is bar."

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ FileRenderer

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.

Initializes a FileTemplate.

Parameters:

  • hash (Hash)

    the attribute hash of the template



19
20
21
# File 'lib/wright/util/file_renderer.rb', line 19

def initialize(hash)
  @hash = hash
end

Instance Method Details

#render(filename) ⇒ Object

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.

Renders a template file.

Parameters:

  • filename (String)

    the filename of the template

Raises:

  • (ArgumentError)

    if the given file type is not supported



26
27
28
29
30
# File 'lib/wright/util/file_renderer.rb', line 26

def render(filename)
  renderer = renderer_for_file(filename)
  template = ::File.read(::File.expand_path(filename))
  renderer.render(template)
end