js-routes 1.2.7 → 1.2.8

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: 673824b92c317dcd831dba31a576e63c057569fc
4
- data.tar.gz: 3bde0b614cb515193e7b2166adeb6be99e8d0bf8
3
+ metadata.gz: fd742d686437361f2d20fe7644ec39eeca842321
4
+ data.tar.gz: 625e04e1a36df51e96b8f9afe10dbe72390071a0
5
5
  SHA512:
6
- metadata.gz: 999966b93d59c45104dfd2a24d9ebd7d891df7924430cb7fb2d4a1438e84e229a901043cf4b27ab1da279f74ae33a2c09b1b6c68005a72d33be76ac8430ea9b0
7
- data.tar.gz: a2ece0a5892d4762c26a5a74f130806c90d82a1c04ec2f528b42f2e3f15172033fa1073b99852bb9b897e21af4d3964e76133128448e23f84372121b6b5801d2
6
+ metadata.gz: 356d2bf3c489cff5c3de2ef37ecd41e6c5f0ebd5e08bb5ab3b1e9c415440de07ac101a1e20d15253c61b1692df18c3b9df14357754204427651ff1f65b60c5f5
7
+ data.tar.gz: 5138a17eced6dbf6f0f6e634e78a6eb5f4377bd10f0ce15109f3d2230686ba8e46c8a9567bb534fe8a11e1b317fcaabc54b81aa76242ba2c1a6846f7698855e0
@@ -1,5 +1,9 @@
1
1
  ## master
2
2
 
3
+ ## v1.2.8
4
+
5
+ * Bugfix warning on Sprockets 4.0 #202
6
+
3
7
  ## v1.2.7
4
8
 
5
9
  * Drop support 1.9.3
data/Rakefile CHANGED
@@ -12,9 +12,22 @@ require 'bundler/gem_tasks'
12
12
  require 'rspec/core'
13
13
  require 'rspec/core/rake_task'
14
14
  require 'appraisal'
15
+ load "rails/tasks/routes.rake"
15
16
 
16
17
  RSpec::Core::RakeTask.new(:spec)
17
18
 
18
19
  task :test_all => :appraisal # test all rails
19
20
 
20
- task :default => :spec
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 CHANGED
@@ -16,9 +16,7 @@ gem "js-routes"
16
16
  Require js routes file in `application.js` or other bundle
17
17
 
18
18
  ``` js
19
- /*
20
- = require js-routes
21
- */
19
+ //= require js-routes
22
20
  ```
23
21
 
24
22
  Also in order to flush asset pipeline cache sometimes you might need to run:
@@ -1,30 +1,69 @@
1
- require 'sprockets/version'
1
+ class JsRoutesSprocketsExtension
2
+ def initialize(filename, &block)
3
+ @filename = filename
4
+ @source = block.call
5
+ end
2
6
 
3
- class JsRoutes
4
- SPROCKETS3 = Gem::Version.new(Sprockets::VERSION) >= Gem::Version.new('3.0.0')
5
- class Engine < ::Rails::Engine
7
+ def render(context, empty_hash_wtf)
8
+ self.class.run(@filename, @source, context)
9
+ end
6
10
 
7
- if SPROCKETS3
8
- initializer 'js-routes.dependent_on_routes', after: :engines_blank_point, before: :finisher_hook do
9
- Rails.application.config.assets.configure do |config|
11
+ def self.run(filename, source, context)
12
+ if context.logical_path == 'js-routes'
13
+ routes = Rails.root.join('config', 'routes.rb').to_s
14
+ context.depend_on(routes)
15
+ end
16
+ source
17
+ end
18
+
19
+ def self.call(input)
20
+ filename = input[:filename]
21
+ source = input[:data]
22
+ context = input[:environment].context_class.new(input)
23
+
24
+ result = run(filename, source, context)
25
+ context.metadata.merge(data: result)
26
+ end
27
+ end
28
+
29
+
30
+ class Engine < ::Rails::Engine
31
+ require 'sprockets/version'
32
+ v2 = Gem::Dependency.new('', ' ~> 2')
33
+ v3 = Gem::Dependency.new('', ' ~> 3')
34
+ v4 = Gem::Dependency.new('', ' >= 4')
35
+ sprockets_version = Gem::Version.new(Sprockets::VERSION).release
36
+ initializer_args = case sprockets_version
37
+ when -> (v) { v2.match?('', v) }
38
+ { after: "sprockets.environment" }
39
+ when -> (v) { v3.match?('', v) || v4.match?('', v) }
40
+ { after: :engines_blank_point, before: :finisher_hook }
41
+ else
42
+ raise StandardError, "Sprockets version #{sprockets_version} is not supported"
43
+ end
44
+
45
+ initializer 'js-routes.dependent_on_routes', initializer_args do
46
+ case sprockets_version
47
+ when -> (v) { v2.match?('', v) }
48
+ if Rails.application.assets.respond_to?(:register_preprocessor)
10
49
  routes = Rails.root.join('config', 'routes.rb').to_s
