mustermann-cake 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +74 -0
- data/lib/mustermann/cake.rb +18 -0
- data/mustermann-cake.gemspec +18 -0
- data/spec/cake_spec.rb +90 -0
- metadata +63 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3b67e070f799e3a83b1420f4b14232664d0f0d1c
|
4
|
+
data.tar.gz: 8f2f5810ea3f2f9f6d709472ec9f3c377213489d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ccbe8220e866c11c742c49f3fb4fa8320f554e40551f45841c39d82e5bae325543216df9a448b2efc8d25cb6a2b84419390932881c05ff2621a85bc9d450e797
|
7
|
+
data.tar.gz: f96e25b053018916c04561878d38462a4c154ed7903a9d10e4c33a240f45584fad4396d397df743d7885641ecb807c7c26e1314939177ac613333e468f948ebf
|
data/README.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# CakePHP Syntax for Mustermann
|
2
|
+
|
3
|
+
This gem implements the `cake` pattern type for Mustermann. It is compatible with [CakePHP](http://cakephp.org/) 2.x and 3.x.
|
4
|
+
|
5
|
+
## Overview
|
6
|
+
|
7
|
+
**Supported options:**
|
8
|
+
`capture`, `except`, `greedy`, `space_matches_plus`, `uri_decode`, and `ignore_unknown_options`.
|
9
|
+
|
10
|
+
**External documentation:**
|
11
|
+
[CakePHP 2.0 Routing](http://book.cakephp.org/2.0/en/development/routing.html),
|
12
|
+
[CakePHP 3.0 Routing](http://book.cakephp.org/3.0/en/development/routing.html)
|
13
|
+
|
14
|
+
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).
|
15
|
+
|
16
|
+
``` ruby
|
17
|
+
require 'mustermann/cake'
|
18
|
+
|
19
|
+
Mustermann.new('/:name/*', type: :cake).params('/a/b/c') # => { name: 'a', splat: ['b', 'c'] }
|
20
|
+
Mustermann.new('/:name/**', type: :cake).params('/a/b/c') # => { name: 'a', splat: 'b/c' }
|
21
|
+
|
22
|
+
pattern = Mustermann.new('/:name')
|
23
|
+
|
24
|
+
pattern.respond_to? :expand # => true
|
25
|
+
pattern.expand(name: 'foo') # => '/foo'
|
26
|
+
|
27
|
+
pattern.respond_to? :to_templates # => true
|
28
|
+
pattern.to_templates # => ['/{name}']
|
29
|
+
```
|
30
|
+
|
31
|
+
## Syntax
|
32
|
+
|
33
|
+
<table>
|
34
|
+
<thead>
|
35
|
+
<tr>
|
36
|
+
<th>Syntax Element</th>
|
37
|
+
<th>Description</th>
|
38
|
+
</tr>
|
39
|
+
</thead>
|
40
|
+
<tbody>
|
41
|
+
<tr>
|
42
|
+
<td><b>:</b><i>name</i></td>
|
43
|
+
<td>
|
44
|
+
Captures anything but a forward slash in a semi-greedy fashion. Capture is named <i>name</i>.
|
45
|
+
Capture behavior can be modified with <tt>capture</tt> and <tt>greedy</tt> option.
|
46
|
+
</td>
|
47
|
+
</tr>
|
48
|
+
<tr>
|
49
|
+
<td><b>*</b></td>
|
50
|
+
<td>
|
51
|
+
Captures anything in a non-greedy fashion. Capture is named splat.
|
52
|
+
It is always an array of captures, as you can use it more than once in a pattern.
|
53
|
+
</td>
|
54
|
+
</tr>
|
55
|
+
<tr>
|
56
|
+
<td><b>**</b></td>
|
57
|
+
<td>
|
58
|
+
Captures anything in a non-greedy fashion. Capture is named splat.
|
59
|
+
It is always an array of captures, as you can use it more than once in a pattern.
|
60
|
+
The value matching a single <tt>**</tt> will be split at slashes when parsed into <tt>params</tt>.
|
61
|
+
</td>
|
62
|
+
</tr>
|
63
|
+
<tr>
|
64
|
+
<td><b>/</b></td>
|
65
|
+
<td>
|
66
|
+
Matches forward slash. Does not match URI encoded version of forward slash.
|
67
|
+
</td>
|
68
|
+
</tr>
|
69
|
+
<tr>
|
70
|
+
<td><i>any other character</i></td>
|
71
|
+
<td>Matches exactly that character or a URI encoded version of it.</td>
|
72
|
+
</tr>
|
73
|
+
</tbody>
|
74
|
+
</table>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'mustermann'
|
2
|
+
require 'mustermann/ast/pattern'
|
3
|
+
|
4
|
+
module Mustermann
|
5
|
+
# CakePHP style pattern implementation.
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
# Mustermann.new('/:foo', type: :cake) === '/bar' # => true
|
9
|
+
#
|
10
|
+
# @see Mustermann::Pattern
|
11
|
+
# @see file:README.md#cake Syntax description in the README
|
12
|
+
class Cake < AST::Pattern
|
13
|
+
register :cake
|
14
|
+
|
15
|
+
on(?:) { |c| node(:capture) { scan(/\w+/) } }
|
16
|
+
on(?*) { |c| node(:splat, convert: (-> e { e.split('/') } unless scan(?*))) }
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
$:.unshift File.expand_path("../../mustermann/lib", __FILE__)
|
2
|
+
require "mustermann/version"
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "mustermann-cake"
|
6
|
+
s.version = Mustermann::VERSION
|
7
|
+
s.author = "Konstantin Haase"
|
8
|
+
s.email = "konstantin.mailinglists@googlemail.com"
|
9
|
+
s.homepage = "https://github.com/rkh/mustermann"
|
10
|
+
s.summary = %q{CakePHP syntax for Mustermann}
|
11
|
+
s.description = %q{Adds CakePHP style patterns to Mustermman}
|
12
|
+
s.license = 'MIT'
|
13
|
+
s.required_ruby_version = '>= 2.1.0'
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.add_dependency 'mustermann', Mustermann::VERSION
|
18
|
+
end
|
data/spec/cake_spec.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'support'
|
2
|
+
require 'mustermann/cake'
|
3
|
+
|
4
|
+
describe Mustermann::Cake do
|
5
|
+
extend Support::Pattern
|
6
|
+
|
7
|
+
pattern '' do
|
8
|
+
it { should match('') }
|
9
|
+
it { should_not match('/') }
|
10
|
+
|
11
|
+
it { should expand.to('') }
|
12
|
+
it { should_not expand(a: 1) }
|
13
|
+
|
14
|
+
it { should generate_template('') }
|
15
|
+
|
16
|
+
it { should respond_to(:expand) }
|
17
|
+
it { should respond_to(:to_templates) }
|
18
|
+
end
|
19
|
+
|
20
|
+
pattern '/' do
|
21
|
+
it { should match('/') }
|
22
|
+
it { should_not match('/foo') }
|
23
|
+
|
24
|
+
it { should expand.to('/') }
|
25
|
+
it { should_not expand(a: 1) }
|
26
|
+
end
|
27
|
+
|
28
|
+
pattern '/foo' do
|
29
|
+
it { should match('/foo') }
|
30
|
+
it { should_not match('/bar') }
|
31
|
+
it { should_not match('/foo.bar') }
|
32
|
+
|
33
|
+
it { should expand.to('/foo') }
|
34
|
+
it { should_not expand(a: 1) }
|
35
|
+
end
|
36
|
+
|
37
|
+
pattern '/foo/bar' do
|
38
|
+
it { should match('/foo/bar') }
|
39
|
+
it { should_not match('/foo%2Fbar') }
|
40
|
+
it { should_not match('/foo%2fbar') }
|
41
|
+
|
42
|
+
it { should expand.to('/foo/bar') }
|
43
|
+
it { should_not expand(a: 1) }
|
44
|
+
end
|
45
|
+
|
46
|
+
pattern '/:foo' do
|
47
|
+
it { should match('/foo') .capturing foo: 'foo' }
|
48
|
+
it { should match('/bar') .capturing foo: 'bar' }
|
49
|
+
it { should match('/foo.bar') .capturing foo: 'foo.bar' }
|
50
|
+
it { should match('/%0Afoo') .capturing foo: '%0Afoo' }
|
51
|
+
it { should match('/foo%2Fbar') .capturing foo: 'foo%2Fbar' }
|
52
|
+
|
53
|
+
it { should_not match('/foo?') }
|
54
|
+
it { should_not match('/foo/bar') }
|
55
|
+
it { should_not match('/') }
|
56
|
+
it { should_not match('/foo/') }
|
57
|
+
|
58
|
+
example { pattern.params('/foo') .should be == {"foo" => "foo"} }
|
59
|
+
example { pattern.params('/f%20o') .should be == {"foo" => "f o"} }
|
60
|
+
example { pattern.params('').should be_nil }
|
61
|
+
|
62
|
+
it { should expand(foo: 'bar') .to('/bar') }
|
63
|
+
it { should expand(foo: 'b r') .to('/b%20r') }
|
64
|
+
it { should expand(foo: 'foo/bar') .to('/foo%2Fbar') }
|
65
|
+
|
66
|
+
it { should_not expand(foo: 'foo', bar: 'bar') }
|
67
|
+
it { should_not expand(bar: 'bar') }
|
68
|
+
it { should_not expand }
|
69
|
+
|
70
|
+
it { should generate_template('/{foo}') }
|
71
|
+
end
|
72
|
+
|
73
|
+
pattern '/*' do
|
74
|
+
it { should match('/') }
|
75
|
+
it { should match('/foo') }
|
76
|
+
it { should match('/foo/bar') }
|
77
|
+
|
78
|
+
example { pattern.params('/foo/bar') .should be == {"splat" => ["foo", "bar"]}}
|
79
|
+
it { should generate_template('/{+splat}') }
|
80
|
+
end
|
81
|
+
|
82
|
+
pattern '/**' do
|
83
|
+
it { should match('/') .capturing splat: '' }
|
84
|
+
it { should match('/foo') .capturing splat: 'foo' }
|
85
|
+
it { should match('/foo/bar') .capturing splat: 'foo/bar' }
|
86
|
+
|
87
|
+
example { pattern.params('/foo/bar') .should be == {"splat" => ["foo/bar"]} }
|
88
|
+
it { should generate_template('/{+splat}') }
|
89
|
+
end
|
90
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mustermann-cake
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Konstantin Haase
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mustermann
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.4.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.4.0
|
27
|
+
description: Adds CakePHP style patterns to Mustermman
|
28
|
+
email: konstantin.mailinglists@googlemail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- README.md
|
34
|
+
- lib/mustermann/cake.rb
|
35
|
+
- mustermann-cake.gemspec
|
36
|
+
- spec/cake_spec.rb
|
37
|
+
homepage: https://github.com/rkh/mustermann
|
38
|
+
licenses:
|
39
|
+
- MIT
|
40
|
+
metadata: {}
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 2.1.0
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 2.4.3
|
58
|
+
signing_key:
|
59
|
+
specification_version: 4
|
60
|
+
summary: CakePHP syntax for Mustermann
|
61
|
+
test_files:
|
62
|
+
- spec/cake_spec.rb
|
63
|
+
has_rdoc:
|