js-routes 1.4.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.eslintrc.js +15 -0
- data/.gitignore +5 -0
- data/.nvmrc +1 -0
- data/.travis.yml +37 -30
- data/Appraisals +16 -13
- data/CHANGELOG.md +95 -0
- data/Rakefile +6 -2
- data/Readme.md +220 -88
- data/VERSION_2_UPGRADE.md +66 -0
- data/app/assets/javascripts/js-routes.js.erb +1 -1
- data/gemfiles/{rails40.gemfile → rails40_sprockets_2.gemfile} +1 -1
- data/gemfiles/{rails40_sprockets3.gemfile → rails40_sprockets_3.gemfile} +0 -0
- data/gemfiles/{rails41.gemfile → rails41_sprockets_2.gemfile} +1 -1
- data/gemfiles/{rails41_sprockets3.gemfile → rails41_sprockets_3.gemfile} +0 -0
- data/gemfiles/{rails32.gemfile → rails42_sprockets_2.gemfile} +2 -2
- data/gemfiles/{rails42_sprockets3.gemfile → rails42_sprockets_3.gemfile} +1 -1
- data/gemfiles/{rails50_sprockets3.gemfile → rails50_sprockets_3.gemfile} +1 -1
- data/gemfiles/rails51_sprockets_3.gemfile +8 -0
- data/gemfiles/rails52_sprockets_3.gemfile +8 -0
- data/js-routes.gemspec +9 -6
- data/lib/js_routes/engine.rb +6 -18
- data/lib/js_routes/version.rb +1 -1
- data/lib/js_routes.rb +329 -171
- data/lib/routes.d.ts +79 -0
- data/lib/routes.js +499 -485
- data/lib/routes.ts +732 -0
- data/lib/tasks/js_routes.rake +8 -2
- data/package.json +37 -0
- data/spec/dummy/app/assets/config/manifest.js +2 -0
- data/spec/js_routes/default_serializer_spec.rb +19 -3
- data/spec/js_routes/{amd_compatibility_spec.rb → module_types/amd_spec.rb} +1 -9
- data/spec/js_routes/module_types/cjs_spec.rb +15 -0
- data/spec/js_routes/module_types/dts/routes.spec.d.ts +114 -0
- data/spec/js_routes/module_types/dts/test.spec.ts +56 -0
- data/spec/js_routes/module_types/dts_spec.rb +111 -0
- data/spec/js_routes/module_types/esm_spec.rb +45 -0
- data/spec/js_routes/{generated_javascript_spec.rb → module_types/umd_spec.rb} +33 -27
- data/spec/js_routes/options_spec.rb +92 -50
- data/spec/js_routes/rails_routes_compatibility_spec.rb +107 -45
- data/spec/js_routes/zzz_last_post_rails_init_spec.rb +19 -8
- data/spec/spec_helper.rb +45 -42
- data/spec/support/routes.rb +19 -14
- data/spec/tsconfig.json +4 -0
- data/tsconfig.json +28 -0
- data/yarn.lock +2145 -0
- metadata +47 -34
- data/gemfiles/rails42.gemfile +0 -8
- data/gemfiles/rails50.gemfile +0 -8
- data/lib/routes.js.coffee +0 -386
data/spec/spec_helper.rb
CHANGED
@@ -6,16 +6,21 @@ require 'rspec'
|
|
6
6
|
require 'rails/all'
|
7
7
|
require 'js-routes'
|
8
8
|
require 'active_support/core_ext/hash/slice'
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
|
10
|
+
unless ENV['TRAVIS_CI']
|
11
|
+
code = system("yarn build")
|
12
|
+
unless code
|
13
|
+
exit(1)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
12
17
|
|
13
18
|
if defined?(JRUBY_VERSION)
|
14
19
|
require 'rhino'
|
15
20
|
JS_LIB_CLASS = Rhino
|
16
21
|
else
|
17
|
-
require '
|
18
|
-
JS_LIB_CLASS =
|
22
|
+
require 'mini_racer'
|
23
|
+
JS_LIB_CLASS = MiniRacer
|
19
24
|
end
|
20
25
|
|
21
26
|
def jscontext(force = false)
|
@@ -27,11 +32,22 @@ def jscontext(force = false)
|
|
27
32
|
end
|
28
33
|
|
29
34
|
def js_error_class
|
30
|
-
|
35
|
+
if defined?(JRUBY_VERSION)
|
36
|
+
JS_LIB_CLASS::JSError
|
37
|
+
else
|
38
|
+
JS_LIB_CLASS::Error
|
39
|
+
end
|
31
40
|
end
|
32
41
|
|
33
|
-
def evaljs(string, force
|
34
|
-
jscontext(force).eval(string)
|
42
|
+
def evaljs(string, force: false, filename: 'context.js')
|
43
|
+
jscontext(force).eval(string, filename: filename)
|
44
|
+
rescue MiniRacer::ParseError => e
|
45
|
+
message = e.message
|
46
|
+
_, _, line, _ = message.split(':')
|
47
|
+
code = line && string.split("\n")[line.to_i-1]
|
48
|
+
raise "#{message}. Code: #{code.strip}";
|
49
|
+
rescue MiniRacer::RuntimeError => e
|
50
|
+
raise e
|
35
51
|
end
|
36
52
|
|
37
53
|
def test_routes
|
@@ -42,11 +58,21 @@ def blog_routes
|
|
42
58
|
BlogEngine::Engine.routes.url_helpers
|
43
59
|
end
|
44
60
|
|
61
|
+
def planner_routes
|
62
|
+
Planner::Engine.routes.url_helpers
|
63
|
+
end
|
64
|
+
|
45
65
|
ActiveSupport::Inflector.inflections do |inflect|
|
46
66
|
inflect.irregular "budgie", "budgies"
|
47
67
|
end
|
48
68
|
|
49
69
|
|
70
|
+
module Planner
|
71
|
+
class Engine < Rails::Engine
|
72
|
+
isolate_namespace Planner
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
50
76
|
module BlogEngine
|
51
77
|
class Engine < Rails::Engine
|
52
78
|
isolate_namespace BlogEngine
|
@@ -60,13 +86,7 @@ class ::App < Rails::Application
|
|
60
86
|
config.assets.enabled = true
|
61
87
|
# initialize_on_precompile
|
62
88
|
config.assets.initialize_on_precompile = true
|
63
|
-
|
64
|
-
if 3 == Rails::VERSION::MAJOR
|
65
|
-
config.paths['config/routes'] << 'spec/config/routes.rb'
|
66
|
-
else
|
67
|
-
config.paths['config/routes.rb'] << 'spec/config/routes.rb'
|
68
|
-
end
|
69
|
-
|
89
|
+
config.paths['config/routes.rb'] << 'spec/config/routes.rb'
|
70
90
|
config.root = File.expand_path('../dummy', __FILE__)
|
71
91
|
end
|
72
92
|
|
@@ -83,39 +103,22 @@ RSpec.configure do |config|
|
|
83
103
|
c.syntax = :expect
|
84
104
|
end
|
85
105
|
|
86
|
-
config.before(:
|
87
|
-
# compile all js files begin
|
88
|
-
Dir["#{File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))}/**/*.coffee"].each do |coffee|
|
89
|
-
File.open(coffee.gsub(/\.coffee$/, ""), 'w') do |f|
|
90
|
-
f.write(CoffeeScript.compile(File.read(coffee)).lstrip)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
# compile all js files end
|
106
|
+
config.before(:suite) do
|
94
107
|
draw_routes
|
95
108
|
end
|
96
109
|
|
97
110
|
config.before :each do
|
98
|
-
evaljs("var window = this;", true)
|
99
|
-
|
100
|
-
def inspectify(value)
|
101
|
-
case value
|
102
|
-
when V8::Array
|
103
|
-
value.map do |v|
|
104
|
-
inspectify(v)
|
105
|
-
end
|
106
|
-
when V8::Object
|
107
|
-
value.to_h.map do |k,v|
|
108
|
-
[k, inspectify(v)]
|
109
|
-
end.to_h
|
110
|
-
when String, nil, Fixnum, FalseClass, TrueClass
|
111
|
-
value
|
112
|
-
else
|
113
|
-
raise "wtf #{value.class}?"
|
114
|
-
end
|
111
|
+
evaljs("var window = this;", {force: true})
|
115
112
|
|
113
|
+
log = proc do |*values|
|
114
|
+
puts values.map(&:inspect).join(", ")
|
116
115
|
end
|
117
|
-
|
118
|
-
|
116
|
+
if defined?(JRUBY_VERSION)
|
117
|
+
jscontext[:"console.log"] = lambda do |context, *values|
|
118
|
+
log(*values)
|
119
|
+
end
|
120
|
+
else
|
121
|
+
jscontext.attach("console.log", log)
|
119
122
|
end
|
120
123
|
end
|
121
124
|
end
|
data/spec/support/routes.rb
CHANGED
@@ -1,32 +1,39 @@
|
|
1
1
|
def draw_routes
|
2
|
+
Planner::Engine.routes.draw do
|
3
|
+
get "/manage" => 'foo#foo', as: :manage
|
4
|
+
end
|
2
5
|
|
3
6
|
BlogEngine::Engine.routes.draw do
|
4
7
|
root to: "application#index"
|
5
|
-
resources :posts
|
8
|
+
resources :posts, only: [:show, :index]
|
6
9
|
end
|
7
10
|
App.routes.draw do
|
8
11
|
|
12
|
+
mount Planner::Engine, at: "/(locale/:locale)", as: :planner
|
13
|
+
|
14
|
+
mount BlogEngine::Engine => "/blog", as: :blog_app
|
9
15
|
get 'support(/page/:page)', to: BlogEngine::Engine, as: 'support'
|
10
16
|
|
11
|
-
resources :inboxes do
|
12
|
-
resources :messages do
|
13
|
-
resources :attachments
|
17
|
+
resources :inboxes, only: [:index, :show] do
|
18
|
+
resources :messages, only: [:index, :show] do
|
19
|
+
resources :attachments, only: [:new, :show]
|
14
20
|
end
|
15
21
|
end
|
16
22
|
|
23
|
+
get "(/:space)/campaigns" => "foo#foo", as: :campaigns, defaults: {space: nil}
|
24
|
+
|
17
25
|
root :to => "inboxes#index"
|
18
26
|
|
19
27
|
namespace :admin do
|
20
|
-
resources :users
|
28
|
+
resources :users, only: [:index]
|
21
29
|
end
|
22
30
|
|
23
31
|
scope "/returns/:return" do
|
24
|
-
resources :objects
|
32
|
+
resources :objects, only: [:show]
|
25
33
|
end
|
26
|
-
resources :returns
|
27
34
|
|
28
35
|
scope "(/optional/:optional_id)" do
|
29
|
-
resources :things
|
36
|
+
resources :things, only: [:show, :index]
|
30
37
|
end
|
31
38
|
|
32
39
|
get "(/sep1/:first_optional)/sep2/:second_required/sep3/:third_required(/:forth_optional)",
|
@@ -42,8 +49,6 @@ def draw_routes
|
|
42
49
|
get 'books/*section/:title' => 'books#show', :as => :book
|
43
50
|
get 'books/:title/*section' => 'books#show', :as => :book_title
|
44
51
|
|
45
|
-
mount BlogEngine::Engine => "/blog", :as => :blog_app
|
46
|
-
|
47
52
|
get '/no_format' => "foo#foo", :format => false, :as => :no_format
|
48
53
|
|
49
54
|
get '/json_only' => "foo#foo", :format => true, :constraints => {:format => /json/}, :as => :json_only
|
@@ -51,11 +56,11 @@ def draw_routes
|
|
51
56
|
get '/привет' => "foo#foo", :as => :hello
|
52
57
|
get '(/o/:organization)/search/:q' => "foo#foo", as: :search
|
53
58
|
|
54
|
-
resources :sessions, :only => [:new, :create
|
55
|
-
|
59
|
+
resources :sessions, :only => [:new, :create], :protocol => 'https'
|
56
60
|
get '/' => 'sso#login', host: 'sso.example.com', as: :sso
|
61
|
+
get "/" => "a#b", subdomain: 'www', host: 'example.com', port: 88, as: :secret_root
|
57
62
|
|
58
|
-
resources :portals, :port => 8080
|
63
|
+
resources :portals, :port => 8080, only: [:index]
|
59
64
|
|
60
65
|
get '/with_defaults' => 'foo#foo', defaults: { bar: 'tested', format: :json }, format: :true
|
61
66
|
|
@@ -63,7 +68,7 @@ def draw_routes
|
|
63
68
|
get "/purchases" => "purchases#index"
|
64
69
|
end
|
65
70
|
|
66
|
-
resources :budgies do
|
71
|
+
resources :budgies, only: [:show, :index] do
|
67
72
|
get "descendents"
|
68
73
|
end
|
69
74
|
|
data/spec/tsconfig.json
ADDED
data/tsconfig.json
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
{
|
2
|
+
"compilerOptions": {
|
3
|
+
"target": "es2019",
|
4
|
+
"lib": ["es2020", "dom"],
|
5
|
+
"module": "commonjs",
|
6
|
+
"sourceMap": false,
|
7
|
+
"declaration": true,
|
8
|
+
"allowSyntheticDefaultImports": true,
|
9
|
+
"resolveJsonModule": false,
|
10
|
+
"strictNullChecks": true,
|
11
|
+
"noImplicitAny": true,
|
12
|
+
"noImplicitThis": true,
|
13
|
+
"strictBindCallApply": true,
|
14
|
+
"strictFunctionTypes": true,
|
15
|
+
"alwaysStrict": false,
|
16
|
+
|
17
|
+
"esModuleInterop": true,
|
18
|
+
"forceConsistentCasingInFileNames": true,
|
19
|
+
"emitDecoratorMetadata": true,
|
20
|
+
"experimentalDecorators": true
|
21
|
+
|
22
|
+
},
|
23
|
+
"ts-node": {
|
24
|
+
"files": true,
|
25
|
+
"transpileOnly": false
|
26
|
+
},
|
27
|
+
"include": ["lib/*.ts"]
|
28
|
+
}
|