module Roda::RodaPlugins::ViewSubdirLeadingSlash

  1. lib/roda/plugins/view_subdir_leading_slash.rb

The view_subdir_leading_slash plugin builds on the view_options plugin, and changes the behavior so that if a view subdir is set, it is used for all templates, unless the template starts with a leading slash:

plugin :view_subdir_leading_slash

route do |r|
  r.on "users" do
    set_view_subdir 'users'

    r.get 'list' do
      view 'lists/users' # uses ./views/users/lists/users.erb
    end

    r.get 'list' do
      view '/lists/users' # uses ./views//lists/users.erb
    end
  end
end

The default for the view_options plugin is to not use a view subdir if the template name contains a slash at all.

Methods

Public Class

  1. load_dependencies

Public Class methods

load_dependencies(app)

Load the view_options plugin before this plugin, since this plugin works by overriding a method in the view_options plugin.

[show source]
   # File lib/roda/plugins/view_subdir_leading_slash.rb
32 def self.load_dependencies(app)
33   app.plugin :view_options
34 end