Module: Roda::RodaPlugins::AdditionalViewDirectories
- Defined in:
- lib/roda/plugins/additional_view_directories.rb
Overview
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.
Example:
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
end
Defined Under Namespace
Modules: InstanceMethods
Class Method Summary collapse
-
.configure(app, view_dirs) ⇒ Object
Set the additional view directories to look in.
-
.load_dependencies(app, view_dirs) ⇒ Object
Depend on the render plugin, since this plugin only makes sense when the render plugin is used.
Class Method Details
.configure(app, view_dirs) ⇒ Object
Set the additional view directories to look in. Each additional view directory is also added as an allowed path.
37 38 39 40 |
# File 'lib/roda/plugins/additional_view_directories.rb', line 37 def self.configure(app, view_dirs) view_dirs = app.opts[:additional_view_directories] = view_dirs.map{|f| app.(f, nil)}.freeze app.plugin :render, :allowed_paths=>(app.opts[:render][:allowed_paths] + view_dirs).uniq.freeze end |
.load_dependencies(app, view_dirs) ⇒ Object
Depend on the render plugin, since this plugin only makes sense when the render plugin is used.
31 32 33 |
# File 'lib/roda/plugins/additional_view_directories.rb', line 31 def self.load_dependencies(app, view_dirs) app.plugin :render end |