routesjs-rails 0.0.3 → 0.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 +4 -4
- data/README.md +86 -9
- data/lib/generators/routes_js/module/module_generator.rb +36 -0
- data/lib/routesjs-rails.rb +1 -1
- data/lib/routesjs/rails/version.rb +1 -1
- data/lib/routesjs/routes.rb +7 -2
- data/lib/routesjs/routing/route.rb +39 -0
- data/test/dummy/config/application.rb +3 -2
- data/test/dummy/config/environments/development.rb +1 -1
- data/test/dummy/config/environments/production.rb +1 -1
- data/test/dummy/config/environments/test.rb +1 -1
- data/test/dummy/config/routes.rb +1 -1
- data/test/dummy/log/development.log +2269 -0
- data/test/dummy/log/test.log +2384 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/1ef842e27a58c8d5c6c766a808769124 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/2df1d6547949be98cd48ede842b34de8 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/3e71ddc988273b8745f0699a893f6fae +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/5c5fe53e623b63ead476521957eb59ad +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/7515bb9ad36eda8e3aac73de7b584b3c +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/7cfb78f56f62208e304eaee5a4687ff5 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/8e3d112db39b8bcf2303854a25c999b9 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/96832d64502eeedb77b21df1afce651e +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/96a60c4d6d1a4f2e334ce111b9b15a44 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/ae24e9c0cdbfb9ec06caa64916150789 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/bf36f67f2b6fbdcfe8d00c090481e768 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/fbe3b083eab395ea58275e685320100c +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/1ef842e27a58c8d5c6c766a808769124 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/2df1d6547949be98cd48ede842b34de8 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/5c5fe53e623b63ead476521957eb59ad +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/7515bb9ad36eda8e3aac73de7b584b3c +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/7cfb78f56f62208e304eaee5a4687ff5 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/96a60c4d6d1a4f2e334ce111b9b15a44 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/ae24e9c0cdbfb9ec06caa64916150789 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/bf36f67f2b6fbdcfe8d00c090481e768 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/fbe3b083eab395ea58275e685320100c +0 -0
- data/test/generators/routes_js/module_generator_test.rb +35 -0
- data/test/generators/tmp/app/assets/javascripts/routesjs.js +75 -0
- data/test/javascripts/routesjs-rails_spec.js +74 -0
- data/test/javascripts/spec_helper.js +4 -0
- data/test/routesjs/routing/route_test.rb +62 -0
- data/test/test_helper.rb +7 -0
- data/vendor/assets/javascripts/routesjs-rails.js.erb +11 -2
- metadata +55 -17
- data/lib/routesjs/formatter.rb +0 -56
- data/lib/tasks/routesjs_tasks.rake +0 -9
- data/test/dummy/config/database.yml +0 -25
- data/test/javascripts/routesjs-rails_spec.coffee +0 -50
- data/test/javascripts/spec_helper.coffee +0 -31
- data/test/routesjs/formatter_test.rb +0 -65
data/lib/routesjs/formatter.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
require "action_dispatch/routing/inspector"
|
2
|
-
|
3
|
-
module RoutesJS
|
4
|
-
class Formatter
|
5
|
-
REDIRECT_URL = /\Aredirect\(\d+,([^)]+)\)\z/.freeze
|
6
|
-
|
7
|
-
def routes
|
8
|
-
@routes ||= {}
|
9
|
-
end
|
10
|
-
|
11
|
-
def result
|
12
|
-
routes.to_json
|
13
|
-
end
|
14
|
-
|
15
|
-
def no_routes; end
|
16
|
-
def header(routes); end
|
17
|
-
def section_title(title); end
|
18
|
-
|
19
|
-
def section(routes_in_section)
|
20
|
-
named_routes(routes_in_section).each do |route|
|
21
|
-
routes[route_name(route)] = route_path(route)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def named_routes(routes)
|
28
|
-
routes.reject { |route| route[:name].blank? }
|
29
|
-
end
|
30
|
-
|
31
|
-
def route_name(route)
|
32
|
-
route[:name].camelize(:lower)
|
33
|
-
end
|
34
|
-
|
35
|
-
def route_path(route)
|
36
|
-
case
|
37
|
-
when redirect?(route)
|
38
|
-
redirect_url(route)
|
39
|
-
else
|
40
|
-
path_without_format(route)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def redirect?(route)
|
45
|
-
REDIRECT_URL =~ route[:reqs]
|
46
|
-
end
|
47
|
-
|
48
|
-
def redirect_url(route)
|
49
|
-
REDIRECT_URL.match(route[:reqs])[1].strip
|
50
|
-
end
|
51
|
-
|
52
|
-
def path_without_format(route)
|
53
|
-
route[:path].sub(/\(\.:format\)\z/, "")
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# SQLite version 3.x
|
2
|
-
# gem install sqlite3
|
3
|
-
#
|
4
|
-
# Ensure the SQLite 3 gem is defined in your Gemfile
|
5
|
-
# gem 'sqlite3'
|
6
|
-
#
|
7
|
-
default: &default
|
8
|
-
adapter: sqlite3
|
9
|
-
pool: 5
|
10
|
-
timeout: 5000
|
11
|
-
|
12
|
-
development:
|
13
|
-
<<: *default
|
14
|
-
database: db/development.sqlite3
|
15
|
-
|
16
|
-
# Warning: The database defined as "test" will be erased and
|
17
|
-
# re-generated from your development database when you run "rake".
|
18
|
-
# Do not set this db to the same as development or production.
|
19
|
-
test:
|
20
|
-
<<: *default
|
21
|
-
database: db/test.sqlite3
|
22
|
-
|
23
|
-
production:
|
24
|
-
<<: *default
|
25
|
-
database: db/production.sqlite3
|
@@ -1,50 +0,0 @@
|
|
1
|
-
describe "Routes", ->
|
2
|
-
beforeEach ->
|
3
|
-
Routes.setBaseUrl("//example.com/")
|
4
|
-
|
5
|
-
describe "simple path and url generation", ->
|
6
|
-
beforeEach ->
|
7
|
-
Routes.initRoutes
|
8
|
-
"oauthToken": "/oauth/token"
|
9
|
-
"adminRoot": "/admin"
|
10
|
-
|
11
|
-
it "makes a path function for each route", ->
|
12
|
-
expect(Routes.oauthTokenPath()).toBe("/oauth/token")
|
13
|
-
expect(Routes.adminRootPath()).toBe("/admin")
|
14
|
-
|
15
|
-
it "makes a url function for each route", ->
|
16
|
-
expect(Routes.oauthTokenUrl()).toBe("//example.com/oauth/token")
|
17
|
-
expect(Routes.adminRootUrl()).toBe("//example.com/admin")
|
18
|
-
|
19
|
-
describe "token replacement with object", ->
|
20
|
-
beforeEach ->
|
21
|
-
Routes.initRoutes
|
22
|
-
"user": "/users/:id"
|
23
|
-
"userRoles": "/users/:id/roles"
|
24
|
-
"userRole": "/users/:id/roles/:role_id"
|
25
|
-
|
26
|
-
it "replaces tokens with values from object", ->
|
27
|
-
user =
|
28
|
-
id: 1
|
29
|
-
role_id: 2
|
30
|
-
|
31
|
-
expect(Routes.userPath(user)).toBe("/users/1")
|
32
|
-
expect(Routes.userRolesPath(user)).toBe("/users/1/roles")
|
33
|
-
expect(Routes.userRoleUrl(user)).toBe("//example.com/users/1/roles/2")
|
34
|
-
|
35
|
-
describe "token replacement with arguments", ->
|
36
|
-
beforeEach ->
|
37
|
-
Routes.initRoutes
|
38
|
-
"root": "/"
|
39
|
-
"user": "/users/:id"
|
40
|
-
"userRole": "/users/:id/roles/:role_id"
|
41
|
-
|
42
|
-
it "replaces tokens with ordered arguments", ->
|
43
|
-
expect(Routes.userPath(1)).toBe("/users/1")
|
44
|
-
expect(Routes.userRoleUrl(1, "admin")).toBe("//example.com/users/1/roles/admin")
|
45
|
-
|
46
|
-
it "ignores extra arguments", ->
|
47
|
-
expect(Routes.userPath(1, "this", 2, "be", "ignored")).toBe("/users/1")
|
48
|
-
|
49
|
-
it "returns the unmodified route when no tokens are found", ->
|
50
|
-
expect(Routes.rootPath(1, 2)).toBe("/")
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# Teaspoon includes some support files, but you can use anything from your own support path too.
|
2
|
-
# require support/jasmine-jquery-1.7.0
|
3
|
-
# require support/jasmine-jquery-2.0.0
|
4
|
-
# require support/sinon
|
5
|
-
# require support/your-support-file
|
6
|
-
#
|
7
|
-
# PhantomJS (Teaspoons default driver) doesn't have support for Function.prototype.bind, which has caused confusion.
|
8
|
-
# Use this polyfill to avoid the confusion.
|
9
|
-
#= require support/bind-poly
|
10
|
-
#
|
11
|
-
# Deferring execution
|
12
|
-
# If you're using CommonJS, RequireJS or some other asynchronous library you can defer execution. Call
|
13
|
-
# Teaspoon.execute() after everything has been loaded. Simple example of a timeout:
|
14
|
-
#
|
15
|
-
# Teaspoon.defer = true
|
16
|
-
# setTimeout(Teaspoon.execute, 1000)
|
17
|
-
#
|
18
|
-
# Matching files
|
19
|
-
# By default Teaspoon will look for files that match _spec.{js,js.coffee,.coffee}. Add a filename_spec.js file in your
|
20
|
-
# spec path and it'll be included in the default suite automatically. If you want to customize suites, check out the
|
21
|
-
# configuration in config/initializers/teaspoon.rb
|
22
|
-
#
|
23
|
-
# Manifest
|
24
|
-
# If you'd rather require your spec files manually (to control order for instance) you can disable the suite matcher in
|
25
|
-
# the configuration and use this file as a manifest.
|
26
|
-
#
|
27
|
-
# For more information: http://github.com/modeset/teaspoon
|
28
|
-
#
|
29
|
-
# You can require your own javascript files here. By default this will include everything in application, however you
|
30
|
-
# may get better load performance if you require the specific files that are being used in the spec that tests them.
|
31
|
-
#= require application
|
@@ -1,65 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class RoutesJS::FormatterTest < ActiveSupport::TestCase
|
4
|
-
include ActionDispatch::Assertions::RoutingAssertions
|
5
|
-
|
6
|
-
setup do
|
7
|
-
inspector.format(formatter)
|
8
|
-
end
|
9
|
-
|
10
|
-
test "only named routes are included" do
|
11
|
-
assert_equal formatter.routes.keys.size, test_routes.size - 1
|
12
|
-
end
|
13
|
-
|
14
|
-
test "hand coded URLs are left as is" do
|
15
|
-
assert_equal "/admin", formatter.routes["admin"]
|
16
|
-
end
|
17
|
-
|
18
|
-
test "namespaced routes include the namespace in the route" do
|
19
|
-
assert_equal "/api/users", formatter.routes["apiUsers"]
|
20
|
-
end
|
21
|
-
|
22
|
-
test "named redirects are supported" do
|
23
|
-
assert_equal "https://google.com/", formatter.routes["google"]
|
24
|
-
end
|
25
|
-
|
26
|
-
test "named redirects within a namespace are supported" do
|
27
|
-
assert_equal "/", formatter.routes["apiHome"]
|
28
|
-
end
|
29
|
-
|
30
|
-
test "result is a valid JSON object" do
|
31
|
-
assert_nothing_raised do
|
32
|
-
JSON.parse(formatter.result)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
def inspector
|
39
|
-
@inspector ||= begin
|
40
|
-
ActionDispatch::Routing::RoutesInspector.new(test_routes)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def formatter
|
45
|
-
@formatter ||= RoutesJS::Formatter.new
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_routes
|
49
|
-
@test_routes ||= with_routing do |set|
|
50
|
-
set.draw do
|
51
|
-
get "/", to: "home#index"
|
52
|
-
get "/admin", to: "home#admin", as: :admin
|
53
|
-
|
54
|
-
get "/google", to: redirect("https://google.com/"), as: :google
|
55
|
-
|
56
|
-
namespace :api do
|
57
|
-
get "/redir", to: redirect("/"), as: :home
|
58
|
-
resources :users, only: [:index, :show]
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
set.routes
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|