named-routes 0.1.0 → 0.1.2
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.
- data/README.md +21 -19
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/lib/named-routes.rb +4 -5
- data/lib/named-routes/routes.rb +2 -2
- data/spec/named-routes/routes_spec.rb +1 -1
- metadata +19 -5
data/README.md
CHANGED
@@ -6,6 +6,8 @@ A simple and generic named routes api. It works really well with Sinatra.
|
|
6
6
|
|
7
7
|
gem install named-routes
|
8
8
|
|
9
|
+
require "named-routes"
|
10
|
+
|
9
11
|
## Route Definitions
|
10
12
|
|
11
13
|
You can define a named route by providing the name of the method and the definition.
|
@@ -35,7 +37,7 @@ If you have multiple handlers for the same route, you can use the block syntax:
|
|
35
37
|
You can also define prefixes on the route definitions:
|
36
38
|
|
37
39
|
include NamedRoutes
|
38
|
-
|
40
|
+
paths.prefix = "admin"
|
39
41
|
|
40
42
|
path(:user, "/users/:user_id") do |_| # => /admin/users/:user_id
|
41
43
|
get _ do
|
@@ -52,29 +54,29 @@ You can also define prefixes on the route definitions:
|
|
52
54
|
You can access the routes by doing the following.
|
53
55
|
|
54
56
|
include NamedRoutes
|
55
|
-
|
57
|
+
paths.host = "example.com"
|
56
58
|
path(:user, "/users/:user_id")
|
57
|
-
|
58
|
-
|
59
|
-
|
59
|
+
paths.user(:user_id => 42) # => "/users/42"
|
60
|
+
paths.http.user(:user_id => 42) # => "http://example.com/users/42"
|
61
|
+
paths.https.user(:user_id => 42) # => "http://example.com/users/42"
|
60
62
|
|
61
63
|
It also works with prefixes:
|
62
64
|
|
63
65
|
include NamedRoutes
|
64
|
-
|
65
|
-
|
66
|
+
paths.host = "example.com"
|
67
|
+
paths.prefix = "admin"
|
66
68
|
path(:user, "/users/:user_id")
|
67
|
-
|
68
|
-
|
69
|
-
|
69
|
+
paths.user(:user_id => 42) # => "/users/42"
|
70
|
+
paths.http.user(:user_id => 42) # => "http://example.com/admin/users/42"
|
71
|
+
paths.https.user(:user_id => 42) # => "http://example.com/admin/users/42"
|
70
72
|
|
71
73
|
And with query params:
|
72
74
|
|
73
75
|
include NamedRoutes
|
74
|
-
|
75
|
-
|
76
|
+
paths.host = "example.com"
|
77
|
+
paths.prefix = "admin"
|
76
78
|
path(:user, "/users/:user_id")
|
77
|
-
|
79
|
+
paths.user(:user_id => 42, :foo => "bar of soap") # => "/users/42&foo=bar+of+soap"
|
78
80
|
|
79
81
|
## Advanced Usages
|
80
82
|
|
@@ -88,24 +90,24 @@ You can also inherit Routes to have different sets of Routes. This is useful if
|
|
88
90
|
self.prefix = "partay"
|
89
91
|
end
|
90
92
|
|
91
|
-
def
|
93
|
+
def admin_paths
|
92
94
|
AdminRoutes
|
93
95
|
end
|
94
96
|
|
95
|
-
def
|
97
|
+
def partay_paths
|
96
98
|
PartayRoutes
|
97
99
|
end
|
98
100
|
|
99
|
-
get
|
101
|
+
get admin_paths.path(:user, "/users/:user_id") do # => /admin/users/:user_id
|
100
102
|
# ...
|
101
103
|
end
|
102
104
|
|
103
|
-
|
105
|
+
admin_paths.user(:user_id => 42) # => "/admin/users/42"
|
104
106
|
|
105
|
-
get
|
107
|
+
get partay_paths.path(:user, "/users/:user_id") do # => /partay/users/:user_id
|
106
108
|
# ...
|
107
109
|
end
|
108
110
|
|
109
|
-
|
111
|
+
partay_paths.user(:user_id => 42, :beer => "pabst") # => "/partay/users/42&beer=pabst"
|
110
112
|
|
111
113
|
Copyright (c) 2010 Brian Takita. This software is licensed under the MIT License.
|
data/Rakefile
CHANGED
@@ -22,6 +22,7 @@ begin
|
|
22
22
|
s.has_rdoc = true
|
23
23
|
s.extra_rdoc_files = [ "README.md", "CHANGES" ]
|
24
24
|
s.rdoc_options = ["--main", "README.md", "--inline-source", "--line-numbers"]
|
25
|
+
s.add_dependency "activesupport", ">= 2.3"
|
25
26
|
end
|
26
27
|
rescue LoadError
|
27
28
|
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/lib/named-routes.rb
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
require "
|
2
|
-
require "active_support/hash_with_indifferent_access"
|
3
|
-
require "active_support/core_ext"
|
4
|
-
require "active_support/core_ext"
|
1
|
+
require "extlib"
|
5
2
|
require "uri"
|
6
3
|
|
7
4
|
module NamedRoutes
|
@@ -9,9 +6,11 @@ module NamedRoutes
|
|
9
6
|
routes.path(*args, &block)
|
10
7
|
end
|
11
8
|
|
12
|
-
def
|
9
|
+
def paths
|
13
10
|
::NamedRoutes::Routes
|
14
11
|
end
|
12
|
+
alias_method :routes, :paths
|
13
|
+
|
15
14
|
extend self
|
16
15
|
end
|
17
16
|
|
data/lib/named-routes/routes.rb
CHANGED
@@ -25,7 +25,7 @@ module NamedRoutes
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def eval(definition, params_arg={})
|
28
|
-
params =
|
28
|
+
params = Mash.new(params_arg)
|
29
29
|
path_string = if params.empty?
|
30
30
|
definition
|
31
31
|
else
|
@@ -42,7 +42,7 @@ module NamedRoutes
|
|
42
42
|
end.join("/")
|
43
43
|
end
|
44
44
|
unless params.empty?
|
45
|
-
path_string << "?#{params.
|
45
|
+
path_string << "?#{escape_params(params).to_params.gsub("%20", "+")}"
|
46
46
|
end
|
47
47
|
path_string
|
48
48
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: named-routes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Brian Takita
|
@@ -17,8 +17,22 @@ cert_chain: []
|
|
17
17
|
|
18
18
|
date: 2010-10-20 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
|
-
dependencies:
|
21
|
-
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: activesupport
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 5
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 3
|
33
|
+
version: "2.3"
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
22
36
|
description:
|
23
37
|
email: brian.takita@gmail.com
|
24
38
|
executables: []
|