Module: Roda::RodaPlugins::MatchAffix
- Defined in:
- lib/roda/plugins/match_affix.rb
Overview
The match_affix plugin allows changing the default prefix and suffix used for match patterns. Roda’s default behavior for a match pattern like "albums"
is to use the pattern /\A\/(?:albums)(?=\/|\z)/
. This prefixes the pattern with /
and suffixes it with (?=\/|\z)
. With the match_affix plugin, you can change the prefix and suffix to use. So if you want to be explicit and require a leading /
in patterns, you can set the prefix to ""
. If you want to consume a trailing slash instead of leaving it, you can set the suffix to (\/|\z)
.
You set the prefix and suffix to use by passing arguments when loading the plugin:
plugin :match_affix, ""
will load the plugin and use an empty prefix (instead of a slash).
plugin :match_affix, "", /(\/|\z)/
will use an empty prefix and change the suffix to consume a trailing slash.
plugin :match_affix, nil, /(?:\/\z|(?=\/|\z))/
will not modify the prefix and will change the suffix so that it consumes a trailing slash at the end of the path only.
This plugin automatically loads the placeholder_string_matchers plugin.
Defined Under Namespace
Modules: RequestClassMethods, RequestMethods
Class Method Summary collapse
-
.configure(app, prefix, suffix = nil) ⇒ Object
Set the default prefix and suffix to use in match patterns, if a non-nil value is given.
- .load_dependencies(app, _prefix, _suffix = nil) ⇒ Object
Class Method Details
.configure(app, prefix, suffix = nil) ⇒ Object
Set the default prefix and suffix to use in match patterns, if a non-nil value is given.
37 38 39 40 |
# File 'lib/roda/plugins/match_affix.rb', line 37 def self.configure(app, prefix, suffix=nil) app.opts[:match_prefix] = prefix if prefix app.opts[:match_suffix] = suffix if suffix end |
.load_dependencies(app, _prefix, _suffix = nil) ⇒ Object
31 32 33 |
# File 'lib/roda/plugins/match_affix.rb', line 31 def self.load_dependencies(app, _prefix, _suffix=nil) app.plugin :placeholder_string_matchers end |