coffeescript-router 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. data/.gitignore +3 -0
  2. data/Cakefile +122 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +22 -0
  5. data/LICENSE.txt +19 -0
  6. data/README.md +18 -0
  7. data/Rakefile +2 -0
  8. data/SpecRunner.html +25 -0
  9. data/coffeescript-router.gemspec +19 -0
  10. data/lib/CoffeeScript.png +0 -0
  11. data/lib/coffeescript-router/version.rb +5 -0
  12. data/lib/jasmine-1.0.2/MIT.LICENSE +20 -0
  13. data/lib/jasmine-1.0.2/jasmine-html.js +188 -0
  14. data/lib/jasmine-1.0.2/jasmine.css +166 -0
  15. data/lib/jasmine-1.0.2/jasmine.js +2421 -0
  16. data/node_modules/.bin/cake +7 -0
  17. data/node_modules/.bin/coffee +7 -0
  18. data/node_modules/.bin/uglifyjs +212 -0
  19. data/node_modules/coffee-script/.npmignore +11 -0
  20. data/node_modules/coffee-script/LICENSE +22 -0
  21. data/node_modules/coffee-script/README +48 -0
  22. data/node_modules/coffee-script/Rakefile +78 -0
  23. data/node_modules/coffee-script/bin/cake +7 -0
  24. data/node_modules/coffee-script/bin/coffee +7 -0
  25. data/node_modules/coffee-script/lib/browser.js +75 -0
  26. data/node_modules/coffee-script/lib/cake.js +76 -0
  27. data/node_modules/coffee-script/lib/coffee-script.js +107 -0
  28. data/node_modules/coffee-script/lib/command.js +274 -0
  29. data/node_modules/coffee-script/lib/grammar.js +591 -0
  30. data/node_modules/coffee-script/lib/helpers.js +66 -0
  31. data/node_modules/coffee-script/lib/index.js +8 -0
  32. data/node_modules/coffee-script/lib/lexer.js +650 -0
  33. data/node_modules/coffee-script/lib/nodes.js +2230 -0
  34. data/node_modules/coffee-script/lib/optparse.js +111 -0
  35. data/node_modules/coffee-script/lib/parser.js +676 -0
  36. data/node_modules/coffee-script/lib/repl.js +114 -0
  37. data/node_modules/coffee-script/lib/rewriter.js +359 -0
  38. data/node_modules/coffee-script/lib/scope.js +120 -0
  39. data/node_modules/coffee-script/package.json +27 -0
  40. data/node_modules/growl/History.md +16 -0
  41. data/node_modules/growl/Readme.md +74 -0
  42. data/node_modules/growl/lib/growl.js +82 -0
  43. data/node_modules/growl/package.json +6 -0
  44. data/node_modules/growl/test.js +17 -0
  45. data/node_modules/uglify-js/.gitignore +4 -0
  46. data/node_modules/uglify-js/README.html +825 -0
  47. data/node_modules/uglify-js/README.org +431 -0
  48. data/node_modules/uglify-js/bin/uglifyjs +212 -0
  49. data/node_modules/uglify-js/docstyle.css +75 -0
  50. data/node_modules/uglify-js/lib/parse-js.js +1319 -0
  51. data/node_modules/uglify-js/lib/process.js +1614 -0
  52. data/node_modules/uglify-js/lib/squeeze-more.js +22 -0
  53. data/node_modules/uglify-js/package.json +22 -0
  54. data/node_modules/uglify-js/test/beautify.js +28 -0
  55. data/node_modules/uglify-js/test/testparser.js +402 -0
  56. data/node_modules/uglify-js/test/unit/compress/expected/array1.js +1 -0
  57. data/node_modules/uglify-js/test/unit/compress/expected/array2.js +1 -0
  58. data/node_modules/uglify-js/test/unit/compress/expected/array3.js +1 -0
  59. data/node_modules/uglify-js/test/unit/compress/expected/array4.js +1 -0
  60. data/node_modules/uglify-js/test/unit/compress/expected/assignment.js +1 -0
  61. data/node_modules/uglify-js/test/unit/compress/expected/concatstring.js +1 -0
  62. data/node_modules/uglify-js/test/unit/compress/expected/const.js +1 -0
  63. data/node_modules/uglify-js/test/unit/compress/expected/empty-blocks.js +1 -0
  64. data/node_modules/uglify-js/test/unit/compress/expected/forstatement.js +1 -0
  65. data/node_modules/uglify-js/test/unit/compress/expected/if.js +1 -0
  66. data/node_modules/uglify-js/test/unit/compress/expected/ifreturn.js +1 -0
  67. data/node_modules/uglify-js/test/unit/compress/expected/issue10.js +1 -0
  68. data/node_modules/uglify-js/test/unit/compress/expected/issue11.js +1 -0
  69. data/node_modules/uglify-js/test/unit/compress/expected/issue13.js +1 -0
  70. data/node_modules/uglify-js/test/unit/compress/expected/issue14.js +1 -0
  71. data/node_modules/uglify-js/test/unit/compress/expected/issue16.js +1 -0
  72. data/node_modules/uglify-js/test/unit/compress/expected/issue17.js +1 -0
  73. data/node_modules/uglify-js/test/unit/compress/expected/issue20.js +1 -0
  74. data/node_modules/uglify-js/test/unit/compress/expected/issue21.js +1 -0
  75. data/node_modules/uglify-js/test/unit/compress/expected/issue25.js +1 -0
  76. data/node_modules/uglify-js/test/unit/compress/expected/issue27.js +1 -0
  77. data/node_modules/uglify-js/test/unit/compress/expected/issue28.js +1 -0
  78. data/node_modules/uglify-js/test/unit/compress/expected/issue29.js +1 -0
  79. data/node_modules/uglify-js/test/unit/compress/expected/issue30.js +1 -0
  80. data/node_modules/uglify-js/test/unit/compress/expected/issue34.js +1 -0
  81. data/node_modules/uglify-js/test/unit/compress/expected/issue4.js +1 -0
  82. data/node_modules/uglify-js/test/unit/compress/expected/issue48.js +1 -0
  83. data/node_modules/uglify-js/test/unit/compress/expected/issue50.js +1 -0
  84. data/node_modules/uglify-js/test/unit/compress/expected/issue53.js +1 -0
  85. data/node_modules/uglify-js/test/unit/compress/expected/issue54.1.js +1 -0
  86. data/node_modules/uglify-js/test/unit/compress/expected/issue68.js +1 -0
  87. data/node_modules/uglify-js/test/unit/compress/expected/issue69.js +1 -0
  88. data/node_modules/uglify-js/test/unit/compress/expected/issue9.js +1 -0
  89. data/node_modules/uglify-js/test/unit/compress/expected/strict-equals.js +1 -0
  90. data/node_modules/uglify-js/test/unit/compress/expected/var.js +1 -0
  91. data/node_modules/uglify-js/test/unit/compress/test/array1.js +3 -0
  92. data/node_modules/uglify-js/test/unit/compress/test/array2.js +4 -0
  93. data/node_modules/uglify-js/test/unit/compress/test/array3.js +4 -0
  94. data/node_modules/uglify-js/test/unit/compress/test/array4.js +6 -0
  95. data/node_modules/uglify-js/test/unit/compress/test/assignment.js +20 -0
  96. data/node_modules/uglify-js/test/unit/compress/test/concatstring.js +3 -0
  97. data/node_modules/uglify-js/test/unit/compress/test/const.js +5 -0
  98. data/node_modules/uglify-js/test/unit/compress/test/empty-blocks.js +4 -0
  99. data/node_modules/uglify-js/test/unit/compress/test/forstatement.js +10 -0
  100. data/node_modules/uglify-js/test/unit/compress/test/if.js +6 -0
  101. data/node_modules/uglify-js/test/unit/compress/test/ifreturn.js +9 -0
  102. data/node_modules/uglify-js/test/unit/compress/test/issue10.js +1 -0
  103. data/node_modules/uglify-js/test/unit/compress/test/issue11.js +3 -0
  104. data/node_modules/uglify-js/test/unit/compress/test/issue13.js +1 -0
  105. data/node_modules/uglify-js/test/unit/compress/test/issue14.js +1 -0
  106. data/node_modules/uglify-js/test/unit/compress/test/issue16.js +1 -0
  107. data/node_modules/uglify-js/test/unit/compress/test/issue17.js +4 -0
  108. data/node_modules/uglify-js/test/unit/compress/test/issue20.js +1 -0
  109. data/node_modules/uglify-js/test/unit/compress/test/issue21.js +6 -0
  110. data/node_modules/uglify-js/test/unit/compress/test/issue25.js +7 -0
  111. data/node_modules/uglify-js/test/unit/compress/test/issue27.js +1 -0
  112. data/node_modules/uglify-js/test/unit/compress/test/issue28.js +3 -0
  113. data/node_modules/uglify-js/test/unit/compress/test/issue29.js +1 -0
  114. data/node_modules/uglify-js/test/unit/compress/test/issue30.js +3 -0
  115. data/node_modules/uglify-js/test/unit/compress/test/issue34.js +3 -0
  116. data/node_modules/uglify-js/test/unit/compress/test/issue4.js +3 -0
  117. data/node_modules/uglify-js/test/unit/compress/test/issue48.js +1 -0
  118. data/node_modules/uglify-js/test/unit/compress/test/issue50.js +9 -0
  119. data/node_modules/uglify-js/test/unit/compress/test/issue53.js +1 -0
  120. data/node_modules/uglify-js/test/unit/compress/test/issue54.1.js +3 -0
  121. data/node_modules/uglify-js/test/unit/compress/test/issue68.js +5 -0
  122. data/node_modules/uglify-js/test/unit/compress/test/issue69.js +1 -0
  123. data/node_modules/uglify-js/test/unit/compress/test/issue9.js +4 -0
  124. data/node_modules/uglify-js/test/unit/compress/test/strict-equals.js +3 -0
  125. data/node_modules/uglify-js/test/unit/compress/test/var.js +3 -0
  126. data/node_modules/uglify-js/test/unit/scripts.js +46 -0
  127. data/node_modules/uglify-js/uglify-js.js +2 -0
  128. data/src/coffeescript/coffeescript-router.js.coffee +31 -0
  129. data/test/coffeescript/routerSpec.coffee +47 -0
  130. data/vendor/assets/javascripts/coffeescript-router.min.js +1 -0
  131. metadata +187 -0
