Class: Expressr::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/expressr/renderer.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.engineObject

Returns the value of attribute engine.



4
5
6
# File 'lib/expressr/renderer.rb', line 4

def engine
  @engine
end

Class Method Details

.enginesObject



21
22
23
24
25
26
# File 'lib/expressr/renderer.rb', line 21

def engines
  {
    'haml' => 'Expressr::Renderers::Haml',
    'slim' => 'Expressr::Renderers::Slim'
  }
end

.get_rendererObject



14
15
16
17
18
19
# File 'lib/expressr/renderer.rb', line 14

def get_renderer
  self.engine = engines[Expressr::App.settings['view engine']]
  raise "Invalid view engine value: #{engine}" unless engine
  klass = Expressr::Utils.constantize(engine)
  klass.new
end

.rendererObject



6
7
8
9
10
11
12
# File 'lib/expressr/renderer.rb', line 6

def renderer
  if engine != Expressr::App.settings['view engine']
    @renderer = get_renderer
  else
    @renderer ||= get_renderer
  end
end

Instance Method Details

#render(path, locals = {}) ⇒ Object



29
30
31
32
33
# File 'lib/expressr/renderer.rb', line 29

def render(path, locals={})
  path = App.settings['root'].join(App.settings['views'], path)
  locals = App.settings['locals'].merge(locals)
  renderer.render(path, locals)
end

#rendererObject



35
36
37
# File 'lib/expressr/renderer.rb', line 35

def renderer
  self.class.renderer
end