Class: Alephant::Publisher::RenderMapper

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/alephant/publisher/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.



9
10
11
12
# File 'lib/alephant/publisher/render_mapper.rb', line 9

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



14
15
16
# File 'lib/alephant/publisher/render_mapper.rb', line 14

def base_path
  @base_path || DEFAULT_LOCATION
end

#base_path=(path) ⇒ Object



18
19
20
# File 'lib/alephant/publisher/render_mapper.rb', line 18

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

#create_renderer(template_file, data) ⇒ Object



29
30
31
32
# File 'lib/alephant/publisher/render_mapper.rb', line 29

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

#generate(data) ⇒ Object



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

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