Rack::LayoutWrapper

Added by Sutto at October 15, 2009 20:15 Star_small_grayStar_small_grayStar_small_grayStar_small_grayStar_small_gray
GitHub stats:
Magnifier watcher(s)
Arrow_branch fork(s)
Wrench

About

Rack::LayoutWrapper makes it super-easy to have shared layouts between a number of Rack applications – it’s as simple as using Rack::LayoutWrapper, setting the template dir option and then using the passed in layout object (as a part of the rack env).

Usage

For the best documentation, look at the attached tests.

In most cases, it’s as simple accessing env[‘x-rack.layout_wrapper’]. This returns the Rack::LayoutWrapper instance
and makes it possible to set the layout. The returned object has available_layouts – a list of layouts templates available.

If you specified a default template, env[‘x-rack.layout_wrapper’].render_layout = true will tell it to render the default template
whilst env[‘x-rack.layout_wrapper’].layout_name = ‘some-layout-name’ would tell it to use some-layout-name.

Lastly, it’s worth noting that you can use yield or content_for_layout in the layout template to render the contents (only once)
(see the tests).

blog comments powered by Disqus