mustermann-pyramid 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +68 -0
- data/lib/mustermann/pyramid.rb +28 -0
- data/mustermann-pyramid.gemspec +18 -0
- data/spec/pyramid_spec.rb +101 -0
- metadata +63 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6ae0f487c444b6e23b9f10327f8634d52d0294e8
|
4
|
+
data.tar.gz: 0a6735a1fa112dd9288ee18ef294bdacdd046337
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e3e78a3219e5b46212c81c814fba0908a56f3fa812812e10f5276614d780d423ab8fcb8f58481d896fe69efe046892be5d224d34eb2059b61977f517696b9ff6
|
7
|
+
data.tar.gz: 2bc10d144d929044247af515033c9d194747672a26437d895ee30b0c7c8d0377af1aea70f716863e26c3a93b78f553fefac572493569af9791ec6161906d427a
|
data/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# Pyramid Syntax for Mustermann
|
2
|
+
|
3
|
+
This gem implements the `pyramid` pattern type for Mustermann. It is compatible with [Pyramid](http://www.pylonsproject.org/projects/pyramid/about) and [Pylons](http://www.pylonsproject.org/projects/pylons-framework/about).
|
4
|
+
|
5
|
+
## Overview
|
6
|
+
|
7
|
+
**Supported options:**
|
8
|
+
`capture`, `except`, `greedy`, `space_matches_plus`, `uri_decode` and `ignore_unknown_options`
|
9
|
+
|
10
|
+
**External Documentation:** [Pylons Framework: URL Configuration](http://docs.pylonsproject.org/projects/pylons-webframework/en/latest/configuration.html#url-config), [Pylons Book: Routes in Detail](http://pylonsbook.com/en/1.0/urls-routing-and-dispatch.html#routes-in-detail), [Pyramid: Route Pattern Syntax](http://docs.pylonsproject.org/projects/pyramid/en/1.5-branch/narr/urldispatch.html#route-pattern-syntax)
|
11
|
+
|
12
|
+
``` ruby
|
13
|
+
require 'mustermann/pyramid'
|
14
|
+
|
15
|
+
Mustermann.new('/{prefix}/*suffix', type: :pyramid).params('/a/b/c') # => { prefix: 'a', suffix: ['b', 'c'] }
|
16
|
+
|
17
|
+
pattern = Mustermann.new('/{name}', type: :pyramid)
|
18
|
+
|
19
|
+
pattern.respond_to? :expand # => true
|
20
|
+
pattern.expand(name: 'foo') # => '/foo'
|
21
|
+
|
22
|
+
pattern.respond_to? :to_templates # => true
|
23
|
+
pattern.to_templates # => ['/{name}']
|
24
|
+
```
|
25
|
+
|
26
|
+
## Syntax
|
27
|
+
|
28
|
+
|
29
|
+
<table>
|
30
|
+
<thead>
|
31
|
+
<tr>
|
32
|
+
<th>Syntax Element</th>
|
33
|
+
<th>Description</th>
|
34
|
+
</tr>
|
35
|
+
</thead>
|
36
|
+
<tbody>
|
37
|
+
<tr>
|
38
|
+
<td><b>{</b><i>name</i><b>}</b></td>
|
39
|
+
<td>
|
40
|
+
Captures anything but a forward slash in a semi-greedy fashion. Capture is named <i>name</i>.
|
41
|
+
Capture behavior can be modified with <tt>capture</tt> and <tt>greedy</tt> option.
|
42
|
+
</td>
|
43
|
+
</tr>
|
44
|
+
<tr>
|
45
|
+
<td><b>{</b><i>name</i><b>:</b><i>regexp</i><b>}</b></td>
|
46
|
+
<td>
|
47
|
+
Captures anything matching the <i>regexp</i> regular expression. Capture is named <i>name</i>.
|
48
|
+
Capture behavior can be modified with <tt>capture</tt>.
|
49
|
+
</td>
|
50
|
+
</tr>
|
51
|
+
<tr>
|
52
|
+
<td><b>*</b><i>name</i></td>
|
53
|
+
<td>
|
54
|
+
Captures anything in a non-greedy fashion. Capture is named <i>name</i>.
|
55
|
+
</td>
|
56
|
+
</tr>
|
57
|
+
<tr>
|
58
|
+
<td><b>/</b></td>
|
59
|
+
<td>
|
60
|
+
Matches forward slash. Does not match URI encoded version of forward slash.
|
61
|
+
</td>
|
62
|
+
</tr>
|
63
|
+
<tr>
|
64
|
+
<td><i>any other character</i></td>
|
65
|
+
<td>Matches exactly that character or a URI encoded version of it.</td>
|
66
|
+
</tr>
|
67
|
+
</tbody>
|
68
|
+
</table>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'mustermann'
|
2
|
+
require 'mustermann/ast/pattern'
|
3
|
+
|
4
|
+
module Mustermann
|
5
|
+
# Pyramid style pattern implementation.
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
# Mustermann.new('/<foo>', type: :pryamid) === '/bar' # => true
|
9
|
+
#
|
10
|
+
# @see Mustermann::Pattern
|
11
|
+
# @see file:README.md#pryamid Syntax description in the README
|
12
|
+
class Pyramid < AST::Pattern
|
13
|
+
register :pyramid
|
14
|
+
|
15
|
+
on(nil, ?}) { |c| unexpected(c) }
|
16
|
+
|
17
|
+
on(?{) do |char|
|
18
|
+
name = expect(/\w+/, char: char)
|
19
|
+
constraint = read_brackets(?{, ?}) if scan(?:)
|
20
|
+
expect(?}) unless constraint
|
21
|
+
node(:capture, name, constraint: constraint)
|
22
|
+
end
|
23
|
+
|
24
|
+
on(?*) do |char|
|
25
|
+
node(:named_splat, expect(/\w+$/, char: char), convert: -> e { e.split(?/) })
|
26
|
+
end
|
27
|
+
end
|
28
|
+
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-pyramid"
|
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{Pyramid syntax for Mustermann}
|
11
|
+
s.description = %q{Adds Pyramid 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
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'support'
|
2
|
+
require 'mustermann/pyramid'
|
3
|
+
|
4
|
+
describe Mustermann::Pyramid 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 '/*foo' do
|
74
|
+
it { should match('/foo') .capturing foo: 'foo' }
|
75
|
+
it { should match('/foo/bar') .capturing foo: 'foo/bar' }
|
76
|
+
|
77
|
+
it { should expand .to('/') }
|
78
|
+
it { should expand(foo: nil) .to('/') }
|
79
|
+
it { should expand(foo: '') .to('/') }
|
80
|
+
it { should expand(foo: 'foo') .to('/foo') }
|
81
|
+
it { should expand(foo: 'foo/bar') .to('/foo/bar') }
|
82
|
+
it { should expand(foo: 'foo.bar') .to('/foo.bar') }
|
83
|
+
|
84
|
+
example { pattern.params("/foo/bar").should be == {"foo" => ["foo", "bar"]}}
|
85
|
+
it { should generate_template('/{+foo}') }
|
86
|
+
end
|
87
|
+
|
88
|
+
pattern '/{foo:.*}' do
|
89
|
+
it { should match('/') .capturing foo: '' }
|
90
|
+
it { should match('/foo') .capturing foo: 'foo' }
|
91
|
+
it { should match('/foo/bar') .capturing foo: 'foo/bar' }
|
92
|
+
|
93
|
+
it { should expand(foo: '') .to('/') }
|
94
|
+
it { should expand(foo: 'foo') .to('/foo') }
|
95
|
+
it { should expand(foo: 'foo/bar') .to('/foo/bar') }
|
96
|
+
it { should expand(foo: 'foo.bar') .to('/foo.bar') }
|
97
|
+
|
98
|
+
example { pattern.params("/foo/bar").should be == {"foo" => "foo/bar"}}
|
99
|
+
it { should generate_template('/{foo}') }
|
100
|
+
end
|
101
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mustermann-pyramid
|
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 Pyramid 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/pyramid.rb
|
35
|
+
- mustermann-pyramid.gemspec
|
36
|
+
- spec/pyramid_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: Pyramid syntax for Mustermann
|
61
|
+
test_files:
|
62
|
+
- spec/pyramid_spec.rb
|
63
|
+
has_rdoc:
|