js-routes 0.6.0 → 0.6.1
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.
- data/Readme.md +11 -3
- data/VERSION +1 -1
- data/js-routes.gemspec +2 -2
- data/lib/routes.js +19 -3
- data/spec/js_routes_spec.rb +26 -8
- data/spec/spec_helper.rb +7 -0
- metadata +4 -4
data/Readme.md
CHANGED
@@ -7,7 +7,7 @@ Generates javascript file that defines all Rails named routes as javascript help
|
|
7
7
|
Your Rails Gemfile:
|
8
8
|
|
9
9
|
``` ruby
|
10
|
-
gem "js-routes"
|
10
|
+
gem "js-routes", :require => 'js_routes'
|
11
11
|
```
|
12
12
|
|
13
13
|
Your application initializer, like `config/initializers/jsroutes.rb`:
|
@@ -72,9 +72,17 @@ In order to make routes helpers available globally:
|
|
72
72
|
jQuery.extend(window, Routes)
|
73
73
|
```
|
74
74
|
|
75
|
-
###
|
75
|
+
### What about security?
|
76
76
|
|
77
|
-
|
77
|
+
js-routes itself do not have security holes. It makes URLs
|
78
|
+
without access protection more reachable by potential attacker.
|
79
|
+
In order to prevent this use `:exclude` option for sensitive urls like `/admin_/`
|
80
|
+
|
81
|
+
|
82
|
+
### Advantages over alternatives
|
83
|
+
|
84
|
+
There are some alternatives available. Most of them has only basic feature and don't reach the level of quality I accept.
|
85
|
+
Advantages of this one are:
|
78
86
|
|
79
87
|
* Rails3 support
|
80
88
|
* Rich options set
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.1
|
data/js-routes.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{js-routes}
|
8
|
-
s.version = "0.6.
|
8
|
+
s.version = "0.6.1"
|
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"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-09-12}
|
13
13
|
s.description = %q{Generates javascript file that defines all Rails named routes as javascript helpers}
|
14
14
|
s.email = %q{agresso@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/routes.js
CHANGED
@@ -17,7 +17,7 @@
|
|
17
17
|
},
|
18
18
|
|
19
19
|
clean_path: function(path) {
|
20
|
-
return path.replace(/\.$/m, '').replace(/\/$/m, '');
|
20
|
+
return path.replace(/\/+/g, "/").replace(/[\)\(]/g, "").replace(/\.$/m, '').replace(/\/$/m, '');
|
21
21
|
},
|
22
22
|
|
23
23
|
extract_format: function(options) {
|
@@ -50,13 +50,29 @@
|
|
50
50
|
result = "";
|
51
51
|
var opts = Utils.extract_options(number_of_params, args);
|
52
52
|
for (var i=0; i < parts.length; i++) {
|
53
|
+
value = args.shift();
|
53
54
|
part = parts[i];
|
54
|
-
|
55
|
-
|
55
|
+
if (Utils.specified(value)) {
|
56
|
+
result += part;
|
57
|
+
result += Utils.path_identifier(value);
|
58
|
+
} else if (!Utils.optional_part(part)) {
|
59
|
+
//TODO: make it strict
|
60
|
+
//throw new Error("Can not build path: required parameter is null or undefined.");
|
61
|
+
result += part;
|
62
|
+
}
|
56
63
|
}
|
57
64
|
var format = Utils.extract_format(opts);
|
58
65
|
return Utils.clean_path(result + format) + Utils.serialize(opts);
|
66
|
+
},
|
67
|
+
|
68
|
+
specified: function(value) {
|
69
|
+
return !(value === undefined || value === null);
|
70
|
+
},
|
71
|
+
|
72
|
+
optional_part: function(part) {
|
73
|
+
return part.match(/\(/);
|
59
74
|
}
|
75
|
+
|
60
76
|
};
|
61
77
|
|
62
78
|
window.NAMESPACE = ROUTES;
|
data/spec/js_routes_spec.rb
CHANGED
@@ -38,10 +38,7 @@ describe JsRoutes do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should support routes with reserved javascript words as parameters" do
|
41
|
-
|
42
|
-
#because the parameter name is return_id
|
43
|
-
#need to find the real way to test
|
44
|
-
evaljs("Routes.return_path(1)").should == "/returns/1"
|
41
|
+
evaljs("Routes.object_path(1, 2)").should == "/returns/1/objects/2"
|
45
42
|
end
|
46
43
|
|
47
44
|
context "when exclude is specified" do
|
@@ -100,23 +97,44 @@ describe JsRoutes do
|
|
100
97
|
it "should use this name space for routing" do
|
101
98
|
evaljs("PHM.Routes.inbox_path").should_not be_nil
|
102
99
|
end
|
103
|
-
|
104
100
|
end
|
105
101
|
|
106
102
|
context "when arguments are objects" do
|
107
|
-
it "should use id property of the object" do
|
103
|
+
it "should use id property of the object in path" do
|
108
104
|
evaljs("Routes.inbox_path({id: 1})").should == "/inboxes/1"
|
109
105
|
end
|
110
106
|
|
111
|
-
it "should
|
107
|
+
it "should prefer to_param property over id property" do
|
112
108
|
evaljs("Routes.inbox_path({id: 1, to_param: 'my'})").should == "/inboxes/my"
|
113
109
|
end
|
114
110
|
|
115
|
-
it "should support
|
111
|
+
it "should support options argument" do
|
116
112
|
evaljs("Routes.inbox_message_path({id:1, to_param: 'my'}, {id:2}, {custom: true, format: 'json'})").should == "/inboxes/my/messages/2.json?custom=true"
|
117
113
|
end
|
118
114
|
end
|
119
115
|
|
116
|
+
context "using optional path fragments" do
|
117
|
+
context "but not including them" do
|
118
|
+
it "should not include the optional parts" do
|
119
|
+
evaljs("Routes.things_path()").should == "/things"
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should treat undefined as non-given optional part" do
|
123
|
+
evaljs("Routes.thing_path(undefined, 5)").should == "/things/5"
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should treat null as non-given optional part" do
|
127
|
+
evaljs("Routes.thing_path(null, 5)").should == "/things/5"
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context "and including them" do
|
132
|
+
it "should include the optional parts" do
|
133
|
+
evaljs("Routes.things_path(5)").should == "/optional/5/things"
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
120
138
|
describe "generated js" do
|
121
139
|
subject { JsRoutes.generate }
|
122
140
|
it "should have correct function without arguments signature" do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: js-routes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 5
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 0.6.
|
9
|
+
- 1
|
10
|
+
version: 0.6.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bogdan Gusiev
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-09-12 00:00:00 +03:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|