Class: Gurk::Page
- Inherits:
-
Object
- Object
- Gurk::Page
- Defined in:
- lib/gurk/page.rb
Instance Attribute Summary collapse
-
#layout ⇒ Object
Returns the value of attribute layout.
-
#locals ⇒ Object
Returns the value of attribute locals.
-
#name ⇒ Object
Returns the value of attribute name.
-
#route ⇒ Object
Returns the value of attribute route.
Instance Method Summary collapse
-
#initialize(data) ⇒ Page
constructor
A new instance of Page.
- #layout_name ⇒ Object
- #layout_path ⇒ Object
- #render(env) ⇒ Object
- #render_template(env) ⇒ Object
- #render_template_with_layout(env, &block) ⇒ Object
- #view_name ⇒ Object
- #view_path ⇒ Object
Constructor Details
#initialize(data) ⇒ Page
Returns a new instance of Page.
8 9 10 11 12 13 |
# 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 |
Instance Attribute Details
#layout ⇒ Object
Returns the value of attribute layout.
6 7 8 |
# File 'lib/gurk/page.rb', line 6 def layout @layout end |
#locals ⇒ Object
Returns the value of attribute locals.
6 7 8 |
# File 'lib/gurk/page.rb', line 6 def locals @locals end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/gurk/page.rb', line 6 def name @name end |
#route ⇒ Object
Returns the value of attribute route.
6 7 8 |
# File 'lib/gurk/page.rb', line 6 def route @route end |
Instance Method Details
#layout_name ⇒ Object
55 56 57 |
# File 'lib/gurk/page.rb', line 55 def layout_name @locals[:layout] end |
#layout_path ⇒ Object
59 60 61 62 63 64 65 |
# 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) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# 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) ⇒ Object
42 43 44 45 |
# 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, &block) ⇒ Object
35 36 37 38 39 40 |
# 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 ⇒ Object
47 48 49 |
# File 'lib/gurk/page.rb', line 47 def view_name @view_name ||= @name end |
#view_path ⇒ Object
51 52 53 |
# File 'lib/gurk/page.rb', line 51 def view_path Gurk.view_path + '/' + view_name + '.' + Gurk.default_view_engine.to_s end |