module Roda::RodaPlugins::AdditionalViewDirectories

  1. lib/roda/plugins/additional_view_directories.rb

The additional_view_directories plugin allows for specifying additional view directories to look in for templates. When rendering a template, it will first try the :views directory specified in the render plugin. If the template file to be rendered does not exist in that directory, it will try each additional view directory specified in this plugin, in order, using the path to the first template file that exists in the file system. If no such path is found, it uses the default path specified by the render plugin.


plugin :render, :views=>'dir'
plugin :additional_view_directories, ['dir1', 'dir2', 'dir3']

route do |r|
  # Will check the following in order, using path for first
  # template file that exists:
  # * dir/t.erb
  # * dir1/t.erb
  # * dir2/t.erb
  # * dir3/t.erb
  render :t


Public Class

  1. configure
  2. load_dependencies

Public Class methods

configure(app, view_dirs)

Set the additional view directories to look in. Each additional view directory is also added as an allowed path.

[show source]
   # File lib/roda/plugins/additional_view_directories.rb
37 def self.configure(app, view_dirs)
38   view_dirs = app.opts[:additional_view_directories] ={|f| app.expand_path(f, nil)}.freeze
39   app.plugin :render, :allowed_paths=>(app.opts[:render][:allowed_paths] + view_dirs).uniq.freeze
40 end
load_dependencies(app, view_dirs)

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

[show source]
   # File lib/roda/plugins/additional_view_directories.rb
31 def self.load_dependencies(app, view_dirs)
32   app.plugin :render
33 end