cone 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +9 -9
- data/Rakefile +2 -1
- data/cone.gemspec +1 -1
- data/lib/assets/javascripts/cone.coffee.erb +9 -11
- data/test/test/integration/cone_gem_test.rb +1 -5
- metadata +2 -2
data/README.md
CHANGED
@@ -1,30 +1,30 @@
|
|
1
1
|
# cone
|
2
2
|
|
3
|
-
Automatically generated
|
3
|
+
Automatically generated Javascript URL helpers based on your Rails routes.
|
4
4
|
|
5
|
-
##
|
5
|
+
## Usage
|
6
6
|
|
7
7
|
```
|
8
8
|
user GET /users/:id(.:format) users#show
|
9
9
|
```
|
10
|
-
Let's say you have this Rails route. Here's how you would access it in
|
10
|
+
Let's say you have this Rails route. Here's how you would access it in Javascript with cone:
|
11
11
|
|
12
12
|
```javascript
|
13
|
-
cone.
|
13
|
+
cone.userPath({id: 12});
|
14
14
|
"/users/12"
|
15
15
|
|
16
|
-
cone.
|
16
|
+
cone.userPath({id: 12, format: 'json'});
|
17
17
|
"/users/12.json"
|
18
18
|
|
19
|
-
cone.
|
19
|
+
cone.userPath({id: 12, format: 'json', foo: 'bar baz'});
|
20
20
|
"/users/12.json?foo=bar%20baz"
|
21
21
|
```
|
22
22
|
|
23
|
-
Reload the server whenever your routes change to have the
|
23
|
+
Reload the server whenever your routes change to have the Javascript regenerated.
|
24
24
|
|
25
|
-
##
|
25
|
+
## Installation
|
26
26
|
|
27
27
|
1. Add gem 'cone' to your Gemfile.
|
28
28
|
2. Run bundle install.
|
29
29
|
3. Add //= require cone to your Javascript manifest file (usually found at app/assets/javascripts/application.js).
|
30
|
-
4. Restart your server
|
30
|
+
4. Restart your server.
|
data/Rakefile
CHANGED
data/cone.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
|
1
|
+
processPath = (path, params) ->
|
2
2
|
params.format = if params.format then ".#{params.format}" else ''
|
3
|
-
|
3
|
+
path = path.replace('(.:format)', params.format)
|
4
4
|
delete(params.format)
|
5
5
|
|
6
6
|
paramsArray = []
|
@@ -8,20 +8,18 @@ processUrl = (url, params) ->
|
|
8
8
|
for k, v of params
|
9
9
|
keySymbol = ":#{k}"
|
10
10
|
|
11
|
-
if
|
11
|
+
if path.indexOf(keySymbol) == -1
|
12
12
|
paramsArray.push("#{encodeURIComponent(k)}=#{encodeURIComponent(v)}")
|
13
13
|
else
|
14
|
-
|
14
|
+
path = path.replace(keySymbol, encodeURIComponent(v))
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
@cone = {}
|
16
|
+
path += "?#{paramsArray.join('&')}" unless paramsArray.length == 0
|
17
|
+
path
|
20
18
|
|
19
|
+
@cone =
|
21
20
|
<% Rails.application.routes.routes.named_routes.each do |route_name, route_val| %>
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
processUrl(<%= route_val.path.spec.to_s.to_json %>, params)
|
22
|
+
<%= route_name.camelize(:lower) %>Path: (params = {}) ->
|
23
|
+
processPath(<%= route_val.path.spec.to_s.to_json %>, params)
|
26
24
|
|
27
25
|
<% end %>
|
@@ -4,7 +4,7 @@ class ConeGemTest < ActionDispatch::IntegrationTest
|
|
4
4
|
|
5
5
|
def get_cone_url(name, opt = {})
|
6
6
|
# alias, params
|
7
|
-
get_js("cone.#{name}
|
7
|
+
get_js("cone.#{name}Path(#{ opt[:params] ? opt[:params].to_json : '' })")
|
8
8
|
end
|
9
9
|
|
10
10
|
test 'url without params' do
|
@@ -22,8 +22,4 @@ class ConeGemTest < ActionDispatch::IntegrationTest
|
|
22
22
|
assert_equal '/users/12/posts?foo=bar%20baz', get_cone_url('userPosts', params: {user_id: '12', foo: 'bar baz'})
|
23
23
|
end
|
24
24
|
|
25
|
-
test 'url helper alias' do
|
26
|
-
assert_equal '/users/12/posts', get_cone_url('userPosts', params: {user_id: '12'}, alias: true)
|
27
|
-
end
|
28
|
-
|
29
25
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: coffee-rails
|