Module: Roda::RodaPlugins::RenderLocals
- Defined in:
- lib/roda/plugins/render_locals.rb
Overview
The render_locals plugin allows setting default locals for rendering templates.
plugin :render_locals, :render=>{:heading=>'Hello'}
route do |r|
r.get "foo" do
view 'foo', :locals=>{:name=>'Foo'} # locals: {:heading=>'Hello', :name=>'Foo'}
end
r.get "bar" do
view 'foo', :locals=>{:heading=>'Bar'} # locals: {:heading=>'Bar'}
end
view "default" # locals: {:heading=>'Hello'}
end
The render_locals plugin accepts the following options:
- render
-
The default locals to use for template rendering
- layout
-
The default locals to use for layout rendering
- merge
-
Whether to merge template locals into layout locals
Defined Under Namespace
Modules: InstanceMethods
Constant Summary collapse
- OPTS =
{}.freeze
Class Method Summary collapse
- .configure(app, opts = RodaPlugins::OPTS) ⇒ Object
- .load_dependencies(app, opts = RodaPlugins::OPTS) ⇒ Object
Class Method Details
.configure(app, opts = RodaPlugins::OPTS) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/roda/plugins/render_locals.rb', line 35 def self.configure(app, opts=RodaPlugins::OPTS) app.opts[:render_locals] = (app.opts[:render_locals] || {}).merge(opts[:render]||{}).freeze app.opts[:layout_locals] = (app.opts[:layout_locals] || {}).merge(opts[:layout]||{}).freeze if opts.has_key?(:merge) app.opts[:merge_locals] = opts[:merge] app.opts[:layout_locals] = app.opts[:render_locals].merge(app.opts[:layout_locals]).freeze end end |
.load_dependencies(app, opts = RodaPlugins::OPTS) ⇒ Object
31 32 33 |
# File 'lib/roda/plugins/render_locals.rb', line 31 def self.load_dependencies(app, opts=RodaPlugins::OPTS) app.plugin :render end |