coffeescript-router 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Cakefile +122 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/LICENSE.txt +19 -0
- data/README.md +18 -0
- data/Rakefile +2 -0
- data/SpecRunner.html +25 -0
- data/coffeescript-router.gemspec +19 -0
- data/lib/CoffeeScript.png +0 -0
- data/lib/coffeescript-router/version.rb +5 -0
- data/lib/jasmine-1.0.2/MIT.LICENSE +20 -0
- data/lib/jasmine-1.0.2/jasmine-html.js +188 -0
- data/lib/jasmine-1.0.2/jasmine.css +166 -0
- data/lib/jasmine-1.0.2/jasmine.js +2421 -0
- data/node_modules/.bin/cake +7 -0
- data/node_modules/.bin/coffee +7 -0
- data/node_modules/.bin/uglifyjs +212 -0
- data/node_modules/coffee-script/.npmignore +11 -0
- data/node_modules/coffee-script/LICENSE +22 -0
- data/node_modules/coffee-script/README +48 -0
- data/node_modules/coffee-script/Rakefile +78 -0
- data/node_modules/coffee-script/bin/cake +7 -0
- data/node_modules/coffee-script/bin/coffee +7 -0
- data/node_modules/coffee-script/lib/browser.js +75 -0
- data/node_modules/coffee-script/lib/cake.js +76 -0
- data/node_modules/coffee-script/lib/coffee-script.js +107 -0
- data/node_modules/coffee-script/lib/command.js +274 -0
- data/node_modules/coffee-script/lib/grammar.js +591 -0
- data/node_modules/coffee-script/lib/helpers.js +66 -0
- data/node_modules/coffee-script/lib/index.js +8 -0
- data/node_modules/coffee-script/lib/lexer.js +650 -0
- data/node_modules/coffee-script/lib/nodes.js +2230 -0
- data/node_modules/coffee-script/lib/optparse.js +111 -0
- data/node_modules/coffee-script/lib/parser.js +676 -0
- data/node_modules/coffee-script/lib/repl.js +114 -0
- data/node_modules/coffee-script/lib/rewriter.js +359 -0
- data/node_modules/coffee-script/lib/scope.js +120 -0
- data/node_modules/coffee-script/package.json +27 -0
- data/node_modules/growl/History.md +16 -0
- data/node_modules/growl/Readme.md +74 -0
- data/node_modules/growl/lib/growl.js +82 -0
- data/node_modules/growl/package.json +6 -0
- data/node_modules/growl/test.js +17 -0
- data/node_modules/uglify-js/.gitignore +4 -0
- data/node_modules/uglify-js/README.html +825 -0
- data/node_modules/uglify-js/README.org +431 -0
- data/node_modules/uglify-js/bin/uglifyjs +212 -0
- data/node_modules/uglify-js/docstyle.css +75 -0
- data/node_modules/uglify-js/lib/parse-js.js +1319 -0
- data/node_modules/uglify-js/lib/process.js +1614 -0
- data/node_modules/uglify-js/lib/squeeze-more.js +22 -0
- data/node_modules/uglify-js/package.json +22 -0
- data/node_modules/uglify-js/test/beautify.js +28 -0
- data/node_modules/uglify-js/test/testparser.js +402 -0
- data/node_modules/uglify-js/test/unit/compress/expected/array1.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/expected/array2.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/expected/array3.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/expected/array4.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/expected/assignment.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/expected/concatstring.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/expected/const.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/expected/empty-blocks.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/expected/forstatement.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/expected/if.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/expected/ifreturn.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/expected/issue10.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/expected/issue11.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/expected/issue13.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/expected/issue14.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/expected/issue16.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/expected/issue17.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/expected/issue20.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/expected/issue21.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/expected/issue25.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/expected/issue27.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/expected/issue28.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/expected/issue29.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/expected/issue30.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/expected/issue34.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/expected/issue4.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/expected/issue48.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/expected/issue50.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/expected/issue53.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/expected/issue54.1.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/expected/issue68.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/expected/issue69.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/expected/issue9.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/expected/strict-equals.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/expected/var.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/test/array1.js +3 -0
- data/node_modules/uglify-js/test/unit/compress/test/array2.js +4 -0
- data/node_modules/uglify-js/test/unit/compress/test/array3.js +4 -0
- data/node_modules/uglify-js/test/unit/compress/test/array4.js +6 -0
- data/node_modules/uglify-js/test/unit/compress/test/assignment.js +20 -0
- data/node_modules/uglify-js/test/unit/compress/test/concatstring.js +3 -0
- data/node_modules/uglify-js/test/unit/compress/test/const.js +5 -0
- data/node_modules/uglify-js/test/unit/compress/test/empty-blocks.js +4 -0
- data/node_modules/uglify-js/test/unit/compress/test/forstatement.js +10 -0
- data/node_modules/uglify-js/test/unit/compress/test/if.js +6 -0
- data/node_modules/uglify-js/test/unit/compress/test/ifreturn.js +9 -0
- data/node_modules/uglify-js/test/unit/compress/test/issue10.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/test/issue11.js +3 -0
- data/node_modules/uglify-js/test/unit/compress/test/issue13.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/test/issue14.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/test/issue16.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/test/issue17.js +4 -0
- data/node_modules/uglify-js/test/unit/compress/test/issue20.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/test/issue21.js +6 -0
- data/node_modules/uglify-js/test/unit/compress/test/issue25.js +7 -0
- data/node_modules/uglify-js/test/unit/compress/test/issue27.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/test/issue28.js +3 -0
- data/node_modules/uglify-js/test/unit/compress/test/issue29.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/test/issue30.js +3 -0
- data/node_modules/uglify-js/test/unit/compress/test/issue34.js +3 -0
- data/node_modules/uglify-js/test/unit/compress/test/issue4.js +3 -0
- data/node_modules/uglify-js/test/unit/compress/test/issue48.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/test/issue50.js +9 -0
- data/node_modules/uglify-js/test/unit/compress/test/issue53.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/test/issue54.1.js +3 -0
- data/node_modules/uglify-js/test/unit/compress/test/issue68.js +5 -0
- data/node_modules/uglify-js/test/unit/compress/test/issue69.js +1 -0
- data/node_modules/uglify-js/test/unit/compress/test/issue9.js +4 -0
- data/node_modules/uglify-js/test/unit/compress/test/strict-equals.js +3 -0
- data/node_modules/uglify-js/test/unit/compress/test/var.js +3 -0
- data/node_modules/uglify-js/test/unit/scripts.js +46 -0
- data/node_modules/uglify-js/uglify-js.js +2 -0
- data/src/coffeescript/coffeescript-router.js.coffee +31 -0
- data/test/coffeescript/routerSpec.coffee +47 -0
- data/vendor/assets/javascripts/coffeescript-router.min.js +1 -0
- metadata +187 -0
@@ -0,0 +1 @@
|
|
1
|
+
[],Array(1),[1,2,3]
|
@@ -0,0 +1 @@
|
|
1
|
+
(function(){var a=function(){};return new a(1,2,3,4)})()
|
@@ -0,0 +1 @@
|
|
1
|
+
(function(){function a(){}return new a(1,2,3,4)})()
|
@@ -0,0 +1 @@
|
|
1
|
+
(function(){function a(){}(function(){return new a(1,2,3)})()})()
|
@@ -0,0 +1 @@
|
|
1
|
+
a=1,b=a,c=1,d=b,e=d,longname=2;if(longname+1){x=3;if(x)var z=7}z=1,y=1,x=1,g+=1,h=g,++i,j=i,i++,j=i+17
|
@@ -0,0 +1 @@
|
|
1
|
+
var a=a+"a"+"b"+1+c,b=a+"c"+"ds"+123+c,c=a+"c"+123+d+"ds"+c
|
@@ -0,0 +1 @@
|
|
1
|
+
var a=13,b=1/3
|
@@ -0,0 +1 @@
|
|
1
|
+
function mak(){for(;;);}function foo(){while(bar());}function bar(){return--x}var x=5
|
@@ -0,0 +1 @@
|
|
1
|
+
a=func(),b=z;for(a++;i<10;i++)alert(i);var z=1;g=2;for(;i<10;i++)alert(i);var a=2;for(var i=1;i<10;i++)alert(i)
|
@@ -0,0 +1 @@
|
|
1
|
+
var a=1;a==1?a=2:a=17
|
@@ -0,0 +1 @@
|
|
1
|
+
function a(a){return a==1?2:17}
|
@@ -0,0 +1 @@
|
|
1
|
+
function f(){var a;return(a="a")?a:a}f()
|
@@ -0,0 +1 @@
|
|
1
|
+
new(A,B),new(A||B),new(X?A:B)
|
@@ -0,0 +1 @@
|
|
1
|
+
var a=/^(?:(\w+):)?(?:\/\/(?:(?:([^:@\/]*):?([^:@\/]*))?@)?([^:\/?#])(?::(\d))?)?(..?$|(?:[^?#\/]\/))([^?#]*)(?:\?([^#]))?(?:#(.))?/
|
@@ -0,0 +1 @@
|
|
1
|
+
var a={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"}
|
@@ -0,0 +1 @@
|
|
1
|
+
var a=3250441966
|
@@ -0,0 +1 @@
|
|
1
|
+
var a=function(b){b(),a()}
|
@@ -0,0 +1 @@
|
|
1
|
+
a:1
|
@@ -0,0 +1 @@
|
|
1
|
+
var a=0;switch(a){case 0:a++}
|
@@ -0,0 +1 @@
|
|
1
|
+
label1:{label2:break label2;console.log(1)}
|
@@ -0,0 +1 @@
|
|
1
|
+
(a?b:c)?d:e
|
@@ -0,0 +1 @@
|
|
1
|
+
o={".5":.5},o={.5:.5},o={.5:.5}
|
@@ -0,0 +1 @@
|
|
1
|
+
result=function(){return 1}()
|
@@ -0,0 +1 @@
|
|
1
|
+
var a=8,b=4,c=4
|
@@ -0,0 +1 @@
|
|
1
|
+
var a={};a["this"]=1,a.that=2
|
@@ -0,0 +1 @@
|
|
1
|
+
var a=2e3,b=.002,c=2e-5
|
@@ -0,0 +1 @@
|
|
1
|
+
var s,i;s="",i=0
|
@@ -0,0 +1 @@
|
|
1
|
+
function bar(a){try{foo()}catch(b){alert("Exception caught (foo not defined)")}alert(a)}bar(10)
|
@@ -0,0 +1 @@
|
|
1
|
+
x=(y,z)
|
@@ -0,0 +1 @@
|
|
1
|
+
foo+"",a.toString(16),b.toString.call(c)
|
@@ -0,0 +1 @@
|
|
1
|
+
function f(){function b(){}a||b()}
|
@@ -0,0 +1 @@
|
|
1
|
+
[(a,b)]
|
@@ -0,0 +1 @@
|
|
1
|
+
var a={a:1,b:2}
|
@@ -0,0 +1 @@
|
|
1
|
+
typeof a=="string",b+""!=c+"",d<e==f<g
|
@@ -0,0 +1 @@
|
|
1
|
+
var a=1,b=2
|
@@ -0,0 +1 @@
|
|
1
|
+
function f() { var a; if (a = 'a') { return a; } else { return a; } }; f();
|
@@ -0,0 +1 @@
|
|
1
|
+
var a = /^(?:(\w+):)?(?:\/\/(?:(?:([^:@\/]*):?([^:@\/]*))?@)?([^:\/?#])(?::(\d))?)?(..?$|(?:[^?#\/]\/))([^?#]*)(?:\?([^#]))?(?:#(.))?/;
|
@@ -0,0 +1 @@
|
|
1
|
+
var a = {'\b': '\\b', '\t': '\\t', '\n': '\\n', '\f': '\\f', '\r': '\\r', '"' : '\\"', '\\': '\\\\'};
|
@@ -0,0 +1 @@
|
|
1
|
+
var a = 0xC1BDCEEE;
|
@@ -0,0 +1 @@
|
|
1
|
+
{a: 1}
|
@@ -0,0 +1 @@
|
|
1
|
+
(a ? b : c) ? d : e
|
@@ -0,0 +1 @@
|
|
1
|
+
result=(function(){ return 1;})()
|
@@ -0,0 +1 @@
|
|
1
|
+
var s, i; s = ''; i = 0;
|
@@ -0,0 +1 @@
|
|
1
|
+
x = (y, z)
|
@@ -0,0 +1 @@
|
|
1
|
+
[(a,b)]
|
@@ -0,0 +1,46 @@
|
|
1
|
+
var fs = require('fs'),
|
2
|
+
uglify = require('uglify-js'),
|
3
|
+
jsp = uglify.parser,
|
4
|
+
nodeunit = require('nodeunit'),
|
5
|
+
path = require('path'),
|
6
|
+
pro = uglify.uglify;
|
7
|
+
|
8
|
+
var Script = process.binding('evals').Script;
|
9
|
+
|
10
|
+
var scriptsPath = __dirname;
|
11
|
+
|
12
|
+
function compress(code) {
|
13
|
+
var ast = jsp.parse(code);
|
14
|
+
ast = pro.ast_mangle(ast);
|
15
|
+
ast = pro.ast_squeeze(ast, {no_warnings: true, extra: true});
|
16
|
+
ast = pro.ast_squeeze_more(ast);
|
17
|
+
return pro.gen_code(ast);
|
18
|
+
};
|
19
|
+
|
20
|
+
module.exports = nodeunit.testCase({
|
21
|
+
compress: function(test) {
|
22
|
+
var testDir = path.join(scriptsPath, "compress", "test");
|
23
|
+
var expectedDir = path.join(scriptsPath, "compress", "expected");
|
24
|
+
|
25
|
+
var scripts = fs.readdirSync(testDir);
|
26
|
+
for (var i in scripts) {
|
27
|
+
var script = scripts[i];
|
28
|
+
testPath = path.join(testDir, script);
|
29
|
+
expectedPath = path.join(expectedDir, script);
|
30
|
+
var content = fs.readFileSync(testPath, 'utf-8');
|
31
|
+
var outputCompress = compress(content);
|
32
|
+
|
33
|
+
// Check if the noncompressdata is larger or same size as the compressed data
|
34
|
+
test.ok(content.length >= outputCompress.length);
|
35
|
+
|
36
|
+
// Check that a recompress gives the same result
|
37
|
+
var outputReCompress = compress(content);
|
38
|
+
test.equal(outputCompress, outputReCompress);
|
39
|
+
|
40
|
+
// Check if the compressed output is what is expected
|
41
|
+
var expected = fs.readFileSync(expectedPath, 'utf-8');
|
42
|
+
test.equal(outputCompress, expected.replace(/(\r?\n)+$/, ""));
|
43
|
+
}
|
44
|
+
test.done();
|
45
|
+
}
|
46
|
+
});
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class Router
|
2
|
+
@routes = []
|
3
|
+
constructor: ->
|
4
|
+
console.log "should never get here"
|
5
|
+
|
6
|
+
@buildRegexString: (path) ->
|
7
|
+
path.replace(/\//g, "\\/").replace(/:(\w*)/g,"(\\w*)")
|
8
|
+
|
9
|
+
@add: (path, func) ->
|
10
|
+
@routes.push {
|
11
|
+
params: path.match(/:(\w*)/g)
|
12
|
+
regex: new RegExp(@buildRegexString(path))
|
13
|
+
callback: func
|
14
|
+
}
|
15
|
+
|
16
|
+
@clear: ->
|
17
|
+
@routes = []
|
18
|
+
|
19
|
+
@process: (url = window.location.pathname) ->
|
20
|
+
for route in @routes
|
21
|
+
results = url.match(route.regex)
|
22
|
+
if results?
|
23
|
+
index = 1
|
24
|
+
namedParams = {}
|
25
|
+
if route.params?
|
26
|
+
for name in route.params
|
27
|
+
namedParams[name.slice(1)] = results[index++]
|
28
|
+
route.callback(namedParams)
|
29
|
+
return
|
30
|
+
|
31
|
+
window.Router = Router
|
@@ -0,0 +1,47 @@
|
|
1
|
+
blog_route = "/blog/:year/:month/:day"
|
2
|
+
|
3
|
+
describe "Router", ->
|
4
|
+
it "should exist", ->
|
5
|
+
expect(Router).not.toBeNull()
|
6
|
+
|
7
|
+
describe "#buildRegexString", ->
|
8
|
+
it "should build the regular expression correctly", ->
|
9
|
+
expect(Router.buildRegexString(blog_route)).toEqual("\\/blog\\/(\\w*)\\/(\\w*)\\/(\\w*)")
|
10
|
+
|
11
|
+
describe "#add", ->
|
12
|
+
beforeEach ->
|
13
|
+
Router.add blog_route, null
|
14
|
+
|
15
|
+
it "should add a route to the routes array", ->
|
16
|
+
expect(Router.routes.length).toBe(1)
|
17
|
+
|
18
|
+
it "should find the three named params", ->
|
19
|
+
expect(Router.routes[0].params.length).toBe(3)
|
20
|
+
|
21
|
+
describe "#clear", ->
|
22
|
+
beforeEach ->
|
23
|
+
Router.add blog_route, null
|
24
|
+
|
25
|
+
it "should clear out the routes array", ->
|
26
|
+
Router.clear()
|
27
|
+
expect(Router.routes.length).toBe(0)
|
28
|
+
|
29
|
+
describe "#process", ->
|
30
|
+
api = result = ""
|
31
|
+
beforeEach ->
|
32
|
+
api = {
|
33
|
+
testCallBack: (params)->
|
34
|
+
console.log "testCallBack"
|
35
|
+
}
|
36
|
+
spyOn(api, "testCallBack").andCallFake( (params)->
|
37
|
+
result = params
|
38
|
+
)
|
39
|
+
|
40
|
+
Router.add blog_route, api.testCallBack
|
41
|
+
Router.process("/blog/2012/01/01")
|
42
|
+
|
43
|
+
it "should find the route and execute the callback", ->
|
44
|
+
expect(api.testCallBack).toHaveBeenCalled()
|
45
|
+
|
46
|
+
it "should execute the callback with the correct parameters", ->
|
47
|
+
expect(result).toEqual({ year: "2012", month: "01", day: "01"})
|