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(controller, path, options = {}) ⇒ Render

Returns a new instance of Render.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/flame/render.rb', line 16

def initialize(controller, path, options = {})
	## Take options for rendering
	@controller = controller
	@scope = options.delete(:scope) || @controller
	@layout = options.delete(:layout)
	@layout = 'layout.*' if @layout.nil?
	## And get the rest variables to locals
	@locals = options.merge(options.delete(:locals) || {})
	## Find filename
	@filename = find_file(path)
	unless @filename
		raise Flame::Errors::TemplateNotFoundError.new(controller, path)
	end
	@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



34
35
36
37
38
39
40
41
# File 'lib/flame/render.rb', line 34

def render(cache: true)
	@cache = cache
	## Compile Tilt to instance hash
	return unless @filename
	tilt = compile_file
	## Render Tilt from instance hash with new options
	layout_render tilt.render(@scope, @locals)
end