Class: Alephant::RenderMapper

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/alephant/models/render_mapper.rb

Constant Summary collapse

DEFAULT_LOCATION =
'components'

Instance Method Summary collapse

Constructor Details

#initialize(component_id, view_base_path = nil) ⇒ RenderMapper

Returns a new instance of RenderMapper.



8
9
10
11
# File 'lib/alephant/models/render_mapper.rb', line 8

def initialize(component_id, view_base_path=nil)
  self.base_path = "#{view_base_path}/#{component_id}" unless view_base_path.nil?
  @component_id = component_id
end

Instance Method Details

#base_pathObject



13
14
15
# File 'lib/alephant/models/render_mapper.rb', line 13

def base_path
  @base_path || DEFAULT_LOCATION
end

#base_path=(path) ⇒ Object



17
18
19
# File 'lib/alephant/models/render_mapper.rb', line 17

def base_path=(path)
  @base_path = File.directory?(path) ? path : (raise "Invalid path")
end

#create_renderer(template_file, data) ⇒ Object



28
29
30
31
# File 'lib/alephant/models/render_mapper.rb', line 28

def create_renderer(template_file, data)
  model = instantiate_model(template_file, data)
  Renderer.create(template_file, base_path, model)
end

#generate(data) ⇒ Object



21
22
23
24
25
26
# File 'lib/alephant/models/render_mapper.rb', line 21

def generate(data)
  template_locations.reduce({}) do |obj, file|
    template_id = template_id_for file
    obj.tap { |o| o[template_id] = create_renderer(template_id, data) }
  end
end