js-routes-rails 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d2e41da3f7d5988bb153308e80144c92278820f7
4
- data.tar.gz: 354ef08359fa825406e15dc906855c4ddbf2c82f
3
+ metadata.gz: 5ad1684a2960e73961358f4b93504130aacfd006
4
+ data.tar.gz: b4b2569de9f228017322dcb01297f071dec1e22c
5
5
  SHA512:
6
- metadata.gz: 3d38649bd0817b0c77c50d4d85a53084485a7fedc24be3cede82c1230a16e5c115e08de5772de4b7e5cf7236460460579a3aaec25a4e08ca7cf12817e584e18f
7
- data.tar.gz: 390599f022123fea8bdf8dc5072f75ea0dabcb8ec14ecc0d09b566b89b44ccbb08f3b358fb86ff429adf4c8da7ca3ca4860f52deb2fe426b9d4f77a10852af63
6
+ metadata.gz: 91daa0ac41b1d6078829e800b66cc97b04cdcac97b0c2e17dd7717f22229f006cf00fca4b7cc669a7d84884ec534ec01b081385c8a66111dcd368cd2fb9874a2
7
+ data.tar.gz: 303bd320c571ca72068051812c823e1cc289d583194e09361c744021d2eb1076a290efd83f063c098bceff7e9cf371166962cc94a579de31b8fa7ea2ea834efe
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
- --format documentation
2
1
  --color
2
+ --format progress
3
+ --require spec_helper
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in js-routes-rails.gemspec
4
4
  gemspec
5
+
6
+ gem 'pry'
data/README.md CHANGED
@@ -37,11 +37,10 @@ And then execute:
37
37
 
38
38
  $ bundle exec rake js_routes_rails:export
39
39
 
40
- This will generate a JavaScript file in `app/assets/javascript/js-routes-rails.js`, which you can consume using the Asset Pipeline, for example:
41
-
40
+ This will generate a JavaScript file in `app/assets/javascripts/js-routes-rails.js`, which you can consume using the Asset Pipeline, for example:
42
41
 
43
42
  ```ruby
44
- javascript_include_tag 'js-routes-rails'
43
+ <%= javascript_include_tag 'js-routes-rails' %>
45
44
  ```
46
45
 
47
46
  or in `application.js`
@@ -50,9 +49,18 @@ or in `application.js`
50
49
  //= 'js-routes-rails'
51
50
  ```
52
51
 
52
+ You can also configure the location and format of the generated JavaScript file in your `application.rb`
53
+
54
+ ```ruby
55
+ Js::Routes::Rails.configure do |c|
56
+ c.output = '/some/other/place.js'
57
+ c.template = 'commonjs'
58
+ end
59
+ ```
60
+
53
61
  ## Usage
54
62
 
55
- Once you've brought the exported file in to your project your now able to use the `JsRoutesRails` object which gives you access to all of your Rails URL helpers on the client.
63
+ Once the generated file is in your project you're able to access the `JsRoutesRails` object which contains all the exported Rails URL helpers on the client.
56
64
 
57
65
  ```javascript
58
66
  JsRoutesRails.new_articles_path() // '/articles/new'
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
- # require "rspec/core/rake_task"
3
- #
4
- # RSpec::Core::RakeTask.new(:spec)
5
- #
6
- # task :default => :spec
2
+ require "rspec/core/rake_task"
3
+
4
+ task :default => :spec
5
+ desc "Run the specs."
6
+ RSpec::Core::RakeTask.new do |t|
7
+ t.pattern = "spec/**/*_spec.rb"
8
+ end
@@ -31,5 +31,5 @@ Gem::Specification.new do |spec|
31
31
 
32
32
  spec.add_development_dependency "bundler", "~> 1.12"
33
33
  spec.add_development_dependency "rake", "~> 10.0"
34
- # spec.add_development_dependency "rspec", "~> 3.0"
34
+ spec.add_development_dependency "rspec-rails"
35
35
  end
@@ -9,15 +9,13 @@ module Js
9
9
  end
10
10
 
11
11
  def export!
12
- File.open(output_path, 'w') { |f| f.write(compiled) }
12
+ File.open(configuration.output, 'w') do |f|
13
+ f.write(compiled)
14
+ end
13
15
  end
14
16
 
15
17
  private
16
18
 
17
- def output_path
18
- ::Rails.root.join('app', 'assets', 'javascripts', 'js-routes-rails.js')
19
- end
20
-
21
19
  def compiled
22
20
  b = binding
23
21
  b.local_variable_set(:routes, routes)
@@ -29,7 +27,15 @@ module Js
29
27
  end
30
28
 
31
29
  def template_path
32
- File.join(Js::Routes.root, 'js-routes-rails-template.js')
30
+ File.join(template_root, "#{configuration.template}.js")
31
+ end
32
+
33
+ def template_root
34
+ File.join(Js::Routes.root, 'templates')
35
+ end
36
+
37
+ def configuration
38
+ @configuration ||= Js::Routes::Rails.configuration
33
39
  end
34
40
  end
35
41
  end
@@ -1,7 +1,7 @@
1
1
  module Js
2
2
  module Routes
3
3
  module Rails
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
6
6
  end
7
7
  end
@@ -9,7 +9,7 @@ module Js
9
9
  end
10
10
 
11
11
  def self.configuration
12
- @configuration ||= OpenStruct.new
12
+ @configuration ||= OpenStruct.new(default_configuration_options)
13
13
  end
14
14
 
15
15
  def self.export!(routes = nil)
@@ -21,6 +21,15 @@ module Js
21
21
  def self.configure
22
22
  yield configuration
23
23
  end
24
+
25
+ private
26
+
27
+ def self.default_configuration_options
28
+ {
29
+ output: ::Rails.root.join('app', 'assets', 'javascripts', 'js-routes-rails.js').to_s,
30
+ template: 'rails'
31
+ }
32
+ end
24
33
  end
25
34
  end
26
35
  end
@@ -0,0 +1,21 @@
1
+ const JsRoutesRails = (function() {
2
+ var routes = {};
3
+ <% @routes.each do |helper, path| %>
4
+ routes['<%= helper %>'] = function(options) {
5
+ return format('<%= path %>', options);
6
+ };
7
+ <% end %>
8
+
9
+ function format(string, options) {
10
+ var str = string.toString();
11
+ for (option in options) {
12
+ str = str.replace(RegExp("\\:" + option, "gi"), options[option]);
13
+ }
14
+
15
+ return str;
16
+ };
17
+
18
+ return routes;
19
+ })();
20
+
21
+ export { JsRoutesRails };
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: js-routes-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damian Nicholson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-21 00:00:00.000000000 Z
11
+ date: 2017-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description: Generates a JavaScript file containing specific url_helpers defined in
56
70
  config/routes.rb
57
71
  email:
@@ -67,7 +81,6 @@ files:
67
81
  - LICENSE
68
82
  - README.md
69
83
  - Rakefile
70
- - js-routes-rails-template.js
71
84
  - js-routes-rails.gemspec
72
85
  - lib/js-routes-rails.rb
73
86
  - lib/js-routes/rails.rb
@@ -76,6 +89,8 @@ files:
76
89
  - lib/js-routes/rails/route_finder.rb
77
90
  - lib/js-routes/rails/version.rb
78
91
  - lib/js-routes/tasks/js-routes-rails.rake
92
+ - templates/commonjs.js
93
+ - templates/rails.js
79
94
  homepage: https://github.com/damian/js-routes-rails
80
95
  licenses:
81
96
  - MIT