Class: Edison::Renderer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(views) ⇒ Renderer

Returns a new instance of Renderer.



72
73
74
# File 'lib/edison.rb', line 72

def initialize(views)
	self.views = views
end

Instance Attribute Details

#viewsObject

Returns the value of attribute views.



71
72
73
# File 'lib/edison.rb', line 71

def views
  @views
end

Instance Method Details

#render(view_name, data) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/edison.rb', line 75

def render(view_name, data)
	view = self.views[view_name]
	if view.nil?
		raise Exception, "Called for view #{view_name}, but _views/#{view_name} does not exist"
	end
	body = Mustache.render(view.body, data)
	if view.layout
		newdata = data.merge("yield" => body)
		self.render(view.layout, newdata)
	else
		body
	end
end