11
- config.register_preprocessor 'application/javascript', :'js-routes_dependent_on_routes' do |ctx,data|
50
+ Rails.application.assets.register_preprocessor 'application/javascript', :'js-routes_dependent_on_routes' do |ctx, data|
12
51
  ctx.depend_on(routes) if ctx.logical_path == 'js-routes'
13
52
  data
14
53
  end
15
54
  end
16
- end
17
- else
18
- initializer 'js-routes.dependent_on_routes', after: "sprockets.environment" do
19
-
20
- if Rails.application.assets.respond_to?(:register_preprocessor)
55
+ when -> (v) { v3.match?('', v) }
56
+ Rails.application.config.assets.configure do |config|
21
57
  routes = Rails.root.join('config', 'routes.rb').to_s
22
- Rails.application.assets.register_preprocessor 'application/javascript', :'js-routes_dependent_on_routes' do |ctx,data|
58
+ config.register_preprocessor 'application/javascript', :'js-routes_dependent_on_routes' do |ctx, data|
23
59
  ctx.depend_on(routes) if ctx.logical_path == 'js-routes'
24
60
  data
25
61
  end
26
62
  end
27
- end
63
+ when -> (v) { v4.match?('', v) }
64
+ Sprockets.register_preprocessor 'application/javascript', JsRoutesSprocketsExtension
65
+ else
66
+ raise StandardError, "Sprockets version #{sprockets_version} is not supported"
28
67
  end
29
68
  end
30
- end
69
+ end
@@ -1,3 +1,3 @@
1
1
  class JsRoutes
2
- VERSION = "1.2.7"
2
+ VERSION = "1.2.8"
3
3
  end
@@ -70,77 +70,6 @@ class App < Rails::Application
70
70
  config.root = File.expand_path('../dummy', __FILE__)
71
71
  end
72
72
 
73
- def draw_routes
74
-
75
- BlogEngine::Engine.routes.draw do
76
- root to: "application#index"
77
- resources :posts
78
- end
79
- App.routes.draw do
80
-
81
- get 'support(/page/:page)', to: BlogEngine::Engine, as: 'support'
82
-
83
- resources :inboxes do
84
- resources :messages do
85
- resources :attachments
86
- end
87
- end
88
-
89
- root :to => "inboxes#index"
90
-
91
- namespace :admin do
92
- resources :users
93
- end
94
-
95
- scope "/returns/:return" do
96
- resources :objects
97
- end
98
- resources :returns
99
-
100
- scope "(/optional/:optional_id)" do
101
- resources :things
102
- end
103
-
104
- get "/:controller(/:action(/:id))" => "classic#classic", :as => :classic
105
-
106
- get "/other_optional/(:optional_id)" => "foo#foo", :as => :foo
107
- get '/other_optional(/*optional_id)' => 'foo#foo', :as => :foo_all
108
-
109
- get 'books/*section/:title' => 'books#show', :as => :book
110
- get 'books/:title/*section' => 'books#show', :as => :book_title
111
-
112
- mount BlogEngine::Engine => "/blog", :as => :blog_app
113
-
114
- get '/no_format' => "foo#foo", :format => false, :as => :no_format
115
-
116
- get '/json_only' => "foo#foo", :format => true, :constraints => {:format => /json/}, :as => :json_only
117
-
118
- get '/привет' => "foo#foo", :as => :hello
119
- get '(/o/:organization)/search/:q' => "foo#foo", as: :search
120
-
121
- resources :sessions, :only => [:new, :create, :destroy], :protocol => 'https'
122
-
123
- get '/' => 'sso#login', host: 'sso.example.com', as: :sso
124
-
125
- resources :portals, :port => 8080
126
-
127
- get '/with_defaults' => 'foo#foo', defaults: { bar: 'tested', format: :json }, format: :true
128
-
129
- namespace :api, format: true, defaults: {format: 'json'} do
130
- get "/purchases" => "purchases#index"
131
- end
132
-
133
- resources :budgies do
134
- get "descendents"
135
- end
136
-
137
- namespace :backend, path: '', constraints: {subdomain: 'backend'} do
138
- root to: 'backend#index'
139
- end
140
-
141
- end
142
-
143
- end
144
73
 
