zooplankton 1.1.0 → 1.2.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 +4 -4
- data/.travis.yml +1 -0
- data/CHANGES.md +5 -0
- data/README.md +83 -34
- data/lib/zooplankton/version.rb +1 -1
- data/lib/zooplankton.rb +1 -1
- data/zooplankton.gemspec +1 -1
- metadata +20 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c878d585575f883e203938c61e037c88a667446b
|
4
|
+
data.tar.gz: 0636a9f4041b56d76e419b2e9c25ea0a70b5f4ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48c544b8b85fd25ccddab92c59a3c188d25939214a18ee531a313f9071b531f9df1d70dc1fb1c36dfd7d9621ca88ed81fffc68c91e3e3be70c3c4968d10a724b
|
7
|
+
data.tar.gz: 1334e12ea45556b4e50dea5fe21c583b6d745b4a43f075adf02829b02b53cb3180ed0197b42e2070bd9f8d0353dce1f9ddb2c279427e37fcbc56fc1e35eac8cc
|
data/.travis.yml
CHANGED
data/CHANGES.md
CHANGED
data/README.md
CHANGED
@@ -1,23 +1,14 @@
|
|
1
|
-
# Zooplankton
|
1
|
+
# Zooplankton
|
2
2
|
|
3
|
-
|
4
|
-
[
|
5
|
-
helping yourself generate the `_links` part of
|
6
|
-
[HAL](http://stateless.co/hal_specification.html), for example.
|
3
|
+
[](https://travis-ci.org/benhamill/zooplankton)
|
4
|
+
[](https://codeclimate.com/github/benhamill/zooplankton)
|
7
5
|
|
8
|
-
|
6
|
+
[Zooplankton](http://en.wikipedia.org/wiki/Zooplankton) are the kind of
|
7
|
+
plankton that are animals (as opposed to phytoplankton, which are plants).
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
And then execute:
|
15
|
-
|
16
|
-
$ bundle
|
17
|
-
|
18
|
-
Or install it yourself as:
|
19
|
-
|
20
|
-
$ gem install zooplankton
|
9
|
+
Zooplankton is a library for helping you turn Rails routes into [URI Template
|
10
|
+
strings](#uri-templates-lolwut). It's useful for helping yourself generate the
|
11
|
+
`_links` part of [HAL](http://stateless.co/hal_specification.html), for example.
|
21
12
|
|
22
13
|
## Usage
|
23
14
|
|
@@ -26,47 +17,67 @@ Given a route file like this:
|
|
26
17
|
```ruby
|
27
18
|
SomeApp::Application.routes.draw do
|
28
19
|
root 'root#index'
|
29
|
-
get '/
|
30
|
-
get '/
|
20
|
+
get '/posts/:slug', to: 'posts#show', as: :post
|
21
|
+
get '/posts/:slug/comments', to: 'comments#index', as: :comments
|
22
|
+
get '/posts/:slug/comments/:comment_id', to: 'commendts#show', as: :comment
|
31
23
|
end
|
32
24
|
```
|
33
25
|
|
34
|
-
|
26
|
+
Without Zooplankton, you might end up generating a URI template for a route by
|
27
|
+
abusing Rails's url helpers like this:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
CGI.unescape post_path(slug: "{slug}")
|
31
|
+
# => '/posts/{slug}'
|
32
|
+
CGI.unescape comment_path(slug: "{slug}", comment_id: "{comment_id}")
|
33
|
+
# => '/posts/{slug}/comments/{comment_id}'
|
34
|
+
```
|
35
|
+
|
36
|
+
If you needed to include query parameters in your template, you'd have an even
|
37
|
+
harder time. Something like:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
CGI.unescape "#{comments_path(slug: "{slug}")}{?page,page_size}"
|
41
|
+
# => '/posts/{slug}/comments{?page,page_size}'
|
42
|
+
```
|
43
|
+
|
44
|
+
With Zooplankton, you can use it like this:
|
35
45
|
|
36
46
|
```ruby
|
37
47
|
> Zooplankton.path_template_for(:root)
|
38
48
|
# => '/'
|
39
49
|
> Zooplankton.path_template_for(:post)
|
40
|
-
# => '/
|
50
|
+
# => '/posts/{slug}'
|
41
51
|
> Zooplankton.path_template_for(:comment)
|
42
|
-
# => '/
|
52
|
+
# => '/posts/{slug}/comments/{comment_id}'
|
43
53
|
```
|
44
54
|
|
45
|
-
It also handles replacing some (or all
|
46
|
-
|
55
|
+
It also handles replacing some (or all, though you might decide to use a Rails
|
56
|
+
url helper at that point) of the templated variables if you want to prepopulate
|
57
|
+
some of them ahead of time:
|
47
58
|
|
48
59
|
``` ruby
|
49
60
|
> Zooplankton.path_template_for(:comment, slug: 'the-best-post-ever')
|
50
|
-
# => '/
|
61
|
+
# => '/posts/the-best-post-ever/comments/{comment_id}'
|
51
62
|
```
|
52
63
|
|
53
64
|
And you can add some query parameters when you're generating the template, if
|
54
65
|
you need:
|
55
66
|
|
56
67
|
``` ruby
|
57
|
-
> Zooplankton.path_template_for(:
|
58
|
-
# => '/
|
59
|
-
> Zooplankton.path_template_for(:
|
60
|
-
# => '/
|
61
|
-
> Zooplankton.path_template_for(:
|
62
|
-
# => '/
|
68
|
+
> Zooplankton.path_template_for(:comments, :page, slug: 'the-best-post-ever')
|
69
|
+
# => '/posts/the-best-post-ever/comments{?page}'
|
70
|
+
> Zooplankton.path_template_for(:comments, %i(page page_size), slug: 'the-best-post-ever')
|
71
|
+
# => '/posts/the-best-post-ever/comments{?page,page_size}'
|
72
|
+
> Zooplankton.path_template_for(:comments, %i(page page_size))
|
73
|
+
# => '/posts/{slug}/comments{?page,page_size}'
|
63
74
|
```
|
64
75
|
|
65
76
|
If you supply a query parameter for replacement, it'll denote a continuation:
|
66
77
|
|
67
78
|
``` ruby
|
68
|
-
> Zooplankton.path_template_for(:
|
69
|
-
# => '/
|
79
|
+
> Zooplankton.path_template_for(:comments, %i(page page_size), slug: 'the-best-post-ever', page: 1)
|
80
|
+
# => '/posts/the-best-post-ever/comments?page=1{&page_size}'
|
70
81
|
```
|
71
82
|
|
72
83
|
It'll generate URLs, too, not just paths.
|
@@ -75,9 +86,47 @@ It'll generate URLs, too, not just paths.
|
|
75
86
|
> Zooplankton.url_template_for(:root)
|
76
87
|
# => 'http://example.com/'
|
77
88
|
> Zooplankton.url_template_for(:post)
|
78
|
-
# => 'http://example.com/
|
89
|
+
# => 'http://example.com/posts/{slug}'
|
79
90
|
```
|
80
91
|
|
92
|
+
## URI Templates LOLWUT
|
93
|
+
|
94
|
+
[URI Templates](http://tools.ietf.org/html/rfc6570) are a notation for teaching
|
95
|
+
machines how to build URIs. They're basically rules for string interpolation.
|
96
|
+
Zooplankton supports a small subset of all the notations, outlined here.
|
97
|
+
|
98
|
+
### Simple String Expansion
|
99
|
+
|
100
|
+
[RFC direct link](http://tools.ietf.org/html/rfc6570#section-3.2.2)
|
101
|
+
|
102
|
+
This is the simplest part of URI Templates and is what Zooplankton uses for
|
103
|
+
parameters that are part of the path of a URI. Basically, given a template like
|
104
|
+
`"foo{var}baz"` and assuming you have a value of `'bar'` for `var`, you'd end up
|
105
|
+
with `"foobarbaz"`.
|
106
|
+
|
107
|
+
### Form-Style Query Expansion
|
108
|
+
|
109
|
+
[RFC direct link](http://tools.ietf.org/html/rfc6570#section-3.2.8)
|
110
|
+
|
111
|
+
This expansion is for telling a computer to build a query string. Something like
|
112
|
+
`"name{?first,last}" with values like in the hash `{first: 'ben', last:
|
113
|
+
'hamill'}` would expand to `"name?first=ben&last=hamill"`. Zooplankton will use
|
114
|
+
this when it's appropriate for building query strings.
|
115
|
+
|
116
|
+
### Form-Style Query Continuation
|
117
|
+
|
118
|
+
[RFC direct link](http://tools.ietf.org/html/rfc6570#section-3.2.9)
|
119
|
+
|
120
|
+
This expansion is for telling a computer to finish off a query string that
|
121
|
+
you've already started. Basically, it's like a query expansion, but instructs
|
122
|
+
the computer to use a starting `&`, rather than a `?`. So `"name{&first,last}"`
|
123
|
+
with values like `{first: 'ben', last: 'hamill'}` would end up as
|
124
|
+
`"name&first=ben&last=hamill"`, but the greatest usefulness is for something
|
125
|
+
like `"name?middle=dale{?first,last}"` which would end up as
|
126
|
+
`"name?middle=dale&first=ben&last=hamill"`. Zooplankton will use this when it's
|
127
|
+
appropriate for building query strings.
|
128
|
+
|
129
|
+
|
81
130
|
## Contributing
|
82
131
|
|
83
132
|
Help is gladly welcomed. If you have a feature you'd like to add, it's much more
|
data/lib/zooplankton/version.rb
CHANGED
data/lib/zooplankton.rb
CHANGED
data/zooplankton.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["git-commits@benhamill.com"]
|
11
11
|
spec.description = %q{A library for turning Rails routes into URI Templates, like maybe for HAL.}
|
12
12
|
spec.summary = %q{A library for turning Rails routes into URI Templates.}
|
13
|
-
spec.homepage = "https://github.com/benhamill/zooplankton#
|
13
|
+
spec.homepage = "https://github.com/benhamill/zooplankton#readme"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
metadata
CHANGED
@@ -1,83 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zooplankton
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Hamill
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.3'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: pry
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '2.14'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '2.14'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rails
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - ~>
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '4.0'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - ~>
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '4.0'
|
83
83
|
description: A library for turning Rails routes into URI Templates, like maybe for
|
@@ -88,9 +88,9 @@ executables: []
|
|
88
88
|
extensions: []
|
89
89
|
extra_rdoc_files: []
|
90
90
|
files:
|
91
|
-
- .gitignore
|
92
|
-
- .rspec
|
93
|
-
- .travis.yml
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".travis.yml"
|
94
94
|
- CHANGES.md
|
95
95
|
- Gemfile
|
96
96
|
- LICENSE.txt
|
@@ -101,7 +101,7 @@ files:
|
|
101
101
|
- spec/spec_helper.rb
|
102
102
|
- spec/zooplankton_spec.rb
|
103
103
|
- zooplankton.gemspec
|
104
|
-
homepage: https://github.com/benhamill/zooplankton#
|
104
|
+
homepage: https://github.com/benhamill/zooplankton#readme
|
105
105
|
licenses:
|
106
106
|
- MIT
|
107
107
|
metadata: {}
|
@@ -111,20 +111,21 @@ require_paths:
|
|
111
111
|
- lib
|
112
112
|
required_ruby_version: !ruby/object:Gem::Requirement
|
113
113
|
requirements:
|
114
|
-
- -
|
114
|
+
- - ">="
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
version: '0'
|
117
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
118
|
requirements:
|
119
|
-
- -
|
119
|
+
- - ">="
|
120
120
|
- !ruby/object:Gem::Version
|
121
121
|
version: '0'
|
122
122
|
requirements: []
|
123
123
|
rubyforge_project:
|
124
|
-
rubygems_version: 2.
|
124
|
+
rubygems_version: 2.2.2
|
125
125
|
signing_key:
|
126
126
|
specification_version: 4
|
127
127
|
summary: A library for turning Rails routes into URI Templates.
|
128
128
|
test_files:
|
129
129
|
- spec/spec_helper.rb
|
130
130
|
- spec/zooplankton_spec.rb
|
131
|
+
has_rdoc:
|