CakePHP Syntax for Mustermann

This gem implements the cake pattern type for Mustermann. It is compatible with CakePHP 2.x and 3.x.

Overview

Supported options: capture, except, greedy, space_matches_plus, uri_decode, and ignore_unknown_options.

External documentation: CakePHP 2.0 Routing, CakePHP 3.0 Routing

CakePHP patterns feature captures and unnamed splats. Captures are prefixed with a colon and splats are either a single asterisk (parsing segments into an array) or a double asterisk (parsing segments as a single string).

require 'mustermann/cake'

Mustermann.new('/:name/*',  type: :cake).params('/a/b/c') # => { name: 'a', splat: ['b', 'c'] }
Mustermann.new('/:name/**', type: :cake).params('/a/b/c') # => { name: 'a', splat: 'b/c' }

pattern = Mustermann.new('/:name')

pattern.respond_to? :expand # => true
pattern.expand(name: 'foo') # => '/foo'

pattern.respond_to? :to_templates # => true
pattern.to_templates              # => ['/{name}']

Syntax

Syntax Element Description
:name Captures anything but a forward slash in a semi-greedy fashion. Capture is named name. Capture behavior can be modified with capture and greedy option.
* Captures anything in a non-greedy fashion. Capture is named splat. It is always an array of captures, as you can use it more than once in a pattern.
** Captures anything in a non-greedy fashion. Capture is named splat. It is always an array of captures, as you can use it more than once in a pattern. The value matching a single ** will be split at slashes when parsed into params.
/ Matches forward slash. Does not match URI encoded version of forward slash.
any other character Matches exactly that character or a URI encoded version of it.