module Roda::RodaPlugins::RenderLocals

  1. lib/roda/plugins/render_locals.rb

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

Methods

Public Class

  1. configure
  2. load_dependencies

Public Class methods

configure (app, opts=OPTS)
[show source]
# File lib/roda/plugins/render_locals.rb, line 31
def self.configure(app, opts=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=OPTS)
[show source]
# File lib/roda/plugins/render_locals.rb, line 27
def self.load_dependencies(app, opts=OPTS)
  app.plugin :render
end