class Gurk::Page
Attributes
layout[RW]
locals[RW]
name[RW]
route[RW]
Public Class Methods
new(data)
click to toggle source
# File lib/gurk/page.rb, line 8 def initialize(data) @name = data[:name].downcase @locals = data[:locals] @route = data[:route] @layout= data[:locals][:layout] if data[:locals] && data[:locals][:layout] end
Public Instance Methods
layout_name()
click to toggle source
# File lib/gurk/page.rb, line 55 def layout_name @locals[:layout] end
layout_path()
click to toggle source
# File lib/gurk/page.rb, line 59 def layout_path if layout_name =~ /\.(erb|haml|)/ Gurk.view_path + '/' + layout_name else Gurk.view_path + '/' + layout_name + '.' + Gurk.default_view_engine.to_s end end
render(env)
click to toggle source
# File lib/gurk/page.rb, line 15 def render(env) output = nil if @layout output = render_template_with_layout(env) do render_template(env) end else output = render_template(env) end [200, {'content_type' => 'text/html'}, [output]] rescue Errno::ENOENT => e raise Gurk::TemplateNotFound.new(e) rescue RuntimeError, Exception => e # TODO: Make this more sensible raise e end
render_template(env)
click to toggle source
# File lib/gurk/page.rb, line 42 def render_template(env) tilt = Tilt.new(view_path) tilt.render(nil, locals) end
render_template_with_layout(env) { || ... }
click to toggle source
# File lib/gurk/page.rb, line 35 def render_template_with_layout(env, &block) tilt = Tilt.new(layout_path) tilt.render(nil, locals) do yield end end
view_name()
click to toggle source
# File lib/gurk/page.rb, line 47 def view_name @view_name ||= @name end
view_path()
click to toggle source
# File lib/gurk/page.rb, line 51 def view_path Gurk.view_path + '/' + view_name + '.' + Gurk.default_view_engine.to_s end