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 |
Classes and Modules
Public Class methods
configure(app, opts=OPTS)
[show source]
# File lib/roda/plugins/render_locals.rb 34 def self.configure(app, opts=OPTS) 35 app.opts[:render_locals] = (app.opts[:render_locals] || {}).merge(opts[:render]||{}).freeze 36 app.opts[:layout_locals] = (app.opts[:layout_locals] || {}).merge(opts[:layout]||{}).freeze 37 if opts.has_key?(:merge) 38 app.opts[:merge_locals] = opts[:merge] 39 app.opts[:layout_locals] = app.opts[:render_locals].merge(app.opts[:layout_locals]).freeze 40 end 41 end
load_dependencies(app, opts=OPTS)
[show source]
# File lib/roda/plugins/render_locals.rb 30 def self.load_dependencies(app, opts=OPTS) 31 app.plugin :render 32 end