Class: TreeRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/tree_renderer.rb,
lib/tree_renderer/version.rb

Overview

Render a tree of files using ERB

example:

TreeRenderer.new("/template/path", "/target/path", variables).save

Constant Summary collapse

VERSION =

Version of the gem

"1.1.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template_path, target_path, variables = {}) ⇒ TreeRenderer

Initialize the paths and variables for rendering

Parameters:

  • template_path (String)

    the path to the template directory to be rendered

  • target_path (String)

    the target path where to render the template

  • variables (Hash, Object, Binding) (defaults to: {})

    the variables to use for rendering



31
32
33
34
35
# File 'lib/tree_renderer.rb', line 31

def initialize(template_path, target_path, variables = {})
  @template_path = template_path
  @target_path   = target_path
  @var_binding   = calculate_binding(variables)
end

Instance Attribute Details

#target_pathString (readonly)

Returns the target path where to render the template.

Returns:

  • (String)

    the target path where to render the template



21
22
23
# File 'lib/tree_renderer.rb', line 21

def target_path
  @target_path
end

#template_pathString (readonly)

Returns the path to the template directory to be rendered.

Returns:

  • (String)

    the path to the template directory to be rendered



19
20
21
# File 'lib/tree_renderer.rb', line 19

def template_path
  @template_path
end

#var_bindingBinding (readonly)

Returns binding for the variables to use for rendering.

Returns:

  • (Binding)

    binding for the variables to use for rendering



23
24
25
# File 'lib/tree_renderer.rb', line 23

def var_binding
  @var_binding
end

Instance Method Details

#saveObject

Run the rendering process



38
39
40
# File 'lib/tree_renderer.rb', line 38

def save
  all_files.each{ |file| parse_and_save(file) }
end