Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

make it work on the server, too

  • Loading branch information...
commit 6d71b2de3cc3fc75edf232999efa92be80802053 1 parent d63e725
@amccollum authored
View
3  Cakefile
@@ -1,9 +1,6 @@
fs = require('fs')
-sys = require('sys')
{spawn, exec} = require('child_process')
-package = JSON.parse(fs.readFileSync('package.json', 'utf8'))
-
execCmds = (cmds) ->
exec cmds.join(' && '), (err, stdout, stderr) ->
output = (stdout + stderr).trim()
View
8 lib/ender.js
@@ -1,5 +1,3 @@
-(function($) {
- return $.ender({
- route: require('route')
- });
-})(ender);
+// Generated by CoffeeScript 1.3.1
+
+
View
52 lib/index.js
@@ -0,0 +1,52 @@
+// Generated by CoffeeScript 1.3.1
+var route;
+
+route = typeof exports !== "undefined" && exports !== null ? exports : (this['route'] = {});
+
+route.Router = (function() {
+
+ Router.name = 'Router';
+
+ Router.prototype._transformations = [[/([?=,\/])/g, '\\$1'], [/:([\w\d]+)/g, '([^/]*)'], [/\*([\w\d]+)/g, '(.*?)']];
+
+ function Router() {
+ this.routes = [];
+ }
+
+ Router.prototype.add = function(routes) {
+ var expr, fn, pattern, replacement, transformer, _i, _len, _ref, _ref1;
+ for (expr in routes) {
+ fn = routes[expr];
+ pattern = expr;
+ _ref = this._transformations;
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ _ref1 = _ref[_i], transformer = _ref1[0], replacement = _ref1[1];
+ pattern = pattern.replace(transformer, replacement);
+ }
+ this.routes.push({
+ expr: expr,
+ pattern: new RegExp(pattern),
+ fn: fn
+ });
+ }
+ };
+
+ Router.prototype.run = function(path, context) {
+ var m, result, results, route, _i, _len, _ref;
+ results = [];
+ _ref = this.routes;
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ route = _ref[_i];
+ if ((m = route.pattern.exec(path))) {
+ result = route.fn.apply(context, m.slice(1));
+ if (result) {
+ results.push(result);
+ }
+ }
+ }
+ return results;
+ };
+
+ return Router;
+
+})();
View
61 lib/route.js
@@ -1,61 +0,0 @@
-(function(route) {
- var Route, _hash, _routes;
- _routes = [];
- _hash = null;
- route.init = function(run) {
- var onchange;
- onchange = function() {
- var hash;
- hash = $.hash();
- if (hash !== _hash) {
- _hash = hash;
- route.run(hash);
- }
- };
- $(window).bind('hashchange', onchange);
- if (run) {
- onchange();
- }
- };
- route.navigate = function(hash, run) {
- if (!run) {
- _hash = hash;
- }
- $.hash(hash);
- };
- route.run = function(hash) {
- var m, route, _i, _len;
- for (_i = 0, _len = _routes.length; _i < _len; _i++) {
- route = _routes[_i];
- if ((m = route.pattern.exec(hash))) {
- route.fn.apply(route, m.slice(1));
- }
- }
- };
- route.add = function(routes, fn) {
- var path;
- if (fn) {
- routes = {};
- routes[routes] = fn;
- }
- for (path in routes) {
- fn = routes[path];
- _routes.push(new Route(path, fn));
- }
- };
- return Route = (function() {
- Route.prototype._transformations = [[/:([\w\d]+)/g, '([^/]*)'], [/\*([\w\d]+)/g, '(.*?)']];
- function Route(path, fn) {
- var pattern, replacement, _i, _len, _ref, _ref2;
- this.path = path;
- this.fn = fn;
- _ref = this._transformations;
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
- _ref2 = _ref[_i], pattern = _ref2[0], replacement = _ref2[1];
- path = path.replace(pattern, replacement);
- }
- this.pattern = new RegExp("^" + path + "$");
- }
- return Route;
- })();
-})(typeof exports !== "undefined" && exports !== null ? exports : (this['route'] = {}));
View
2  package.json
@@ -8,7 +8,7 @@
"repositories": [{ "type": "git", "url": "https://github.com/amccollum/route.git" }],
"licenses": [{ "type": "MIT", "url": "http://opensource.org/licenses/mit-license.php" }],
- "main": "lib/route.js",
+ "main": "lib/index.js",
"ender": "lib/ender.js",
"directories": { "lib": "lib" },
View
7 src/ender.coffee
@@ -1,3 +1,4 @@
-(($) ->
- $.ender({ route: require('route') })
-)(ender)
+# (($) ->
+# route = require('route')
+#
+# )(ender)
View
42 src/index.coffee
@@ -0,0 +1,42 @@
+route = exports ? (@['route'] = {})
+
+class route.Router
+ _transformations: [
+ [ # Escape URL Special Characters
+ /([?=,\/])/g
+ '\\$1'
+ ],
+
+ [ # Named Parameters
+ /:([\w\d]+)/g
+ '([^/]*)'
+ ],
+
+ [ # Splat Parameters
+ /\*([\w\d]+)/g
+ '(.*?)'
+ ],
+ ]
+
+ constructor: ->
+ @routes = []
+
+ add: (routes) ->
+ for expr, fn of routes
+ pattern = expr
+ for [transformer, replacement] in @_transformations
+ pattern = pattern.replace(transformer, replacement)
+
+ @routes.push({ expr: expr, pattern: new RegExp(pattern), fn: fn })
+
+ return
+
+ run: (path, context) ->
+ results = []
+
+ for route in @routes
+ if (m = route.pattern.exec(path))
+ result = route.fn.apply(context, m.slice(1))
+ results.push(result) if result
+
+ return results
View
66 src/route.coffee
@@ -1,66 +0,0 @@
-((route) ->
- _routes = []
- _hash = null
-
- route.init = (run) ->
- onchange = () ->
- hash = $.hash()
- if hash != _hash
- _hash = hash
- route.run(hash)
-
- return
-
- $(window).bind 'hashchange', onchange
- onchange() if run
-
- return
-
- route.navigate = (hash, run) ->
- if not run
- _hash = hash
-
- $.hash(hash)
- return
-
- route.run = (hash) ->
- for route in _routes
- if (m = route.pattern.exec(hash))
- route.fn.apply(route, m.slice(1))
-
- return
-
- route.add = (routes, fn) ->
- if fn
- routes = {}
- routes[routes] = fn
-
- for path, fn of routes
- _routes.push(new Route(path, fn))
-
- return
-
- class Route
- _transformations: [
- [ # Named Parameters
- /:([\w\d]+)/g
- '([^/]*)'
- ],
-
- [ # Splat Parameters
- /\*([\w\d]+)/g
- '(.*?)'
- ],
- ]
-
- constructor: (path, fn) ->
- @path = path
- @fn = fn
-
- for [pattern, replacement] in @_transformations
- path = path.replace(pattern, replacement)
-
- @pattern = new RegExp("^#{path}$")
-
-
-)(exports ? (@['route'] = {}))
Please sign in to comment.
Something went wrong with that request. Please try again.