145
74
  # prevent warning
146
75
  Rails.configuration.active_support.deprecation = :log
@@ -0,0 +1,71 @@
1
+ def draw_routes
2
+
3
+ BlogEngine::Engine.routes.draw do
4
+ root to: "application#index"
5
+ resources :posts
6
+ end
7
+ App.routes.draw do
8
+
9
+ get 'support(/page/:page)', to: BlogEngine::Engine, as: 'support'
10
+
11
+ resources :inboxes do
12
+ resources :messages do
13
+ resources :attachments
14
+ end
15
+ end
16
+
17
+ root :to => "inboxes#index"
18
+
19
+ namespace :admin do
20
+ resources :users
21
+ end
22
+
23
+ scope "/returns/:return" do
24
+ resources :objects
25
+ end
26
+ resources :returns
27
+
28
+ scope "(/optional/:optional_id)" do
29
+ resources :things
30
+ end
31
+
32
+ get "/:controller(/:action(/:id))" => "classic#classic", :as => :classic
33
+
34
+ get "/other_optional/(:optional_id)" => "foo#foo", :as => :foo
35
+ get '/other_optional(/*optional_id)' => 'foo#foo', :as => :foo_all
36
+
37
+ get 'books/*section/:title' => 'books#show', :as => :book
38
+ get 'books/:title/*section' => 'books#show', :as => :book_title
39
+
40
+ mount BlogEngine::Engine => "/blog", :as => :blog_app
41
+
42
+ get '/no_format' => "foo#foo", :format => false, :as => :no_format
43
+
44
+ get '/json_only' => "foo#foo", :format => true, :constraints => {:format => /json/}, :as => :json_only
45
+
46
+ get '/привет' => "foo#foo", :as => :hello
47
+ get '(/o/:organization)/search/:q' => "foo#foo", as: :search
48
+
49
+ resources :sessions, :only => [:new, :create, :destroy], :protocol => 'https'
50
+
51
+ get '/' => 'sso#login', host: 'sso.example.com', as: :sso
52
+
53
+ resources :portals, :port => 8080
54
+
55
+ get '/with_defaults' => 'foo#foo', defaults: { bar: 'tested', format: :json }, format: :true
56
+
57
+ namespace :api, format: true, defaults: {format: 'json'} do
58
+ get "/purchases" => "purchases#index"
59
+ end
60
+
61
+ resources :budgies do
62
+ get "descendents"
63
+ end
64
+
65
+ namespace :backend, path: '', constraints: {subdomain: 'backend'} do
66
+ root to: 'backend#index'
67
+ end
68
+
69
+ end
70
+
71
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: js-routes
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.7
4
+ version: 1.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bogdan Gusiev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-14 00:00:00.000000000 Z
11
+ date: 2016-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -167,6 +167,7 @@ files:
167
167
  - spec/js_routes/rails_routes_compatibility_spec.rb
168
168
  - spec/js_routes/zzz_last_post_rails_init_spec.rb
169
169
  - spec/spec_helper.rb
170
+ - spec/support/routes.rb
170
171
  homepage: http://github.com/railsware/js-routes
171
172
  licenses:
172
173
  - MIT