Class: Flame::Render

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

Overview

Helper for render functionality

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Render.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/flame/render.rb', line 12

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)
	# @ctrl.instance_exec { halt 404 } unless @filename
	return unless @filename
	@layout = nil if File.basename(@filename)[0] == '_'
end

Instance Method Details

#render(cache: true) ⇒ Object

Render template

Parameters:

  • cache (Boolean) (defaults to: true)

    cache compiles or not



28
29
30
31
32
33
34
# File 'lib/flame/render.rb', line 28

def render(cache: true)
	## Compile Tilt to instance hash
	return unless @filename
	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