@@ -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
+ 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=function(b){b(),a()}
@@ -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
+ o={".5":.5},o={.5:.5},o={.5:.5}
@@ -0,0 +1 @@
1
+ result=function(){return 1}()
@@ -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
+ function bar(a){try{foo()}catch(b){alert("Exception caught (foo not defined)")}alert(a)}bar(10)
@@ -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
+ typeof a=="string",b+""!=c+"",d<e==f<g
@@ -0,0 +1,3 @@
1
+ new Array();
2
+ new Array(1);
3
+ new Array(1, 2, 3);
@@ -0,0 +1,4 @@
1
+ (function(){
2
+ var Array = function(){};
3
+ return new Array(1, 2, 3, 4);
4
+ })();
@@ -0,0 +1,4 @@
1
+ (function(){
2
+ return new Array(1, 2, 3, 4);
3
+ function Array() {};
4
+ })();
@@ -0,0 +1,6 @@
1
+ (function(){
2
+ (function(){
3
+ return new Array(1, 2, 3);
4
+ })();
5
+ function Array(){};
6
+ })();
@@ -0,0 +1,20 @@
1
+ a=1;
2
+ b=a;
3
+ c=1;
4
+ d=b;
5
+ e=d;
6
+ longname=2;
7
+ if (longname+1) {
8
+ x=3;
9
+ if (x) var z = 7;
10
+ }
11
+ z=1,y=1,x=1
12
+
13
+ g+=1;
14
+ h=g;
15
+
16
+ ++i;
17
+ j=i;
18
+
19
+ i++;
20
+ j=i+17;
@@ -0,0 +1,3 @@
1
+ var a = a + "a" + "b" + 1 + c;
2
+ var b = a + "c" + "ds" + 123 + c;
3
+ var c = a + "c" + 123 + d + "ds" + c;
@@ -0,0 +1,5 @@
1
+ // test that the calculation is fold to 13
2
+ var a = 1 + 2 * 6;
3
+
4
+ // test that it isn't replaced with 0.3333 because that is more characters
5
+ var b = 1/3;
@@ -0,0 +1,4 @@
1
+ var x = 5;
2
+ function bar() { return --x; }
3
+ function foo() { while (bar()); }
4
+ function mak() { for(;;); }
@@ -0,0 +1,10 @@
1
+ a=func();
2
+ b=z;
3
+ for (a++; i < 10; i++) { alert(i); }
4
+
5
+ var z=1;
6
+ g=2;
7
+ for (; i < 10; i++) { alert(i); }
8
+
9
+ var a = 2;
10
+ for (var i = 1; i < 10; i++) { alert(i); }
@@ -0,0 +1,6 @@
1
+ var a = 1;
2
+ if (a == 1) {
3
+ a = 2;
4
+ } else {
5
+ a = 17;
6
+ }
@@ -0,0 +1,9 @@
1
+ function a(b) {
2
+ if (b == 1) {
3
+ return 2;
4
+ } else {
5
+ return 17;
6
+ }
7
+
8
+ return 3;
9
+ }
@@ -0,0 +1 @@
1
+ function f() { var a; if (a = 'a') { return a; } else { return a; } }; f();
@@ -0,0 +1,3 @@
1
+ new (A, B)
2
+ new (A || B)
3
+ 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,4 @@
1
+ var a = function(b) {
2
+ b();
3
+ a()
4
+ }
@@ -0,0 +1,6 @@
1
+ var a = 0;
2
+ switch(a) {
3
+ case 0:
4
+ a++;
5
+ break;
6
+ }
@@ -0,0 +1,7 @@
1
+ label1 : {
2
+ label2 : {
3
+ break label2;
4
+ console.log(2);
5
+ }
6
+ console.log(1);
7
+ }
@@ -0,0 +1,3 @@
1
+ o = {'.5':.5}
2
+ o = {'0.5':.5}
3
+ o = {0.5:.5}
@@ -0,0 +1 @@
1
+ result=(function(){ return 1;})()
@@ -0,0 +1,3 @@
1
+ var a = 1 << 3;
2
+ var b = 8 >> 1;
3
+ var c = 8 >>> 1;
@@ -0,0 +1,3 @@
1
+ var a = {};
2
+ a["this"] = 1;
3
+ a["that"] = 2;
@@ -0,0 +1,3 @@
1
+ var a = 2e3;
2
+ var b = 2e-3;
3
+ var c = 2e-5;
@@ -0,0 +1 @@
1
+ var s, i; s = ''; i = 0;
@@ -0,0 +1,9 @@
1
+ function bar(a) {
2
+ try {
3
+ foo();
4
+ } catch(e) {
5
+ alert("Exception caught (foo not defined)");
6
+ }
7
+ alert(a); // 10 in FF, "[object Error]" in IE
8
+ }
9
+ bar(10);
@@ -0,0 +1,3 @@
1
+ foo.toString();
2
+ a.toString(16);
3
+ b.toString.call(c);
@@ -0,0 +1,5 @@
1
+ function f() {
2
+ if (a) return;
3
+ g();
4
+ function g(){}
5
+ };
@@ -0,0 +1,4 @@
1
+ var a = {
2
+ a: 1,
3
+ b: 2, // <-- trailing comma
4
+ };
@@ -0,0 +1,3 @@
1
+ typeof a === 'string'
2
+ b + "" !== c + ""
3
+ d < e === f < g
@@ -0,0 +1,3 @@
1
+ // var declarations after each other should be combined
2
+ var a = 1;
3
+ var b = 2;
@@ -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,2 @@
1
+ exports.parser = require("./lib/parse-js");
2
+ exports.uglify = require("./lib/process");
@@ -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"})