24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/ruby_app/mixins/render_mixin.rb', line 24
def render(format, write_cache = false)
cache = self.is_a?(Class) ? self.get_cache(format) : self.class.get_cache(format)
if File.exists?(cache)
self.rendered?(cache) do
return File.read(cache)
end
else
templates = self.is_a?(Class) ? self.get_templates(format) : self.class.get_templates(format)
unless templates.empty?
self.init_haml_helpers
begin
yield(self) if block_given?
templates.each_with_index do |template, index|
content = Haml::Engine.new(File.read(template), :filename => template).render(self) do |*arguments|
if arguments.empty?
index == 0 ? nil : RubyApp::Request.get_content(self, templates[index - 1])
else
_content = RubyApp::Request.get_content(self, arguments[0])
if self.block_is_haml?(_content)
self.capture_haml(arguments, &_content)
else
_content
end
end
end
RubyApp::Request.content_for(self, template, content)
end
if cache && write_cache
cache_directory = File.dirname(cache)
Dir.mkdir(cache_directory) unless File.exists?(cache_directory)
File.open(cache, 'w') do |file|
file.write(RubyApp::Request.get_content(self, templates.last))
file.flush
end
end
return RubyApp::Request.get_content(self, templates.last)
ensure
RubyApp::Request.clear_content(self)
end
end
end
end
|