Class: Alephant::Renderer::ViewMapper
- Inherits:
-
Object
- Object
- Alephant::Renderer::ViewMapper
- Includes:
- Logger
- Defined in:
- lib/alephant/renderer/view_mapper.rb
Constant Summary collapse
- DEFAULT_LOCATION =
"components"
Instance Method Summary collapse
- #base_path ⇒ Object
- #base_path=(path) ⇒ Object
- #generate(data) ⇒ Object
-
#initialize(renderer_id, view_base_path = nil) ⇒ ViewMapper
constructor
A new instance of ViewMapper.
Constructor Details
#initialize(renderer_id, view_base_path = nil) ⇒ ViewMapper
Returns a new instance of ViewMapper.
11 12 13 14 15 |
# File 'lib/alephant/renderer/view_mapper.rb', line 11 def initialize(renderer_id, view_base_path=nil) unless view_base_path.nil? self.base_path = "#{view_base_path}/#{renderer_id}" end end |
Instance Method Details
#base_path ⇒ Object
17 18 19 |
# File 'lib/alephant/renderer/view_mapper.rb', line 17 def base_path @base_path || DEFAULT_LOCATION end |
#base_path=(path) ⇒ Object
21 22 23 |
# File 'lib/alephant/renderer/view_mapper.rb', line 21 def base_path=(path) @base_path = File.directory?(path) ? path : raise_error(path) end |
#generate(data) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/alephant/renderer/view_mapper.rb', line 25 def generate(data) model_locations.reduce({}) do |obj, file| obj.tap do |o| model_id = model_id_for file o[model_id] = model(model_id, data) end end end |