js-routes 0.8.7 → 0.8.8
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +52 -0
- data/.travis.yml +7 -1
- data/Gemfile +2 -8
- data/Guardfile +3 -0
- data/Rakefile +2 -15
- data/Readme.md +13 -11
- data/js-routes.gemspec +13 -51
- data/lib/js_routes.rb +7 -3
- data/lib/js_routes/version.rb +3 -0
- data/lib/routes.js +129 -126
- data/lib/routes.js.coffee +132 -0
- data/spec/js_routes/options_spec.rb +31 -11
- data/spec/js_routes/rails_routes_compatibility_spec.rb +3 -3
- data/spec/spec_helper.rb +14 -7
- metadata +124 -102
- data/Gemfile.lock +0 -106
- data/VERSION +0 -1
data/.gitignore
ADDED
@@ -0,0 +1,52 @@
|
|
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
|
+
|
52
|
+
Gemfile.lock
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -1,10 +1,4 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
|
3
|
-
gem
|
4
|
-
|
5
|
-
group :development do
|
6
|
-
gem "therubyracer"
|
7
|
-
gem "rspec", "~> 2.10.0"
|
8
|
-
gem "bundler", "~> 1.1.0"
|
9
|
-
gem "jeweler", "~> 1.6.2"
|
10
|
-
end
|
3
|
+
# Specify your gem's dependencies in js-routes.gemspec
|
4
|
+
gemspec
|
data/Guardfile
ADDED
data/Rakefile
CHANGED
@@ -9,23 +9,10 @@ rescue Bundler::BundlerError => e
|
|
9
9
|
$stderr.puts "Run `bundle install` to install missing gems"
|
10
10
|
exit e.status_code
|
11
11
|
end
|
12
|
-
require '
|
13
|
-
|
14
|
-
require 'jeweler'
|
15
|
-
Jeweler::Tasks.new do |gem|
|
16
|
-
gem.name = "js-routes"
|
17
|
-
gem.homepage = "http://github.com/railsware/js-routes"
|
18
|
-
gem.license = "MIT"
|
19
|
-
gem.summary = %Q{Brings Rails named routes to javascript}
|
20
|
-
gem.description = %Q{Generates javascript file that defines all Rails named routes as javascript helpers}
|
21
|
-
gem.email = "agresso@gmail.com"
|
22
|
-
gem.authors = ["Bogdan Gusiev"]
|
23
|
-
# dependencies defined in Gemfile
|
24
|
-
end
|
25
|
-
Jeweler::RubygemsDotOrgTasks.new
|
26
|
-
|
12
|
+
require 'bundler/gem_tasks'
|
27
13
|
require 'rspec/core'
|
28
14
|
require 'rspec/core/rake_task'
|
15
|
+
|
29
16
|
RSpec::Core::RakeTask.new(:spec) do |spec|
|
30
17
|
spec.pattern = FileList['spec/**/*_spec.rb'].sort_by do|n|
|
31
18
|
# we need to run post_rails_init_spec as the latest
|
data/Readme.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# JsRoutes
|
2
|
+
[![Build Status](https://travis-ci.org/railsware/js-routes.png)](https://travis-ci.org/railsware/js-routes)
|
2
3
|
|
3
4
|
Generates javascript file that defines all Rails named routes as javascript helpers
|
4
5
|
|
@@ -26,9 +27,9 @@ Also in order to flush asset pipeline cache sometimes you might need to run:
|
|
26
27
|
rake tmp:cache:clear
|
27
28
|
```
|
28
29
|
|
29
|
-
This cache is not flushed on server restart in development environment.
|
30
|
+
This cache is not flushed on server restart in development environment.
|
30
31
|
|
31
|
-
**Important:** If routes.js file is not updated after some configuration change you need to run this
|
32
|
+
**Important:** If routes.js file is not updated after some configuration change you need to run this rake task again.
|
32
33
|
|
33
34
|
### Advanced Setup
|
34
35
|
|
@@ -46,19 +47,20 @@ Available options:
|
|
46
47
|
* Note that currently only optional parameters (like `:format`) can be defaulted.
|
47
48
|
* Example: {:format => "json"}
|
48
49
|
* Default: {}
|
49
|
-
* `exclude` - Array of regexps to exclude from js routes.
|
50
|
+
* `exclude` - Array of regexps to exclude from js routes.
|
50
51
|
* Note that regexp applied to **named route** not to *URL*
|
51
52
|
* Default: []
|
52
|
-
* `include` - Array of regexps to include in js routes.
|
53
|
+
* `include` - Array of regexps to include in js routes.
|
53
54
|
* Note that regexp applied to **named route** not to *URL*
|
54
55
|
* Default: []
|
55
|
-
* `namespace` - global object used to access routes.
|
56
|
+
* `namespace` - global object used to access routes.
|
56
57
|
* Supports nested namespace like `MyProject.routes`
|
57
58
|
* Default: `Routes`
|
58
|
-
* `prefix` - String representing a url path to prepend to all paths.
|
59
|
-
* Example: `http://yourdomain.com`. This will cause route helpers to generate full path only.
|
59
|
+
* `prefix` - String representing a url path to prepend to all paths.
|
60
|
+
* Example: `http://yourdomain.com`. This will cause route helpers to generate full path only.
|
60
61
|
* Default: blank
|
61
|
-
|
62
|
+
* `camel_case` (version >= 0.8.8) - Generate camel case route names.
|
63
|
+
* Default: false
|
62
64
|
|
63
65
|
You can generate routes files on the application side like this:
|
64
66
|
|
@@ -105,7 +107,7 @@ jQuery.extend(window, Routes)
|
|
105
107
|
|
106
108
|
## What about security?
|
107
109
|
|
108
|
-
js-routes itself do not have security holes. It makes URLs
|
110
|
+
js-routes itself do not have security holes. It makes URLs
|
109
111
|
without access protection more reachable by potential attacker.
|
110
112
|
In order to prevent this use `:exclude` option for sensitive urls like `/admin_/`
|
111
113
|
|
@@ -119,7 +121,7 @@ Spork.trap_method(JsRoutes, :generate!)
|
|
119
121
|
|
120
122
|
## Advantages over alternatives
|
121
123
|
|
122
|
-
There are some alternatives available. Most of them has only basic feature and don't reach the level of quality I accept.
|
124
|
+
There are some alternatives available. Most of them has only basic feature and don't reach the level of quality I accept.
|
123
125
|
Advantages of this one are:
|
124
126
|
|
125
127
|
* Rails3 support
|
@@ -129,4 +131,4 @@ Advantages of this one are:
|
|
129
131
|
|
130
132
|
#### Thanks to [Contributors](https://github.com/railsware/js-routes/contributors)
|
131
133
|
|
132
|
-
#### Have fun
|
134
|
+
#### Have fun
|
data/js-routes.gemspec
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'js_routes/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{js-routes}
|
8
|
-
s.version =
|
8
|
+
s.version = JsRoutes::VERSION
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Bogdan Gusiev"]
|
@@ -15,57 +15,19 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE.txt"
|
17
17
|
]
|
18
|
-
s.files =
|
19
|
-
".document",
|
20
|
-
".rspec",
|
21
|
-
".travis.yml",
|
22
|
-
"Gemfile",
|
23
|
-
"Gemfile.lock",
|
24
|
-
"LICENSE.txt",
|
25
|
-
"Rakefile",
|
26
|
-
"Readme.md",
|
27
|
-
"VERSION",
|
28
|
-
"app/assets/javascripts/js-routes.js.erb",
|
29
|
-
"js-routes.gemspec",
|
30
|
-
"lib/js-routes.rb",
|
31
|
-
"lib/js_routes.rb",
|
32
|
-
"lib/js_routes/engine.rb",
|
33
|
-
"lib/routes.js",
|
34
|
-
"lib/tasks/js_routes.rake",
|
35
|
-
"spec/js_routes/generated_javascript_spec.rb",
|
36
|
-
"spec/js_routes/options_spec.rb",
|
37
|
-
"spec/js_routes/post_rails_init_spec.rb",
|
38
|
-
"spec/js_routes/rails_routes_compatibility_spec.rb",
|
39
|
-
"spec/spec_helper.rb"
|
40
|
-
]
|
18
|
+
s.files = `git ls-files`.split("\n")
|
41
19
|
s.homepage = %q{http://github.com/railsware/js-routes}
|
42
20
|
s.licenses = ["MIT"]
|
43
21
|
s.require_paths = ["lib"]
|
44
22
|
s.rubygems_version = %q{1.6.0}
|
45
23
|
s.summary = %q{Brings Rails named routes to javascript}
|
46
24
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
s.add_development_dependency(%q<bundler>, ["~> 1.1.0"])
|
55
|
-
s.add_development_dependency(%q<jeweler>, ["~> 1.6.2"])
|
56
|
-
else
|
57
|
-
s.add_dependency(%q<rails>, [">= 3.2"])
|
58
|
-
s.add_dependency(%q<therubyracer>, [">= 0"])
|
59
|
-
s.add_dependency(%q<rspec>, ["~> 2.10.0"])
|
60
|
-
s.add_dependency(%q<bundler>, ["~> 1.1.0"])
|
61
|
-
s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
|
62
|
-
end
|
63
|
-
else
|
64
|
-
s.add_dependency(%q<rails>, [">= 3.2"])
|
65
|
-
s.add_dependency(%q<therubyracer>, [">= 0"])
|
66
|
-
s.add_dependency(%q<rspec>, ["~> 2.10.0"])
|
67
|
-
s.add_dependency(%q<bundler>, ["~> 1.1.0"])
|
68
|
-
s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
|
69
|
-
end
|
25
|
+
s.add_runtime_dependency(%q<rails>, [">= 3.2"])
|
26
|
+
s.add_development_dependency(%q<therubyracer>, [">= 0"])
|
27
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.10.0"])
|
28
|
+
s.add_development_dependency(%q<bundler>, [">= 1.1.0"])
|
29
|
+
s.add_development_dependency(%q<guard>, [">= 0"])
|
30
|
+
s.add_development_dependency(%q<rb-fsevent>, [">= 0"])
|
31
|
+
s.add_development_dependency(%q<guard-coffeescript>, [">= 0"])
|
70
32
|
end
|
71
33
|
|
data/lib/js_routes.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'js_routes/version'
|
1
2
|
class JsRoutes
|
2
3
|
|
3
4
|
#
|
@@ -12,6 +13,7 @@ class JsRoutes
|
|
12
13
|
:include => //,
|
13
14
|
:file => DEFAULT_PATH,
|
14
15
|
:prefix => "",
|
16
|
+
:camel_case => false,
|
15
17
|
:default_url_options => {}
|
16
18
|
}
|
17
19
|
|
@@ -93,9 +95,9 @@ class JsRoutes
|
|
93
95
|
end
|
94
96
|
|
95
97
|
def deprecated_default_format
|
96
|
-
if @options.key?(:default_format)
|
98
|
+
if @options.key?(:default_format)
|
97
99
|
warn("default_format option is deprecated. Use default_url_options = {:format => <format>} instead")
|
98
|
-
{:format => @options[:default_format]}
|
100
|
+
{:format => @options[:default_format]}
|
99
101
|
else
|
100
102
|
{}
|
101
103
|
end
|
@@ -149,9 +151,11 @@ class JsRoutes
|
|
149
151
|
required_parts = route.required_parts.clone
|
150
152
|
optional_parts = route.optional_parts.clone
|
151
153
|
optional_parts.push(required_parts.delete :format) if required_parts.include?(:format)
|
154
|
+
route_name = "#{name.join('_')}_path"
|
155
|
+
route_name = route_name.camelize(:lower) if true == @options[:camel_case]
|
152
156
|
_ = <<-JS.strip!
|
153
157
|
// #{name.join('.')} => #{parent_spec}#{route.path.spec}
|
154
|
-
#{
|
158
|
+
#{route_name}: function(#{build_params(required_parts)}) {
|
155
159
|
return Utils.build_path(#{json(required_parts)}, #{json(optional_parts)}, #{json(serialize(route.path.spec, parent_spec))}, arguments);
|
156
160
|
}
|
157
161
|
JS
|
data/lib/routes.js
CHANGED
@@ -1,205 +1,208 @@
|
|
1
|
-
(function(){
|
1
|
+
(function() {
|
2
|
+
var NodeTypes, ParameterMissing, Utils, defaults,
|
3
|
+
__hasProp = {}.hasOwnProperty;
|
2
4
|
|
3
|
-
function
|
4
|
-
|
5
|
-
}
|
6
|
-
|
5
|
+
ParameterMissing = function(message) {
|
6
|
+
this.message = message;
|
7
|
+
};
|
8
|
+
|
9
|
+
ParameterMissing.prototype = new Error();
|
7
10
|
|
8
|
-
|
9
|
-
prefix:
|
11
|
+
defaults = {
|
12
|
+
prefix: "PREFIX",
|
10
13
|
default_url_options: DEFAULT_URL_OPTIONS
|
11
14
|
};
|
12
15
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
+
NodeTypes = NODE_TYPES;
|
17
|
+
|
18
|
+
Utils = {
|
19
|
+
serialize: function(obj) {
|
20
|
+
var i, key, prop, result, s, val, _i, _len;
|
16
21
|
|
17
|
-
|
18
|
-
|
22
|
+
if (!obj) {
|
23
|
+
return "";
|
24
|
+
}
|
19
25
|
if (window.jQuery) {
|
20
|
-
|
21
|
-
return !result ? "" : "?" + result
|
22
|
-
}
|
23
|
-
|
24
|
-
for (
|
25
|
-
if (obj
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
result = window.jQuery.param(obj);
|
27
|
+
return (!result ? "" : "?" + result);
|
28
|
+
}
|
29
|
+
s = [];
|
30
|
+
for (key in obj) {
|
31
|
+
if (!__hasProp.call(obj, key)) continue;
|
32
|
+
prop = obj[key];
|
33
|
+
if (prop != null) {
|
34
|
+
if (prop instanceof Array) {
|
35
|
+
for (i = _i = 0, _len = prop.length; _i < _len; i = ++_i) {
|
36
|
+
val = prop[i];
|
37
|
+
s.push("" + key + (encodeURIComponent("[]")) + "=" + (encodeURIComponent(val.toString())));
|
30
38
|
}
|
31
39
|
} else {
|
32
|
-
s.push(
|
40
|
+
s.push("" + key + "=" + (encodeURIComponent(prop.toString())));
|
33
41
|
}
|
34
42
|
}
|
35
43
|
}
|
36
|
-
if (s.length
|
37
|
-
return
|
44
|
+
if (!s.length) {
|
45
|
+
return "";
|
38
46
|
}
|
39
|
-
return "?" + s.join(
|
47
|
+
return "?" + (s.join("&"));
|
40
48
|
},
|
41
|
-
|
42
49
|
clean_path: function(path) {
|
50
|
+
var last_index;
|
51
|
+
|
43
52
|
path = path.split("://");
|
44
|
-
|
45
|
-
path[last_index] = path[last_index].replace(/\/+/g, "/").replace(/\/$/m,
|
53
|
+
last_index = path.length - 1;
|
54
|
+
path[last_index] = path[last_index].replace(/\/+/g, "/").replace(/\/$/m, "");
|
46
55
|
return path.join("://");
|
47
56
|
},
|
48
|
-
|
49
57
|
set_default_url_options: function(optional_parts, options) {
|
50
|
-
|
51
|
-
|
58
|
+
var i, part, _i, _len, _results;
|
59
|
+
|
60
|
+
_results = [];
|
61
|
+
for (i = _i = 0, _len = optional_parts.length; _i < _len; i = ++_i) {
|
62
|
+
part = optional_parts[i];
|
52
63
|
if (!options.hasOwnProperty(part) && defaults.default_url_options.hasOwnProperty(part)) {
|
53
|
-
options[part] = defaults.default_url_options[part];
|
64
|
+
_results.push(options[part] = defaults.default_url_options[part]);
|
65
|
+
} else {
|
66
|
+
_results.push(void 0);
|
54
67
|
}
|
55
68
|
}
|
69
|
+
return _results;
|
56
70
|
},
|
57
|
-
|
58
71
|
extract_anchor: function(options) {
|
59
|
-
var anchor
|
60
|
-
delete options.anchor;
|
61
|
-
return anchor ? "#" + anchor : "";
|
62
|
-
},
|
72
|
+
var anchor;
|
63
73
|
|
64
|
-
|
65
|
-
if (
|
66
|
-
|
67
|
-
|
68
|
-
return {};
|
74
|
+
anchor = "";
|
75
|
+
if (options.hasOwnProperty("anchor")) {
|
76
|
+
anchor = "#" + options.anchor;
|
77
|
+
options.anchor = null;
|
69
78
|
}
|
79
|
+
return anchor;
|
70
80
|
},
|
81
|
+
extract_options: function(number_of_params, args) {
|
82
|
+
var ret_value;
|
71
83
|
|
84
|
+
ret_value = {};
|
85
|
+
if (args.length > number_of_params && typeof args[args.length - 1] === "object") {
|
86
|
+
ret_value = args.pop();
|
87
|
+
}
|
88
|
+
return ret_value;
|
89
|
+
},
|
72
90
|
path_identifier: function(object) {
|
91
|
+
var property;
|
92
|
+
|
73
93
|
if (object === 0) {
|
74
|
-
return
|
94
|
+
return "0";
|
75
95
|
}
|
76
|
-
|
77
|
-
|
78
|
-
return '';
|
96
|
+
if (!object) {
|
97
|
+
return "";
|
79
98
|
}
|
80
|
-
|
81
|
-
if (typeof
|
82
|
-
|
83
|
-
if (typeof
|
84
|
-
property = property.call(object)
|
99
|
+
property = object;
|
100
|
+
if (typeof object === "object") {
|
101
|
+
property = object.to_param || object.id || object;
|
102
|
+
if (typeof property === "function") {
|
103
|
+
property = property.call(object);
|
85
104
|
}
|
86
|
-
return property.toString();
|
87
|
-
} else {
|
88
|
-
return object.toString();
|
89
105
|
}
|
106
|
+
return property.toString();
|
90
107
|
},
|
108
|
+
clone: function(obj) {
|
109
|
+
var attr, copy, key;
|
91
110
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
111
|
+
if (null === obj || "object" !== typeof obj) {
|
112
|
+
return obj;
|
113
|
+
}
|
114
|
+
copy = obj.constructor();
|
115
|
+
for (key in obj) {
|
116
|
+
if (!__hasProp.call(obj, key)) continue;
|
117
|
+
attr = obj[key];
|
118
|
+
copy[key] = attr;
|
97
119
|
}
|
98
120
|
return copy;
|
99
121
|
},
|
100
|
-
|
101
122
|
prepare_parameters: function(required_parameters, actual_parameters, options) {
|
102
|
-
var result
|
103
|
-
|
104
|
-
|
123
|
+
var i, result, val, _i, _len;
|
124
|
+
|
125
|
+
result = this.clone(options) || {};
|
126
|
+
for (i = _i = 0, _len = required_parameters.length; _i < _len; i = ++_i) {
|
127
|
+
val = required_parameters[i];
|
128
|
+
result[val] = actual_parameters[i];
|
105
129
|
}
|
106
130
|
return result;
|
107
131
|
},
|
108
|
-
|
109
132
|
build_path: function(required_parameters, optional_parts, route, args) {
|
133
|
+
var opts, parameters, result;
|
134
|
+
|
110
135
|
args = Array.prototype.slice.call(args);
|
111
|
-
|
136
|
+
opts = this.extract_options(required_parameters.length, args);
|
112
137
|
if (args.length > required_parameters.length) {
|
113
138
|
throw new Error("Too many parameters provided for path");
|
114
139
|
}
|
115
|
-
|
116
|
-
var parameters = this.prepare_parameters(required_parameters, args, opts);
|
140
|
+
parameters = this.prepare_parameters(required_parameters, args, opts);
|
117
141
|
this.set_default_url_options(optional_parts, parameters);
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
result += this.visit(route, parameters)
|
122
|
-
return Utils.clean_path(result + anchor) + Utils.serialize(parameters);
|
142
|
+
result = "" + (Utils.get_prefix()) + (this.visit(route, parameters));
|
143
|
+
return Utils.clean_path("" + result + (Utils.extract_anchor(parameters))) + Utils.serialize(parameters);
|
123
144
|
},
|
124
|
-
|
125
|
-
/*
|
126
|
-
* This function is JavaScript impelementation of the
|
127
|
-
* Journey::Visitors::Formatter that builds route by given parameters
|
128
|
-
* from route binary tree.
|
129
|
-
* Binary tree is serialized in the following way:
|
130
|
-
* [node type, left node, right node ]
|
131
|
-
*
|
132
|
-
* @param {Boolean} optional Marks the currently visited branch as optional.
|
133
|
-
* If set to `true`, this method will not throw when encountering
|
134
|
-
* a missing parameter (used in recursive calls).
|
135
|
-
*/
|
136
145
|
visit: function(route, parameters, optional) {
|
137
|
-
var type
|
138
|
-
|
139
|
-
|
146
|
+
var left, left_part, right, right_part, type, value;
|
147
|
+
|
148
|
+
type = route[0], left = route[1], right = route[2];
|
140
149
|
switch (type) {
|
141
150
|
case NodeTypes.GROUP:
|
142
|
-
return this.visit(left, parameters, true)
|
143
151
|
case NodeTypes.STAR:
|
144
|
-
return this.visit(left, parameters, true)
|
145
|
-
case NodeTypes.CAT:
|
146
|
-
var leftPart = this.visit(left, parameters, optional),
|
147
|
-
rightPart = this.visit(right, parameters, optional);
|
148
|
-
|
149
|
-
if (optional && ! (leftPart && rightPart))
|
150
|
-
return '';
|
151
|
-
|
152
|
-
return leftPart + rightPart;
|
152
|
+
return this.visit(left, parameters, true);
|
153
153
|
case NodeTypes.LITERAL:
|
154
|
-
return left;
|
155
154
|
case NodeTypes.SLASH:
|
156
|
-
return left;
|
157
155
|
case NodeTypes.DOT:
|
158
156
|
return left;
|
157
|
+
case NodeTypes.CAT:
|
158
|
+
left_part = this.visit(left, parameters, optional);
|
159
|
+
right_part = this.visit(right, parameters, optional);
|
160
|
+
if (optional && !(left_part && right_part)) {
|
161
|
+
return "";
|
162
|
+
}
|
163
|
+
return "" + left_part + right_part;
|
159
164
|
case NodeTypes.SYMBOL:
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
delete parameters[left];
|
165
|
+
value = parameters[left];
|
166
|
+
if (value != null) {
|
167
|
+
parameters[left] = null;
|
164
168
|
return this.path_identifier(value);
|
165
169
|
}
|
166
|
-
|
167
170
|
if (optional) {
|
168
|
-
return
|
171
|
+
return "";
|
169
172
|
} else {
|
170
173
|
throw new ParameterMissing("Route parameter missing: " + left);
|
171
174
|
}
|
172
|
-
|
173
|
-
* I don't know what is this node type
|
174
|
-
* Please send your PR if you do
|
175
|
-
*/
|
176
|
-
//case NodeTypes.OR:
|
175
|
+
break;
|
177
176
|
default:
|
178
177
|
throw new Error("Unknown Rails node type");
|
179
178
|
}
|
180
179
|
},
|
180
|
+
get_prefix: function() {
|
181
|
+
var prefix;
|
181
182
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
if( prefix !== "" ){
|
186
|
-
prefix = prefix.match('\/$') ? prefix : ( prefix + '/');
|
183
|
+
prefix = defaults.prefix;
|
184
|
+
if (prefix !== "") {
|
185
|
+
prefix = (prefix.match("/$") ? prefix : "" + prefix + "/");
|
187
186
|
}
|
188
|
-
|
189
187
|
return prefix;
|
190
188
|
},
|
189
|
+
namespace: function(root, namespaceString) {
|
190
|
+
var current, parts;
|
191
191
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
192
|
+
parts = (namespaceString ? namespaceString.split(".") : []);
|
193
|
+
if (!parts.length) {
|
194
|
+
return;
|
195
|
+
}
|
196
|
+
current = parts.shift();
|
197
|
+
root[current] = root[current] || {};
|
198
|
+
return Utils.namespace(root[current], parts.join("."));
|
199
199
|
}
|
200
200
|
};
|
201
201
|
|
202
|
-
Utils.namespace(window,
|
202
|
+
Utils.namespace(window, "NAMESPACE");
|
203
|
+
|
203
204
|
window.NAMESPACE = ROUTES;
|
205
|
+
|
204
206
|
window.NAMESPACE.options = defaults;
|
205
|
-
|
207
|
+
|
208
|
+
}).call(this);
|