module Roda::RodaPlugins::MultiView

  1. lib/roda/plugins/multi_view.rb

The multi_view plugin makes it easy to render multiple views, where the view template is the same as the matched element. It adds an r.multi_view method, which takes an argument that is passed to r.get, and should capture a single argument, which is treated as the template name to pass to view. This makes it possible to pass in an array of strings, or a regexp with a single capture.

The advantage of using a regexp over an array of strings is that the regexp is generally faster and uses less memory. However, constructing the regexps is more cumbersome. To make it easier, the multi_view plugin also offers a multi_view_compile class method that will take an array of view template names and construct a regexp that can be passed to r.multi_view.

Example:

plugin :multi_view

route do |r|
  r.multi_view(['foo', 'bar', 'baz'])
end

# or:

route do |r|
  r.multi_view(/(foo|bar|baz)/)
end

# or:

regexp = multi_view_compile(['foo', 'bar', 'baz'])
route do |r|
  r.multi_view(regexp)
end

# all are equivalent to:

route do |r|
  r.get 'foo' do
    view('foo')
  end

  r.get 'bar' do
    view('bar')
  end

  r.get 'baz' do
    view('baz')
  end
end

Methods

Public Class

  1. load_dependencies

Public Class methods

load_dependencies(app)

Depend on the render plugin, since this plugin only makes sense when the render plugin is used.

[show source]
   # File lib/roda/plugins/multi_view.rb
58 def self.load_dependencies(app)
59   app.plugin :render
60 end