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 CHANGED
@@ -1,30 +1,30 @@
1
1
  # cone
2
2
 
3
- Automatically generated javascript url helpers based on your Rails routes.
3
+ Automatically generated Javascript URL helpers based on your Rails routes.
4
4
 
5
- ## usage
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 javascript with cone:
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.userUrl({id: 12 });
13
+ cone.userPath({id: 12});
14
14
  "/users/12"
15
15
 
16
- cone.userUrl({id: 12, format: 'json' });
16
+ cone.userPath({id: 12, format: 'json'});
17
17
  "/users/12.json"
18
18
 
19
- cone.userUrl({id: 12, format: 'json', foo: 'bar baz'});
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 javascript regenerated.
23
+ Reload the server whenever your routes change to have the Javascript regenerated.
24
24
 
25
- ## installation
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
@@ -6,6 +6,7 @@ end
6
6
 
7
7
  task :build do
8
8
  system 'gem build cone.gemspec'
9
- `mkdir -p build`
9
+ `rm -rf build`
10
+ `mkdir build`
10
11
  `mv *.gem build`
11
12
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'cone'
3
- gem.version = '0.0.2'
3
+ gem.version = '0.0.3'
4
4
  gem.summary = "Rails client side url helpers"
5
5
  gem.author = 'Lihan Li'
6
6
  gem.email = 'frankieteardrop@gmail.com'
@@ -1,6 +1,6 @@
1
- processUrl = (url, params) ->
1
+ processPath = (path, params) ->
2
2
  params.format = if params.format then ".#{params.format}" else ''
3
- url = url.replace('(.:format)', params.format)
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 url.indexOf(keySymbol) == -1
11
+ if path.indexOf(keySymbol) == -1
12
12
  paramsArray.push("#{encodeURIComponent(k)}=#{encodeURIComponent(v)}")
13
13
  else
14
- url = url.replace(keySymbol, encodeURIComponent(v))
14
+ path = path.replace(keySymbol, encodeURIComponent(v))
15
15
 
16
- url += "?#{paramsArray.join('&')}" unless paramsArray.length == 0
17
- url
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
- <% route_name = route_name.camelize(:lower) %>
24
- cone.<%= route_name %>Path = cone.<%= route_name %>Url = (params = {}) ->
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}#{ opt[:alias] ? 'Url' : 'Path' }(#{ opt[:params] ? opt[:params].to_json : '' })")
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.2
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-11 00:00:00.000000000 Z
12
+ date: 2012-12-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: coffee-rails