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 +4 -4
- data/.rspec +2 -1
- data/Gemfile +2 -0
- data/README.md +12 -4
- data/Rakefile +7 -5
- data/js-routes-rails.gemspec +1 -1
- data/lib/js-routes/rails/route_exporter.rb +12 -6
- data/lib/js-routes/rails/version.rb +1 -1
- data/lib/js-routes/rails.rb +10 -1
- data/templates/commonjs.js +21 -0
- data/{js-routes-rails-template.js → templates/rails.js} +0 -0
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ad1684a2960e73961358f4b93504130aacfd006
|
4
|
+
data.tar.gz: b4b2569de9f228017322dcb01297f071dec1e22c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91daa0ac41b1d6078829e800b66cc97b04cdcac97b0c2e17dd7717f22229f006cf00fca4b7cc669a7d84884ec534ec01b081385c8a66111dcd368cd2fb9874a2
|
7
|
+
data.tar.gz: 303bd320c571ca72068051812c823e1cc289d583194e09361c744021d2eb1076a290efd83f063c098bceff7e9cf371166962cc94a579de31b8fa7ea2ea834efe
|
data/.rspec
CHANGED
data/Gemfile
CHANGED
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/
|
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
|
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
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
data/js-routes-rails.gemspec
CHANGED
@@ -9,15 +9,13 @@ module Js
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def export!
|
12
|
-
File.open(
|
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(
|
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
|
data/lib/js-routes/rails.rb
CHANGED
@@ -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.
|
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:
|
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
|