Class: Flame::Render

Inherits:
Object
  • Object
show all
Defined in:
lib/flame/render.rb

Overview

Helper for render functionality

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ctrl, path, options = {}) ⇒ Render

Returns a new instance of Render.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/flame/render.rb', line 8

def initialize(ctrl, path, options = {})
	## Take options for rendering
	@ctrl = ctrl
	@scope = options.delete(:scope) || @ctrl
	@layout = options.delete(:layout) || 'layout.*'
	## And get the rest variables to locals
	@locals = options.merge(options.delete(:locals) || {})
	## Find filename
	@filename = find_file(path)
	@layout = nil if File.basename(@filename)[0] == '_'
end

Class Method Details

.tilts ⇒ Object



35
36
37
# File 'lib/flame/render.rb', line 35

def self.tilts
	@tilts ||= {}
end

Instance Method Details

#render(cache: true) ⇒ Object



20
21
22
23
24
25
# File 'lib/flame/render.rb', line 20

def render(cache: true)
	## Compile Tilt to instance hash
	tilt = cache ? self.class.tilts[@filename] ||= compile : compile
	## Render Tilt from instance hash with new options
	layout_render tilt.render(@scope, @locals), cache: cache
end