crossroadsjs-rails 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.rspec +3 -0
- data/Gemfile +3 -0
- data/LICENSE +9 -0
- data/README.md +57 -0
- data/Rakefile +5 -0
- data/crossroadsjs-rails.gemspec +28 -0
- data/lib/crossroadsjs-rails.rb +1 -0
- data/lib/crossroadsjs/rails.rb +10 -0
- data/lib/crossroadsjs/rails/engine.rb +6 -0
- data/lib/crossroadsjs/rails/railtie.rb +6 -0
- data/lib/crossroadsjs/rails/version.rb +6 -0
- data/lib/generators/crossroadsjs/install/install_generator.rb +17 -0
- data/spec/crossroadsjs/rails/version_spec.rb +6 -0
- data/spec/spec_helper.rb +3 -0
- data/vendor/assets/javascripts/crossroads.js +395 -0
- data/vendor/assets/javascripts/crossroads.min.js +15 -0
- metadata +83 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
/Gemfile.lock
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (C) 2012 Phil Ostler
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
|
+
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# Crossroads.js for Rails ![Build Status][travis_ci_build_status]
|
2
|
+
|
3
|
+
Provides Crossroads.js (0.7.1) for use with Rails 3
|
4
|
+
|
5
|
+
[RubyGems][ruby_gems] | [Ruby Toolbox][ruby_toolbox] | [GitHub][github] | [Travis CI][travis_ci] | [RubyDoc][ruby_doc]
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
### JavaScript Dependencies
|
9
|
+
Crossroads.js depends upon [js-signals][jssignals_project_page] which must also be added to your application. Either...
|
10
|
+
|
11
|
+
* Use [jssignals-rails][jssignals_rails_github] gem to add js-signals to the asset pipeline
|
12
|
+
* Place a copy of signals.js (or signals.min.js) in one of the asset pipeline or public directories
|
13
|
+
|
14
|
+
### Rails 3.1+
|
15
|
+
To use Crossroads.js with your Rails 3.1+ application, add the following to your Gemfile
|
16
|
+
|
17
|
+
```
|
18
|
+
gem "crossroadsjs-rails"
|
19
|
+
```
|
20
|
+
Run ```bundle install``` and Crossroads.js will be available for you to use via the asset pipeline. Add the following line into your ```app/assets/javascripts/application.js``` file...
|
21
|
+
|
22
|
+
```
|
23
|
+
//= require crossroads
|
24
|
+
```
|
25
|
+
...or for the minified version in development
|
26
|
+
|
27
|
+
```
|
28
|
+
//= require crossroads.min
|
29
|
+
```
|
30
|
+
Crossroads.js is now installed. Woop!
|
31
|
+
|
32
|
+
### Rails 3.0
|
33
|
+
To use Crossroads.js with your Rails 3.0 application, add the following to your Gemfile
|
34
|
+
|
35
|
+
```
|
36
|
+
gem "crossroadsjs-rails"
|
37
|
+
```
|
38
|
+
Run ```bundle install``` followed by the install generator
|
39
|
+
|
40
|
+
```
|
41
|
+
rails generate crossroadsjs:install
|
42
|
+
```
|
43
|
+
Crossroads.js is now installed. Woop!
|
44
|
+
|
45
|
+
##Crossroads.js Resources
|
46
|
+
[Project Page][crossroadsjs_project_page] | [GitHub][crossroadsjs_github]
|
47
|
+
|
48
|
+
[github]: http://github.com/philostler/crossroadsjs-rails
|
49
|
+
[ruby_doc]: http://rubydoc.info/github/philostler/crossroadsjs-rails/master/frames
|
50
|
+
[ruby_gems]: http://rubygems.org/gems/crossroadsjs-rails
|
51
|
+
[travis_ci]: http://travis-ci.org/philostler/crossroadsjs-rails
|
52
|
+
[travis_ci_build_status]: https://secure.travis-ci.org/philostler/crossroadsjs-rails.png
|
53
|
+
[ruby_toolbox]: http://www.ruby-toolbox.com/projects/crossroadsjs-rails
|
54
|
+
[jssignals_project_page]: http://millermedeiros.github.com/js-signals
|
55
|
+
[jssignals_rails_github]: http://github.com/philostler/jssignals-rails
|
56
|
+
[crossroadsjs_project_page]: http://millermedeiros.github.com/crossroads.js
|
57
|
+
[crossroadsjs_github]: http://github.com/millermedeiros/crossroads.js
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path("../lib/crossroadsjs/rails/version", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "crossroadsjs-rails"
|
6
|
+
s.version = Crossroadsjs::Rails::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.author = "Phil Ostler"
|
9
|
+
s.email = "philostler@gmail.com"
|
10
|
+
s.homepage = "http://github.com/philostler/crossroadsjs-rails"
|
11
|
+
s.summary = %q{Crossroads.js for Rails}
|
12
|
+
s.description = %q{Provides Crossroads.js for use with Rails 3}
|
13
|
+
|
14
|
+
s.add_dependency "railties", "~> 3.0"
|
15
|
+
|
16
|
+
s.add_development_dependency "rspec", "~> 2.0"
|
17
|
+
|
18
|
+
s.files = Dir[".gitignore"] +
|
19
|
+
Dir[".rspec"] +
|
20
|
+
Dir["Gemfile"] +
|
21
|
+
Dir["crossroadsjs-rails.gemspec"] +
|
22
|
+
Dir["LICENSE"] +
|
23
|
+
Dir["Rakefile"] +
|
24
|
+
Dir["README.md"] +
|
25
|
+
Dir["**/*.js"] +
|
26
|
+
Dir["**/*.rb"]
|
27
|
+
s.require_paths = ["lib"]
|
28
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "crossroadsjs/rails"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "rails"
|
2
|
+
|
3
|
+
module Crossroadsjs
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
desc "This generator installs Crossroads.js (#{Crossroadsjs::Rails::CROSSROADSJS_VERSION})"
|
7
|
+
source_root File.expand_path "../../../../../vendor/assets/javascripts", __FILE__
|
8
|
+
|
9
|
+
def copy_crossroadsjs
|
10
|
+
say_status "copying", "Crossroads.js (#{Crossroadsjs::Rails::CROSSROADSJS_VERSION})", :green
|
11
|
+
|
12
|
+
copy_file "crossroads.js", "public/javascripts/crossroads.js"
|
13
|
+
copy_file "crossroads.min.js", "public/javascripts/crossroads.min.js"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end if ::Rails.version < 3.1
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,395 @@
|
|
1
|
+
/** @license
|
2
|
+
* Crossroads.js <http://millermedeiros.github.com/crossroads.js>
|
3
|
+
* Released under the MIT license
|
4
|
+
* Author: Miller Medeiros
|
5
|
+
* Version: 0.7.1 - Build: 93 (2012/02/02 09:29 AM)
|
6
|
+
*/
|
7
|
+
|
8
|
+
(function (define) {
|
9
|
+
define(['signals'], function (signals) {
|
10
|
+
|
11
|
+
var crossroads,
|
12
|
+
patternLexer,
|
13
|
+
UNDEF;
|
14
|
+
|
15
|
+
// Helpers -----------
|
16
|
+
//====================
|
17
|
+
|
18
|
+
function arrayIndexOf(arr, val) {
|
19
|
+
if (arr.indexOf) {
|
20
|
+
return arr.indexOf(val);
|
21
|
+
} else {
|
22
|
+
//Array.indexOf doesn't work on IE 6-7
|
23
|
+
var n = arr.length;
|
24
|
+
while (n--) {
|
25
|
+
if (arr[n] === val) {
|
26
|
+
return n;
|
27
|
+
}
|
28
|
+
}
|
29
|
+
return -1;
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
function isKind(val, kind) {
|
34
|
+
return '[object '+ kind +']' === Object.prototype.toString.call(val);
|
35
|
+
}
|
36
|
+
|
37
|
+
function isRegExp(val) {
|
38
|
+
return isKind(val, 'RegExp');
|
39
|
+
}
|
40
|
+
|
41
|
+
function isArray(val) {
|
42
|
+
return isKind(val, 'Array');
|
43
|
+
}
|
44
|
+
|
45
|
+
function isFunction(val) {
|
46
|
+
return isKind(val, 'Function');
|
47
|
+
}
|
48
|
+
|
49
|
+
//borrowed from AMD-utils
|
50
|
+
function typecastValue(val) {
|
51
|
+
var r;
|
52
|
+
if (val === null || val === 'null') {
|
53
|
+
r = null;
|
54
|
+
} else if (val === 'true') {
|
55
|
+
r = true;
|
56
|
+
} else if (val === 'false') {
|
57
|
+
r = false;
|
58
|
+
} else if (val === UNDEF || val === 'undefined') {
|
59
|
+
r = UNDEF;
|
60
|
+
} else if (val === '' || isNaN(val)) {
|
61
|
+
//isNaN('') returns false
|
62
|
+
r = val;
|
63
|
+
} else {
|
64
|
+
//parseFloat(null || '') returns NaN
|
65
|
+
r = parseFloat(val);
|
66
|
+
}
|
67
|
+
return r;
|
68
|
+
}
|
69
|
+
|
70
|
+
function typecastArrayValues(values) {
|
71
|
+
var n = values.length,
|
72
|
+
result = [];
|
73
|
+
while (n--) {
|
74
|
+
result[n] = typecastValue(values[n]);
|
75
|
+
}
|
76
|
+
return result;
|
77
|
+
}
|
78
|
+
|
79
|
+
|
80
|
+
// Crossroads --------
|
81
|
+
//====================
|
82
|
+
|
83
|
+
/**
|
84
|
+
* @constructor
|
85
|
+
*/
|
86
|
+
function Crossroads() {
|
87
|
+
this._routes = [];
|
88
|
+
this.bypassed = new signals.Signal();
|
89
|
+
this.routed = new signals.Signal();
|
90
|
+
}
|
91
|
+
|
92
|
+
Crossroads.prototype = {
|
93
|
+
|
94
|
+
normalizeFn : null,
|
95
|
+
|
96
|
+
create : function () {
|
97
|
+
return new Crossroads();
|
98
|
+
},
|
99
|
+
|
100
|
+
shouldTypecast : false,
|
101
|
+
|
102
|
+
addRoute : function (pattern, callback, priority) {
|
103
|
+
var route = new Route(pattern, callback, priority, this);
|
104
|
+
this._sortedInsert(route);
|
105
|
+
return route;
|
106
|
+
},
|
107
|
+
|
108
|
+
removeRoute : function (route) {
|
109
|
+
var i = arrayIndexOf(this._routes, route);
|
110
|
+
if (i !== -1) {
|
111
|
+
this._routes.splice(i, 1);
|
112
|
+
}
|
113
|
+
route._destroy();
|
114
|
+
},
|
115
|
+
|
116
|
+
removeAllRoutes : function () {
|
117
|
+
var n = this.getNumRoutes();
|
118
|
+
while (n--) {
|
119
|
+
this._routes[n]._destroy();
|
120
|
+
}
|
121
|
+
this._routes.length = 0;
|
122
|
+
},
|
123
|
+
|
124
|
+
parse : function (request) {
|
125
|
+
request = request || '';
|
126
|
+
|
127
|
+
var routes = this._getMatchedRoutes(request),
|
128
|
+
i = 0,
|
129
|
+
n = routes.length,
|
130
|
+
cur;
|
131
|
+
|
132
|
+
if (n) {
|
133
|
+
//shold be incremental loop, execute routes in order
|
134
|
+
while (i < n) {
|
135
|
+
cur = routes[i];
|
136
|
+
cur.route.matched.dispatch.apply(cur.route.matched, cur.params);
|
137
|
+
cur.isFirst = !i;
|
138
|
+
this.routed.dispatch(request, cur);
|
139
|
+
i += 1;
|
140
|
+
}
|
141
|
+
} else {
|
142
|
+
this.bypassed.dispatch(request);
|
143
|
+
}
|
144
|
+
},
|
145
|
+
|
146
|
+
getNumRoutes : function () {
|
147
|
+
return this._routes.length;
|
148
|
+
},
|
149
|
+
|
150
|
+
_sortedInsert : function (route) {
|
151
|
+
//simplified insertion sort
|
152
|
+
var routes = this._routes,
|
153
|
+
n = routes.length;
|
154
|
+
do { --n; } while (routes[n] && route._priority <= routes[n]._priority);
|
155
|
+
routes.splice(n+1, 0, route);
|
156
|
+
},
|
157
|
+
|
158
|
+
_getMatchedRoutes : function (request) {
|
159
|
+
var res = [],
|
160
|
+
routes = this._routes,
|
161
|
+
n = routes.length,
|
162
|
+
route;
|
163
|
+
//should be decrement loop since higher priorities are added at the end of array
|
164
|
+
while (route = routes[--n]) {
|
165
|
+
if ((!res.length || route.greedy) && route.match(request)) {
|
166
|
+
res.push({
|
167
|
+
route : route,
|
168
|
+
params : route._getParamsArray(request)
|
169
|
+
});
|
170
|
+
}
|
171
|
+
}
|
172
|
+
return res;
|
173
|
+
},
|
174
|
+
|
175
|
+
toString : function () {
|
176
|
+
return '[crossroads numRoutes:'+ this.getNumRoutes() +']';
|
177
|
+
}
|
178
|
+
};
|
179
|
+
|
180
|
+
//"static" instance
|
181
|
+
crossroads = new Crossroads();
|
182
|
+
crossroads.VERSION = '0.7.1';
|
183
|
+
|
184
|
+
|
185
|
+
|
186
|
+
// Route --------------
|
187
|
+
//=====================
|
188
|
+
|
189
|
+
/**
|
190
|
+
* @constructor
|
191
|
+
*/
|
192
|
+
function Route(pattern, callback, priority, router) {
|
193
|
+
var isRegexPattern = isRegExp(pattern);
|
194
|
+
this._router = router;
|
195
|
+
this._pattern = pattern;
|
196
|
+
this._paramsIds = isRegexPattern? null : patternLexer.getParamIds(this._pattern);
|
197
|
+
this._optionalParamsIds = isRegexPattern? null : patternLexer.getOptionalParamsIds(this._pattern);
|
198
|
+
this._matchRegexp = isRegexPattern? pattern : patternLexer.compilePattern(pattern);
|
199
|
+
this.matched = new signals.Signal();
|
200
|
+
if (callback) {
|
201
|
+
this.matched.add(callback);
|
202
|
+
}
|
203
|
+
this._priority = priority || 0;
|
204
|
+
}
|
205
|
+
|
206
|
+
Route.prototype = {
|
207
|
+
|
208
|
+
greedy : false,
|
209
|
+
|
210
|
+
rules : void(0),
|
211
|
+
|
212
|
+
match : function (request) {
|
213
|
+
return this._matchRegexp.test(request) && this._validateParams(request); //validate params even if regexp because of `request_` rule.
|
214
|
+
},
|
215
|
+
|
216
|
+
_validateParams : function (request) {
|
217
|
+
var rules = this.rules,
|
218
|
+
values = this._getParamsObject(request),
|
219
|
+
key;
|
220
|
+
for (key in rules) {
|
221
|
+
// normalize_ isn't a validation rule... (#39)
|
222
|
+
if(key !== 'normalize_' && rules.hasOwnProperty(key) && ! this._isValidParam(request, key, values)){
|
223
|
+
return false;
|
224
|
+
}
|
225
|
+
}
|
226
|
+
return true;
|
227
|
+
},
|
228
|
+
|
229
|
+
_isValidParam : function (request, prop, values) {
|
230
|
+
var validationRule = this.rules[prop],
|
231
|
+
val = values[prop],
|
232
|
+
isValid = false;
|
233
|
+
|
234
|
+
if (val == null && this._optionalParamsIds && arrayIndexOf(this._optionalParamsIds, prop) !== -1) {
|
235
|
+
isValid = true;
|
236
|
+
}
|
237
|
+
else if (isRegExp(validationRule)) {
|
238
|
+
isValid = validationRule.test(val);
|
239
|
+
}
|
240
|
+
else if (isArray(validationRule)) {
|
241
|
+
isValid = arrayIndexOf(validationRule, val) !== -1;
|
242
|
+
}
|
243
|
+
else if (isFunction(validationRule)) {
|
244
|
+
isValid = validationRule(val, request, values);
|
245
|
+
}
|
246
|
+
|
247
|
+
return isValid; //fail silently if validationRule is from an unsupported type
|
248
|
+
},
|
249
|
+
|
250
|
+
_getParamsObject : function (request) {
|
251
|
+
var shouldTypecast = this._router.shouldTypecast,
|
252
|
+
values = patternLexer.getParamValues(request, this._matchRegexp, shouldTypecast),
|
253
|
+
o = {},
|
254
|
+
n = values.length;
|
255
|
+
while (n--) {
|
256
|
+
o[n] = values[n]; //for RegExp pattern and also alias to normal paths
|
257
|
+
if (this._paramsIds) {
|
258
|
+
o[this._paramsIds[n]] = values[n];
|
259
|
+
}
|
260
|
+
}
|
261
|
+
o.request_ = shouldTypecast? typecastValue(request) : request;
|
262
|
+
o.vals_ = values;
|
263
|
+
return o;
|
264
|
+
},
|
265
|
+
|
266
|
+
_getParamsArray : function (request) {
|
267
|
+
var norm = this.rules? this.rules.normalize_ : null,
|
268
|
+
params;
|
269
|
+
norm = norm || this._router.normalizeFn; // default normalize
|
270
|
+
if (norm && isFunction(norm)) {
|
271
|
+
params = norm(request, this._getParamsObject(request));
|
272
|
+
} else {
|
273
|
+
params = patternLexer.getParamValues(request, this._matchRegexp, this._router.shouldTypecast);
|
274
|
+
}
|
275
|
+
return params;
|
276
|
+
},
|
277
|
+
|
278
|
+
dispose : function () {
|
279
|
+
this._router.removeRoute(this);
|
280
|
+
},
|
281
|
+
|
282
|
+
_destroy : function () {
|
283
|
+
this.matched.dispose();
|
284
|
+
this.matched = this._pattern = this._matchRegexp = null;
|
285
|
+
},
|
286
|
+
|
287
|
+
toString : function () {
|
288
|
+
return '[Route pattern:"'+ this._pattern +'", numListeners:'+ this.matched.getNumListeners() +']';
|
289
|
+
}
|
290
|
+
|
291
|
+
};
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
// Pattern Lexer ------
|
296
|
+
//=====================
|
297
|
+
|
298
|
+
patternLexer = crossroads.patternLexer = (function () {
|
299
|
+
|
300
|
+
|
301
|
+
var ESCAPE_CHARS_REGEXP = /[\\.+*?\^$\[\](){}\/'#]/g, //match chars that should be escaped on string regexp
|
302
|
+
UNNECESSARY_SLASHES_REGEXP = /\/$/g, //trailing slash
|
303
|
+
OPTIONAL_SLASHES_REGEXP = /([:}]|\w(?=\/))\/?(:)/g, //slash between `::` or `}:` or `\w:`. $1 = before, $2 = after
|
304
|
+
REQUIRED_SLASHES_REGEXP = /([:}])\/?(\{)/g, //used to insert slash between `:{` and `}{`
|
305
|
+
|
306
|
+
REQUIRED_PARAMS_REGEXP = /\{([^}]+)\}/g, //match everything between `{ }`
|
307
|
+
OPTIONAL_PARAMS_REGEXP = /:([^:]+):/g, //match everything between `: :`
|
308
|
+
PARAMS_REGEXP = /(?:\{|:)([^}:]+)(?:\}|:)/g, //capture everything between `{ }` or `: :`
|
309
|
+
|
310
|
+
//used to save params during compile (avoid escaping things that
|
311
|
+
//shouldn't be escaped).
|
312
|
+
SAVE_REQUIRED_PARAMS = '__CR_RP__',
|
313
|
+
SAVE_OPTIONAL_PARAMS = '__CR_OP__',
|
314
|
+
SAVE_REQUIRED_SLASHES = '__CR_RS__',
|
315
|
+
SAVE_OPTIONAL_SLASHES = '__CR_OS__',
|
316
|
+
SAVED_REQUIRED_REGEXP = new RegExp(SAVE_REQUIRED_PARAMS, 'g'),
|
317
|
+
SAVED_OPTIONAL_REGEXP = new RegExp(SAVE_OPTIONAL_PARAMS, 'g'),
|
318
|
+
SAVED_OPTIONAL_SLASHES_REGEXP = new RegExp(SAVE_OPTIONAL_SLASHES, 'g'),
|
319
|
+
SAVED_REQUIRED_SLASHES_REGEXP = new RegExp(SAVE_REQUIRED_SLASHES, 'g');
|
320
|
+
|
321
|
+
|
322
|
+
function captureVals(regex, pattern) {
|
323
|
+
var vals = [], match;
|
324
|
+
while (match = regex.exec(pattern)) {
|
325
|
+
vals.push(match[1]);
|
326
|
+
}
|
327
|
+
return vals;
|
328
|
+
}
|
329
|
+
|
330
|
+
function getParamIds(pattern) {
|
331
|
+
return captureVals(PARAMS_REGEXP, pattern);
|
332
|
+
}
|
333
|
+
|
334
|
+
function getOptionalParamsIds(pattern) {
|
335
|
+
return captureVals(OPTIONAL_PARAMS_REGEXP, pattern);
|
336
|
+
}
|
337
|
+
|
338
|
+
function compilePattern(pattern) {
|
339
|
+
pattern = pattern || '';
|
340
|
+
if(pattern){
|
341
|
+
pattern = pattern.replace(UNNECESSARY_SLASHES_REGEXP, '');
|
342
|
+
pattern = tokenize(pattern);
|
343
|
+
pattern = pattern.replace(ESCAPE_CHARS_REGEXP, '\\$&');
|
344
|
+
pattern = untokenize(pattern);
|
345
|
+
}
|
346
|
+
return new RegExp('^'+ pattern + '/?$'); //trailing slash is optional
|
347
|
+
}
|
348
|
+
|
349
|
+
function tokenize(pattern) {
|
350
|
+
//save chars that shouldn't be escaped
|
351
|
+
pattern = pattern.replace(OPTIONAL_SLASHES_REGEXP, '$1'+ SAVE_OPTIONAL_SLASHES +'$2');
|
352
|
+
pattern = pattern.replace(REQUIRED_SLASHES_REGEXP, '$1'+ SAVE_REQUIRED_SLASHES +'$2');
|
353
|
+
pattern = pattern.replace(OPTIONAL_PARAMS_REGEXP, SAVE_OPTIONAL_PARAMS);
|
354
|
+
return pattern.replace(REQUIRED_PARAMS_REGEXP, SAVE_REQUIRED_PARAMS);
|
355
|
+
}
|
356
|
+
|
357
|
+
function untokenize(pattern) {
|
358
|
+
pattern = pattern.replace(SAVED_OPTIONAL_SLASHES_REGEXP, '\\/?');
|
359
|
+
pattern = pattern.replace(SAVED_REQUIRED_SLASHES_REGEXP, '\\/');
|
360
|
+
pattern = pattern.replace(SAVED_OPTIONAL_REGEXP, '([^\\/]+)?\/?');
|
361
|
+
return pattern.replace(SAVED_REQUIRED_REGEXP, '([^\\/]+)');
|
362
|
+
}
|
363
|
+
|
364
|
+
function getParamValues(request, regexp, shouldTypecast) {
|
365
|
+
var vals = regexp.exec(request);
|
366
|
+
if (vals) {
|
367
|
+
vals.shift();
|
368
|
+
if (shouldTypecast) {
|
369
|
+
vals = typecastArrayValues(vals);
|
370
|
+
}
|
371
|
+
}
|
372
|
+
return vals;
|
373
|
+
}
|
374
|
+
|
375
|
+
//API
|
376
|
+
return {
|
377
|
+
getParamIds : getParamIds,
|
378
|
+
getOptionalParamsIds : getOptionalParamsIds,
|
379
|
+
getParamValues : getParamValues,
|
380
|
+
compilePattern : compilePattern
|
381
|
+
};
|
382
|
+
|
383
|
+
}());
|
384
|
+
|
385
|
+
|
386
|
+
return crossroads;
|
387
|
+
});
|
388
|
+
}(typeof define === 'function' && define.amd ? define : function (deps, factory) {
|
389
|
+
if (typeof module !== 'undefined' && module.exports) { //Node
|
390
|
+
module.exports = factory(require(deps[0]));
|
391
|
+
} else {
|
392
|
+
/*jshint sub:true */
|
393
|
+
window['crossroads'] = factory(window[deps[0]]);
|
394
|
+
}
|
395
|
+
}));
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
|
3
|
+
Crossroads.js <http://millermedeiros.github.com/crossroads.js>
|
4
|
+
Released under the MIT license
|
5
|
+
Author: Miller Medeiros
|
6
|
+
Version: 0.7.1 - Build: 93 (2012/02/02 09:29 AM)
|
7
|
+
*/
|
8
|
+
(function(f){f(["signals"],function(g){function f(a,b){if(a.indexOf)return a.indexOf(b);else{for(var c=a.length;c--;)if(a[c]===b)return c;return-1}}function i(a,b){return"[object "+b+"]"===Object.prototype.toString.call(a)}function n(a){return a===null||a==="null"?null:a==="true"?!0:a==="false"?!1:a===m||a==="undefined"?m:a===""||isNaN(a)?a:parseFloat(a)}function k(){this._routes=[];this.bypassed=new g.Signal;this.routed=new g.Signal}function o(a,b,c,e){var d=i(a,"RegExp");this._router=e;this._pattern=
|
9
|
+
a;this._paramsIds=d?null:h.getParamIds(this._pattern);this._optionalParamsIds=d?null:h.getOptionalParamsIds(this._pattern);this._matchRegexp=d?a:h.compilePattern(a);this.matched=new g.Signal;b&&this.matched.add(b);this._priority=c||0}var j,h,m;k.prototype={normalizeFn:null,create:function(){return new k},shouldTypecast:!1,addRoute:function(a,b,c){a=new o(a,b,c,this);this._sortedInsert(a);return a},removeRoute:function(a){var b=f(this._routes,a);b!==-1&&this._routes.splice(b,1);a._destroy()},removeAllRoutes:function(){for(var a=
|
10
|
+
this.getNumRoutes();a--;)this._routes[a]._destroy();this._routes.length=0},parse:function(a){var a=a||"",b=this._getMatchedRoutes(a),c=0,e=b.length,d;if(e)for(;c<e;)d=b[c],d.route.matched.dispatch.apply(d.route.matched,d.params),d.isFirst=!c,this.routed.dispatch(a,d),c+=1;else this.bypassed.dispatch(a)},getNumRoutes:function(){return this._routes.length},_sortedInsert:function(a){var b=this._routes,c=b.length;do--c;while(b[c]&&a._priority<=b[c]._priority);b.splice(c+1,0,a)},_getMatchedRoutes:function(a){for(var b=
|
11
|
+
[],c=this._routes,e=c.length,d;d=c[--e];)(!b.length||d.greedy)&&d.match(a)&&b.push({route:d,params:d._getParamsArray(a)});return b},toString:function(){return"[crossroads numRoutes:"+this.getNumRoutes()+"]"}};j=new k;j.VERSION="0.7.1";o.prototype={greedy:!1,rules:void 0,match:function(a){return this._matchRegexp.test(a)&&this._validateParams(a)},_validateParams:function(a){var b=this.rules,c=this._getParamsObject(a),e;for(e in b)if(e!=="normalize_"&&b.hasOwnProperty(e)&&!this._isValidParam(a,e,c))return!1;
|
12
|
+
return!0},_isValidParam:function(a,b,c){var e=this.rules[b],d=c[b],l=!1;d==null&&this._optionalParamsIds&&f(this._optionalParamsIds,b)!==-1?l=!0:i(e,"RegExp")?l=e.test(d):i(e,"Array")?l=f(e,d)!==-1:i(e,"Function")&&(l=e(d,a,c));return l},_getParamsObject:function(a){for(var b=this._router.shouldTypecast,c=h.getParamValues(a,this._matchRegexp,b),e={},d=c.length;d--;)e[d]=c[d],this._paramsIds&&(e[this._paramsIds[d]]=c[d]);e.request_=b?n(a):a;e.vals_=c;return e},_getParamsArray:function(a){var b=this.rules?
|
13
|
+
this.rules.normalize_:null;return(b=b||this._router.normalizeFn)&&i(b,"Function")?b(a,this._getParamsObject(a)):h.getParamValues(a,this._matchRegexp,this._router.shouldTypecast)},dispose:function(){this._router.removeRoute(this)},_destroy:function(){this.matched.dispose();this.matched=this._pattern=this._matchRegexp=null},toString:function(){return'[Route pattern:"'+this._pattern+'", numListeners:'+this.matched.getNumListeners()+"]"}};h=j.patternLexer=function(){function a(a,b){for(var c=[],d;d=a.exec(b);)c.push(d[1]);
|
14
|
+
return c}var b=/[\\.+*?\^$\[\](){}\/'#]/g,c=/\/$/g,e=/([:}]|\w(?=\/))\/?(:)/g,d=/([:}])\/?(\{)/g,f=/\{([^}]+)\}/g,g=/:([^:]+):/g,h=/(?:\{|:)([^}:]+)(?:\}|:)/g,i=RegExp("__CR_RP__","g"),j=RegExp("__CR_OP__","g"),k=RegExp("__CR_OS__","g"),m=RegExp("__CR_RS__","g");return{getParamIds:function(b){return a(h,b)},getOptionalParamsIds:function(b){return a(g,b)},getParamValues:function(a,b,c){if(a=b.exec(a))if(a.shift(),c){c=a;a=c.length;for(b=[];a--;)b[a]=n(c[a]);a=b}return a},compilePattern:function(a){if(a=
|
15
|
+
a||"")a=a.replace(c,""),a=a.replace(e,"$1__CR_OS__$2"),a=a.replace(d,"$1__CR_RS__$2"),a=a.replace(g,"__CR_OP__"),a=a.replace(f,"__CR_RP__"),a=a.replace(b,"\\$&"),a=a.replace(k,"\\/?"),a=a.replace(m,"\\/"),a=a.replace(j,"([^\\/]+)?/?"),a=a.replace(i,"([^\\/]+)");return RegExp("^"+a+"/?$")}}}();return j})})(typeof define==="function"&&define.amd?define:function(f,g){typeof module!=="undefined"&&module.exports?module.exports=g(require(f[0])):window.crossroads=g(window[f[0]])});
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: crossroadsjs-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Phil Ostler
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: railties
|
16
|
+
requirement: &22510320 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *22510320
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &22509852 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *22509852
|
36
|
+
description: Provides Crossroads.js for use with Rails 3
|
37
|
+
email: philostler@gmail.com
|
38
|
+
executables: []
|
39
|
+
extensions: []
|
40
|
+
extra_rdoc_files: []
|
41
|
+
files:
|
42
|
+
- .gitignore
|
43
|
+
- .rspec
|
44
|
+
- Gemfile
|
45
|
+
- crossroadsjs-rails.gemspec
|
46
|
+
- LICENSE
|
47
|
+
- Rakefile
|
48
|
+
- README.md
|
49
|
+
- vendor/assets/javascripts/crossroads.js
|
50
|
+
- vendor/assets/javascripts/crossroads.min.js
|
51
|
+
- lib/crossroadsjs/rails/engine.rb
|
52
|
+
- lib/crossroadsjs/rails/railtie.rb
|
53
|
+
- lib/crossroadsjs/rails/version.rb
|
54
|
+
- lib/crossroadsjs/rails.rb
|
55
|
+
- lib/crossroadsjs-rails.rb
|
56
|
+
- lib/generators/crossroadsjs/install/install_generator.rb
|
57
|
+
- spec/crossroadsjs/rails/version_spec.rb
|
58
|
+
- spec/spec_helper.rb
|
59
|
+
homepage: http://github.com/philostler/crossroadsjs-rails
|
60
|
+
licenses: []
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 1.8.15
|
80
|
+
signing_key:
|
81
|
+
specification_version: 3
|
82
|
+
summary: Crossroads.js for Rails
|
83
|
+
test_files: []
|