coffee_routes 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -1
- data/lib/coffee_routes/version.rb +1 -1
- data/vendor/assets/javascripts/coffee_routes.coffee.erb +15 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa05708db5df8866ba3d2afae4525f55e3720b3e
|
4
|
+
data.tar.gz: 7c494d355047a7ec277f9b210cbd8384aca8d64f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de54c9739b7fa86e6a661bbe1dd0bde95e02d2b84c1d07911adeedcac4d210622a1fbb9d736ed1d18460a600a496047b59d098953816f3d70ae0543512ca4902
|
7
|
+
data.tar.gz: e447455fa90f3b44294b12c0494577ec6c0c25e75fb21c4e5d16c470ef553234c1505643365a26c8a7e6d31ec4bbe6a54be2521024ebcd8a64019e5ff2a64c71
|
data/README.md
CHANGED
@@ -28,11 +28,14 @@ Include coffee_routes in your application.coffeee
|
|
28
28
|
|
29
29
|
You should now have the CoffeeRoutes object in your global javascript scope.
|
30
30
|
|
31
|
-
To access a named route,
|
31
|
+
To access a named route, you can use the CoffeeRoute.path helper directly or you can use the global _path helper that is attached to window that you can call just like you would when writing a rails view.
|
32
32
|
|
33
33
|
```coffee
|
34
34
|
CoffeeRoutes.path('project_item')
|
35
35
|
=> "/projects/:project_id/item/:id"
|
36
|
+
|
37
|
+
project_item_path()
|
38
|
+
=> "/projects/:project_id/item/:id"
|
36
39
|
```
|
37
40
|
|
38
41
|
To substitute in the parameter values pass in a hash.
|
@@ -40,6 +43,9 @@ To substitute in the parameter values pass in a hash.
|
|
40
43
|
```coffee
|
41
44
|
CoffeeRoutes.path('project_item', {"project_id" : "project-awesome", "id" : 5})
|
42
45
|
=> "/projects/project-awesome/items/5"
|
46
|
+
|
47
|
+
project_item_path({"project_id" : "project-awesome", "id" : 5})
|
48
|
+
=> "/projects/project-awesome/items/5"
|
43
49
|
```
|
44
50
|
|
45
51
|
You can also get the HTTP verb that should be used with the named route.
|
@@ -1,20 +1,34 @@
|
|
1
1
|
window.CoffeeRoutes =
|
2
|
+
# Store a routing table as created by ActionDispatch::Routing::JSONFormatter
|
2
3
|
routes: <%= CoffeeRoutes.routes %>
|
3
4
|
|
5
|
+
# Calculate get the path from a name and substitute in any parameters
|
4
6
|
path: (path, params)->
|
5
7
|
params ||= {}
|
6
8
|
if @routes[path]?
|
7
9
|
route = @routes[path]
|
10
|
+
# Remote the (.:format) from the end of the path string
|
8
11
|
path = route.path.replace(/\(.\:format\)$/, '')
|
12
|
+
|
13
|
+
# Replace the :params in the path for values from the params
|
9
14
|
path = path.replace /:[a-z0-9_\-]+/gi, (match)->
|
10
15
|
key = match.replace(/^:/, '')
|
11
16
|
if params[key]? then params[key] else match
|
12
17
|
|
18
|
+
# Add a format parameter if one is passed in params
|
13
19
|
if params['format']?
|
14
20
|
path += ".#{params['format']}"
|
15
21
|
|
16
22
|
path
|
17
23
|
|
24
|
+
# Grab the HTTP verb for the given named route
|
18
25
|
method: (path)->
|
19
26
|
if @routes[path]?
|
20
|
-
@routes[path].verb
|
27
|
+
@routes[path].verb
|
28
|
+
|
29
|
+
# Create global function delcarations for each named route e.g. window.root_path
|
30
|
+
for route_name, data of CoffeeRoutes.routes
|
31
|
+
do (route_name, data) ->
|
32
|
+
window["#{route_name}_path"] = (params)->
|
33
|
+
route = route_name += ""
|
34
|
+
CoffeeRoutes.path(route, params)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coffee_routes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Wentworth
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|