js-routes-zigexn 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9e596334de0a0fd64c5d88a4bea56c1fab971a70
4
+ data.tar.gz: b38ea25faef8856509140dfb57480c09121e68ac
5
+ SHA512:
6
+ metadata.gz: fe1a1a7b65fa1d5bb0f256c7f36ebb4176cf569d58c8acc88f7ff0b9275e0722ec04b4b605a48e1cf5ccda4ce35f109069fd9fe3290026fb5b58b8dbbe1c85f3
7
+ data.tar.gz: 00def775ee6f0ccdac3d58136f7cf026482d83f70ede7be13fdaf9708bd52d8da48c5cf67b59591be5007d326bfde314df5f1431f44a648277c726c8a1f832b1
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.gitignore ADDED
@@ -0,0 +1,60 @@
1
+ # rcov generated
2
+ coverage
3
+
4
+ # rdoc generated
5
+ rdoc
6
+
7
+ # yard generated
8
+ doc
9
+ .yardoc
10
+ log
11
+
12
+ # bundler
13
+ .bundle
14
+
15
+ # jeweler generated
16
+ pkg
17
+
18
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
19
+ #
20
+ # * Create a file at ~/.gitignore
21
+ # * Include files you want ignored
22
+ # * Run: git config --global core.excludesfile ~/.gitignore
23
+ #
24
+ # After doing this, these files will be ignored in all your git projects,
25
+ # saving you from having to 'pollute' every project you touch with them
26
+ #
27
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
28
+ #
29
+ # For MacOS:
30
+ #
31
+ #.DS_Store
32
+
33
+ # For TextMate
34
+ #*.tmproj
35
+ #tmtags
36
+
37
+ # For emacs:
38
+ #*~
39
+ #\#*
40
+ #.\#*
41
+
42
+ # For vim:
43
+ #*.swp
44
+
45
+ # For redcar:
46
+ #.redcar
47
+
48
+ # For rubinius:
49
+ #*.rbc
50
+ .rvmrc
51
+ .ruby-version
52
+
53
+ Gemfile.lock
54
+ gemfiles/*.lock
55
+
56
+ .DS_Store
57
+
58
+ /spec/dummy/app/assets/javascripts/routes.js
59
+ /spec/dummy/logs
60
+ /spec/dummy/tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,60 @@
1
+ language: ruby
2
+ cache: bundler
3
+
4
+ before_install:
5
+ - gem install bundler # need for jruby and ruby-head
6
+
7
+ rvm:
8
+ - 2.0
9
+ - 2.1
10
+ - 2.2.5
11
+ - 2.3.1
12
+ - 2.4.1
13
+ - jruby-19mode
14
+ - ruby-head
15
+ - jruby-head
16
+
17
+ gemfile:
18
+ - gemfiles/rails32.gemfile
19
+ - gemfiles/rails40.gemfile
20
+ - gemfiles/rails40_sprockets3.gemfile
21
+ - gemfiles/rails41.gemfile
22
+ - gemfiles/rails41_sprockets3.gemfile
23
+ - gemfiles/rails42.gemfile
24
+ - gemfiles/rails42_sprockets3.gemfile
25
+ - gemfiles/rails50.gemfile
26
+ - gemfiles/rails50_sprockets3.gemfile
27
+
28
+ sudo: false
29
+
30
+ notifications:
31
+ email:
32
+ - agresso@gmail.com
33
+
34
+ branches:
35
+ only:
36
+ - master
37
+
38
+ matrix:
39
+ allow_failures:
40
+ - rvm: jruby-19mode
41
+ - rvm: ruby-head
42
+ - rvm: jruby-head
43
+ - gemfile: gemfiles/rails50.gemfile
44
+ exclude:
45
+ - rvm: 2.0
46
+ gemfile: gemfiles/rails50.gemfile
47
+ - rvm: 2.0
48
+ gemfile: gemfiles/rails50_sprockets3.gemfile
49
+ - rvm: 2.1
50
+ gemfile: gemfiles/rails50.gemfile
51
+ - rvm: 2.1
52
+ gemfile: gemfiles/rails50_sprockets3.gemfile
53
+ - rvm: 2.4.1
54
+ gemfile: gemfiles/rails40.gemfile # Segmentation fault (core dumped) for 2.4
55
+ - rvm: 2.4.1
56
+ gemfile: gemfiles/rails40_sprockets3.gemfile # Segmentation fault (core dumped) for 2.4
57
+ - rvm: 2.4.1
58
+ gemfile: gemfiles/rails41.gemfile # Segmentation fault (core dumped) for 2.4
59
+ - rvm: 2.4.1
60
+ gemfile: gemfiles/rails41_sprockets3.gemfile # Segmentation fault (core dumped) for 2.4
data/Appraisals ADDED
@@ -0,0 +1,16 @@
1
+ appraise "rails32" do
2
+ gem "railties", "~> 3.2.22.5"
3
+ gem 'tzinfo'
4
+ end
5
+
6
+ {rails40: '4.0.13', rails41: '4.1.16', rails42: '4.2.8', rails50: '5.0.2'}.each do |rails, version|
7
+ appraise "#{rails}" do
8
+ gem "railties", "~> #{version}"
9
+ gem "sprockets", "< 3"
10
+ end
11
+
12
+ appraise "#{rails}-sprockets3" do
13
+ gem "railties", "~> #{version}"
14
+ gem "sprockets", "~> 3.0"
15
+ end
16
+ end
data/CHANGELOG.md ADDED
@@ -0,0 +1,112 @@
1
+ ## master
2
+
3
+ ## v1.3.3
4
+
5
+ * Improved optional parameters support #216
6
+
7
+ ## v1.3.2
8
+
9
+ * Added `application` option #214
10
+
11
+ ## v1.3.1
12
+
13
+ * Raise error object with id null passed as route paramter #209
14
+ * Sprockets bugfixes #212
15
+
16
+ ## v1.3.0
17
+
18
+ * Introduce the special _options key. Fixes #86
19
+
20
+ ## v1.2.9
21
+
22
+ * Fixed deprecation varning on Sprockets 3.7
23
+
24
+ ## v1.2.8
25
+
26
+ * Bugfix warning on Sprockets 4.0 #202
27
+
28
+ ## v1.2.7
29
+
30
+ * Drop support 1.9.3
31
+ * Add helper for indexOf, if no native implementation in JS engine
32
+ * Add sprockets3 compatibility
33
+ * Bugfix domain defaults to path #197
34
+
35
+ ## v1.2.6
36
+
37
+ * Use default prefix from `Rails.application.config.relative_url_root` #186
38
+ * Bugfix route globbing with optional fragments bug #191
39
+
40
+ ## v1.2.5
41
+
42
+ * Bugfix subdomain default parameter in routes #184
43
+ * Bugfix infinite recursion in some specific route sets #183
44
+
45
+ ## v1.2.4
46
+
47
+ * Additional bugfixes to support all versions of Sprockets: 2.x and 3.x
48
+
49
+ ## v1.2.3
50
+
51
+ * Sprockets ~= 3.0 support
52
+
53
+ ## v1.2.2
54
+
55
+ * Sprockets ~= 3.0 support
56
+ * Support default parameters specified in route.rb file
57
+
58
+ ## v1.2.1
59
+
60
+ * Fixes for Rails 5
61
+
62
+ ## v1.2.0
63
+
64
+ * Support host, port and protocol inline parameters
65
+ * Support host, port and protocol parameters given to a route explicitly
66
+ * Remove all incompatibilities between actiondispatch and js-routes in handling route URLs
67
+
68
+ ## v1.1.2
69
+
70
+ * Bugfix support nested object null parameters #164
71
+ * Bugfix support for nested optional parameters #162 #163
72
+
73
+ ## v1.1.1
74
+
75
+ * Bugfix regression in serialisation on blank strings caused by [#155](https://github.com/railsware/js-routes/pull/155/files)
76
+
77
+ ## v1.1.0
78
+
79
+ * Ensure routes are loaded, prior to generating them [#148](https://github.com/railsware/js-routes/pull/148)
80
+ * Use `flat_map` rather than `map{...}.flatten` [#149](https://github.com/railsware/js-routes/pull/149)
81
+ * URL escape routes.rb url to fix bad URI(is not URI?) error [#150](https://github.com/railsware/js-routes/pull/150)
82
+ * Fix for rails 5 - test rails-edge on travis allowing failure [#151](https://github.com/railsware/js-routes/pull/151)
83
+ * Adds `serializer` option [#155](https://github.com/railsware/js-routes/pull/155/files)
84
+
85
+ ## v1.0.1
86
+
87
+ * Support sprockets-3
88
+ * Performance optimization of include/exclude options
89
+
90
+ ## v1.0.0
91
+
92
+ * Add the compact mode [#125](https://github.com/railsware/js-routes/pull/125)
93
+ * Add support for host, protocol, and port configuration [#137](https://github.com/railsware/js-routes/pull/137)
94
+ * Routes path specs [#135](https://github.com/railsware/js-routes/pull/135)
95
+ * Support Rails 4.2 and Ruby 2.2 [#140](https://github.com/railsware/js-routes/pull/140)
96
+
97
+ ## v0.9.9
98
+
99
+ * Bugfix Rails Engine subapplication route generation when they are nested [#120](https://github.com/railsware/js-routes/pull/120)
100
+
101
+ ## v0.9.8
102
+
103
+ * Support AMD/Require.js [#111](https://github.com/railsware/js-routes/pull/111)
104
+ * Support trailing slash [#106](https://github.com/railsware/js-routes/pull/106)
105
+
106
+ ## v0.9.7
107
+
108
+ * Depend on railties [#97](https://github.com/railsware/js-routes/pull/97)
109
+ * Fix typeof error for IE [#95](https://github.com/railsware/js-routes/pull/95)
110
+ * Fix testing on ruby-head [#92](https://github.com/railsware/js-routes/pull/92)
111
+ * Correct thread safety issue in js-routes generation [#90](https://github.com/railsware/js-routes/pull/90)
112
+ * Use the `of` operator to detect for `to_param` and `id` in objects [#87](https://github.com/railsware/js-routes/pull/87)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in js-routes.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Bogdan Gusiev
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+ require 'rubygems'
3
+ require 'bundler'
4
+ begin
5
+ Bundler.setup(:default, :development)
6
+ rescue Bundler::BundlerError => e
7
+ $stderr.puts e.message
8
+ $stderr.puts "Run `bundle install` to install missing gems"
9
+ exit e.status_code
10
+ end
11
+ require 'bundler/gem_tasks'
12
+ require 'rspec/core'
13
+ require 'rspec/core/rake_task'
14
+ require 'appraisal'
15
+ load "rails/tasks/routes.rake"
16
+
17
+ RSpec::Core::RakeTask.new(:spec)
18
+
19
+ task :test_all => :appraisal # test all rails
20
+
21
+ task :default => :spec
22
+
23
+
24
+ namespace :spec do
25
+ task :routes do
26
+ require './spec/spec_helper'
27
+ require 'action_dispatch/routing/inspector'
28
+ draw_routes
29
+ all_routes = Rails.application.routes.routes
30
+ inspector = ActionDispatch::Routing::RoutesInspector.new(all_routes)
31
+ puts inspector.format(ActionDispatch::Routing::ConsoleFormatter.new, ENV['CONTROLLER'])
32
+ end
33
+ end
data/Readme.md ADDED
@@ -0,0 +1,234 @@
1
+ # JsRoutes
2
+ [![Build Status](https://travis-ci.org/railsware/js-routes.svg?branch=master)](https://travis-ci.org/railsware/js-routes)
3
+
4
+ Generates javascript file that defines all Rails named routes as javascript helpers
5
+
6
+ ## Intallation
7
+
8
+ Your Rails Gemfile:
9
+
10
+ ``` ruby
11
+ gem "js-routes"
12
+ ```
13
+
14
+ ### Basic Setup
15
+
16
+ Require js routes file in `application.js` or other bundle
17
+
18
+ ``` js
19
+ //= require js-routes
20
+ ```
21
+
22
+ Also in order to flush asset pipeline cache sometimes you might need to run:
23
+
24
+ ``` sh
25
+ rake tmp:cache:clear
26
+ ```
27
+
28
+ This cache is not flushed on server restart in development environment.
29
+
30
+ **Important:** If routes.js file is not updated after some configuration change you need to run this rake task again.
31
+
32
+ ### Advanced Setup
33
+
34
+ If you need to customize routes file create initializer, like `config/initializers/jsroutes.rb`:
35
+
36
+ ``` ruby
37
+ JsRoutes.setup do |config|
38
+ config.option = value
39
+ end
40
+ ```
41
+
42
+ Available options:
43
+
44
+ * `default_url_options` - default parameters used when generating URLs
45
+ * Note that only specific options are supported at this time.
46
+ * Example: {:format => "json", :trailing\_slash => true, :protocol => "https", :host => "example.com", :port => 3000}
47
+ * Default: {}
48
+ * `exclude` - Array of regexps to exclude from js routes.
49
+ * Default: []
50
+ * The regexp applies only to the name before the `_path` suffix, eg: you want to match exactly `settings_path`, the regexp should be `/^settings$/`
51
+ * `include` - Array of regexps to include in js routes.
52
+ * Default: []
53
+ * The regexp applies only to the name before the `_path` suffix, eg: you want to match exactly `settings_path`, the regexp should be `/^settings$/`
54
+ * `namespace` - global object used to access routes.
55
+ * Supports nested namespace like `MyProject.routes`
56
+ * Default: `Routes`
57
+ * `prefix` - String representing a url path to prepend to all paths.
58
+ * Example: `http://yourdomain.com`. This will cause route helpers to generate full path only.
59
+ * Default: `Rails.application.config.relative_url_root`
60
+ * `camel_case` (version >= 0.8.8) - Generate camel case route names.
61
+ * Default: false
62
+ * `url_links` (version >= 0.8.9) - Generate `*_url` helpers (in addition to the default `*_path` helpers).
63
+ * Example: true
64
+ * Default: false
65
+ * Note: generated URLs will first use the protocol, host, and port options specified in the route definition. Otherwise, the URL will be based on the option specified in the `default_url_options` config. If no default option has been set, then the URL will fallback to the current URL based on `window.location`.
66
+ * `compact` (version > 0.9.9) - Remove `_path` suffix in path routes(`*_url` routes stay untouched if they were enabled)
67
+ * Default: false
68
+ * Sample route call when option is set to true: Routes.users() => `/users`
69
+ * `serializer` (version >= 1.1.0) - Puts a JS function here that serializes a Javascript Hash object into URL paramters: `{a: 1, b: 2} => "a=1&b=2"`.
70
+ * Default: `nil`. Uses built-in serializer
71
+ * Example: `jQuery.param` - use jQuery's serializer algorithm. You can attach serialize function from your favorite AJAX framework.
72
+ * Example: `MyApp.custom_serialize` - use completely custom serializer of your application.
73
+
74
+ * `special_options_key` - a special key that helps js-routes to destinguish serialized model from options hash
75
+ * This option is required because JS doesn't provide a difference between an object and a hash
76
+ * Default: `_options`
77
+ * `application` - a key to specify which rails engine you want to generate routes too.
78
+ * This option allows to only generate routes for a specific rails engine, that is mounted into routes instead of all Rails app routes
79
+ * Default: `Rails.application`
80
+
81
+ ### Very Advanced Setup
82
+
83
+ In case you need multiple route files for different parts of your application, you have to create the files manually.
84
+ If your application has an `admin` and an `application` namespace for example:
85
+
86
+ ```
87
+ # app/assets/javascripts/admin/routes.js.erb
88
+ <%= JsRoutes.generate(namespace: "AdminRoutes", include: /admin/) %>
89
+
90
+ # app/assets/javascripts/admin.js.coffee
91
+ #= require admin/routes
92
+ ```
93
+
94
+ ```
95
+ # app/assets/javascripts/application/routes.js.erb
96
+ <%= JsRoutes.generate(namespace: "AppRoutes", exclude: /admin/) %>
97
+
98
+ # app/assets/javascripts/application.js.coffee
99
+ #= require application/routes
100
+ ```
101
+
102
+ In order to generate the routes JS code to a string:
103
+
104
+ ```ruby
105
+ routes_js = JsRoutes.generate(options)
106
+ ```
107
+
108
+ If you want to generate the routes files outside of the asset pipeline, you can use `JsRoutes.generate!`:
109
+
110
+ ``` ruby
111
+ path = "app/assets/javascripts"
112
+ JsRoutes.generate!("#{path}/app_routes.js", :namespace => "AppRoutes", :exclude => [/^admin_/, /^api_/])
113
+ JsRoutes.generate!("#{path}/adm_routes.js", :namespace => "AdmRoutes", :include => /^admin_/)
114
+ JsRoutes.generate!("#{path}/api_routes.js", :namespace => "ApiRoutes", :include => /^api_/, :default_url_options => {:format => "json"})
115
+ ```
116
+
117
+ ### Rails relative URL root
118
+
119
+ If you've installed your application in a sub-path or sub-URI of your server instead of at the root, you need to set the `RAILS_RELATIVE_URL_ROOT` environment variable to the correct path prefix for your application when you precompile assets. Eg., if your application's base URL is "https://appl.example.com/Application1", the command to precompile assets would be:
120
+ ```
121
+ RAILS_RELATIVE_URL_ROOT=/Application1 RAILS_ENV=production bundle exec rake assets:precompile
122
+ ```
123
+ The environment variable is only needed for precompilation of assets, at any other time (eg. when assets are compiled on-the-fly as in the development environment) Rails will set the relative URL root correctly on it's own.
124
+
125
+
126
+ ## Usage
127
+
128
+ Configuration above will create a nice javascript file with `Routes` object that has all the rails routes available:
129
+
130
+ ``` js
131
+ Routes.users_path() // => "/users"
132
+ Routes.user_path(1) // => "/users/1"
133
+ Routes.user_path(1, {format: 'json'}) // => "/users/1.json"
134
+ Routes.user_path(1, {anchor: 'profile'}) // => "/users/1#profile"
135
+ Routes.new_user_project_path(1, {format: 'json'}) // => "/users/1/projects/new.json"
136
+ Routes.user_project_path(1,2, {q: 'hello', custom: true}) // => "/users/1/projects/2?q=hello&custom=true"
137
+ Routes.user_project_path(1,2, {hello: ['world', 'mars']}) // => "/users/1/projects/2?hello%5B%5D=world&hello%5B%5D=mars"
138
+ ```
139
+
140
+ Using serialized object as route function arguments:
141
+
142
+ ``` js
143
+ var google = {id: 1, name: "Google"};
144
+ Routes.company_path(google) // => "/companies/1"
145
+ var google = {id: 1, name: "Google", to_param: "google"};
146
+ Routes.company_path(google) // => "/companies/google"
147
+ ```
148
+
149
+ In order to make routes helpers available globally:
150
+
151
+ ``` js
152
+ jQuery.extend(window, Routes)
153
+ ```
154
+
155
+ ## Get spec of routes and required params
156
+
157
+ Possible to get `spec` of route by function `toString`:
158
+
159
+ ```js
160
+ Routes.users_path.toString() // => "/users(.:format)"
161
+ Routes.user_path.toString() // => "/users/:id(.:format)"
162
+ ```
163
+
164
+ This function allow to get the same `spec` for route, if you will get string representation of the route function:
165
+
166
+ ```js
167
+ '' + Routes.users_path // => "/users(.:format)", a string representation of the object
168
+ '' + Routes.user_path // => "/users/:id(.:format)"
169
+ ```
170
+
171
+ Route function also contain inside attribute `required_params` required param names as array:
172
+
173
+ ```js
174
+ Routes.users_path.required_params // => []
175
+ Routes.user_path.required_params // => ['id']
176
+ ```
177
+
178
+
179
+ ## Rails Compatibilities
180
+
181
+ JsRoutes ties to be as close as possible to rails behaviour in all aspects of routing API.
182
+ Please make and issue in case of any incomtibilities found outside of described below.
183
+
184
+ ### Object and Hash distinction issue
185
+
186
+ Sometimes the destinction between JS Hash and Object can not be found by js-routes.
187
+ In this case you would need to pass a special key to help:
188
+
189
+ ``` js
190
+ Routes.company_project_path({company_id: 1, id: 2}) // => Not Enough parameters
191
+ Routes.company_project_path({company_id: 1, id: 2, _options: true}) // => "/companies/1/projects/2"
192
+ ```
193
+
194
+
195
+ ## What about security?
196
+
197
+ js-routes itself do not have security holes. It makes URLs
198
+ without access protection more reachable by potential attacker.
199
+ In order to prevent this use `:exclude` option for sensitive urls like `/admin_/`
200
+
201
+ ## Spork
202
+
203
+ When using Spork and `Spork.trap_method(Rails::Application::RoutesReloader, :reload!)` you should also do:
204
+
205
+ ``` ruby
206
+ Spork.trap_method(JsRoutes, :generate!)
207
+ ```
208
+
209
+ ## JS-Routes and heroku
210
+
211
+ Heroku environment has a specific problems with setup. It is impossible to use asset pipeline in this environment. You should use "Very Advanced Setup" schema in this case.
212
+
213
+ For example create routes.js.erb in assets folder with needed content:
214
+
215
+ ``` erb
216
+ <%= JsRoutes.generate(options) %>
217
+ ```
218
+
219
+ This should just work.
220
+
221
+ ## Advantages over alternatives
222
+
223
+ There are some alternatives available. Most of them has only basic feature and don't reach the level of quality I accept.
224
+ Advantages of this one are:
225
+
226
+ * Rails 3-5 support
227
+ * Rich options set
228
+ * Full rails compatibility
229
+ * Support Rails `#to_param` convention for seo optimized paths
230
+ * Well tested
231
+
232
+ #### Thanks to [Contributors](https://github.com/railsware/js-routes/contributors)
233
+
234
+ #### Have fun