3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/dimples/renderable.rb', line 3
def render(context = {}, body = nil, use_layout = true)
class_name = self.class.name.split('::').last.downcase.to_sym
context[:site] = @site unless context[:site]
context[class_name] = self unless context[class_name]
scope = Object.new
context.each_pair do |key, value|
scope.instance_variable_set("@#{key}".to_sym, value)
end
begin
output = renderer.render(scope) { body }.strip
@rendered_contents = output
rescue RuntimeError, TypeError, NoMethodError, SyntaxError, NameError => e
problem_file = if @path
@path.gsub(@site.source_paths[:root], '')
else
"dynamic #{self.class}"
end
raise Errors::RenderingError.new(problem_file, e.message)
end
if use_layout && defined?(@layout) && @site.templates[@layout]
output = @site.templates[@layout].render(context, output)
end
output
end
|