ninjs 0.14.1 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (191) hide show
  1. data/.bundle/config +2 -2
  2. data/.travis.yml +1 -0
  3. data/Gemfile +1 -0
  4. data/Gemfile.lock +13 -11
  5. data/README.md +108 -93
  6. data/Rakefile +17 -7
  7. data/VERSION +1 -1
  8. data/bin/ninjs +24 -22
  9. data/lib/ninjs/command.rb +32 -21
  10. data/lib/ninjs/configuration.rb +35 -53
  11. data/lib/ninjs/generator.rb +6 -6
  12. data/lib/ninjs/notification.rb +5 -5
  13. data/lib/ninjs/project.rb +31 -25
  14. data/ninjs.gemspec +18 -142
  15. data/repository/ninjs/core/application.js +13 -24
  16. data/repository/ninjs/core/dom.js +87 -68
  17. data/repository/ninjs/core/existence.js +44 -105
  18. data/repository/ninjs/core/extend.js +11 -32
  19. data/repository/ninjs/core/module.js +53 -107
  20. data/repository/ninjs/core/nin.js +5 -7
  21. data/repository/ninjs/tests/extension.test.js +0 -10
  22. data/repository/ninjs/tests/index.html +19 -20
  23. data/repository/ninjs/tests/module.test.js +52 -56
  24. data/repository/ninjs/utilities/array.js +8 -8
  25. data/repository/ninjs/utilities/cookie.js +59 -0
  26. data/repository/ninjs/utilities/css.js +7 -7
  27. data/repository/ninjs/utilities/number.js +2 -2
  28. data/repository/ninjs/utilities/string.js +26 -26
  29. data/spec/cli_spec.rb +90 -88
  30. data/spec/command_spec.rb +104 -137
  31. data/spec/configuration_spec.rb +23 -37
  32. data/spec/fixtures/_global.module.js +9 -0
  33. data/spec/fixtures/compressed.myapp.js +23 -44
  34. data/spec/fixtures/foo.elements.js +1 -1
  35. data/spec/fixtures/foo.js +5 -5
  36. data/spec/fixtures/foo.model.js +1 -1
  37. data/spec/fixtures/foo.module.js +3 -3
  38. data/spec/fixtures/hello.elements.js +1 -1
  39. data/spec/fixtures/hello.js +5 -5
  40. data/spec/fixtures/hello.model.js +1 -1
  41. data/spec/fixtures/hello.module.js +3 -3
  42. data/spec/fixtures/myapp.initial.js +198 -329
  43. data/spec/fixtures/myapp.js +285 -357
  44. data/spec/fixtures/mymodule.alias.module.js +2 -2
  45. data/spec/fixtures/mymodule.dependencies.module.js +2 -2
  46. data/spec/fixtures/mymodule.elements.js +1 -1
  47. data/spec/fixtures/mymodule.model.js +1 -1
  48. data/spec/fixtures/mymodule.module.js +2 -2
  49. data/spec/fixtures/mymodule.module_alias.module.js +10 -0
  50. data/spec/fixtures/new.ninjs.conf +2 -0
  51. data/spec/fixtures/nin.js +198 -329
  52. data/spec/fixtures/ninjs.conf +2 -0
  53. data/spec/fixtures/updated.ninjs.conf +8 -0
  54. data/spec/generator_spec.rb +37 -26
  55. data/spec/ninjs_spec.rb +6 -6
  56. data/spec/project_spec.rb +229 -221
  57. data/spec/spec_helper.rb +3 -1
  58. data/spec/testspec_spec.rb +7 -0
  59. metadata +28 -145
  60. data/repository/json2.js +0 -482
  61. data/repository/modernizr/1.5.js +0 -28
  62. data/repository/modernizr/latest.js +0 -1
  63. data/repository/ninjs/docs/Data/ClassHierarchy.nd +0 -0
  64. data/repository/ninjs/docs/Data/ConfigFileInfo.nd +0 -0
  65. data/repository/ninjs/docs/Data/FileInfo.nd +0 -16
  66. data/repository/ninjs/docs/Data/ImageFileInfo.nd +0 -0
  67. data/repository/ninjs/docs/Data/ImageReferenceTable.nd +0 -0
  68. data/repository/ninjs/docs/Data/IndexInfo.nd +0 -0
  69. data/repository/ninjs/docs/Data/PreviousMenuState.nd +0 -0
  70. data/repository/ninjs/docs/Data/PreviousSettings.nd +0 -0
  71. data/repository/ninjs/docs/Data/SymbolTable.nd +0 -0
  72. data/repository/ninjs/docs/Languages.txt +0 -113
  73. data/repository/ninjs/docs/Menu.txt +0 -63
  74. data/repository/ninjs/docs/Topics.txt +0 -81
  75. data/repository/ninjs/docs/files/core/application-js.html +0 -44
  76. data/repository/ninjs/docs/files/core/existence-js.html +0 -60
  77. data/repository/ninjs/docs/files/core/extend-js.html +0 -55
  78. data/repository/ninjs/docs/files/core/module-js.html +0 -80
  79. data/repository/ninjs/docs/files/core/nin-js.html +0 -38
  80. data/repository/ninjs/docs/index.html +0 -1
  81. data/repository/ninjs/docs/index/Classes.html +0 -33
  82. data/repository/ninjs/docs/index/Files.html +0 -45
  83. data/repository/ninjs/docs/index/Functions.html +0 -65
  84. data/repository/ninjs/docs/index/General.html +0 -85
  85. data/repository/ninjs/docs/index/Variables.html +0 -45
  86. data/repository/ninjs/docs/javascript/main.js +0 -841
  87. data/repository/ninjs/docs/javascript/prettify.js +0 -1526
  88. data/repository/ninjs/docs/javascript/searchdata.js +0 -152
  89. data/repository/ninjs/docs/search/ClassesN.html +0 -20
  90. data/repository/ninjs/docs/search/FilesA.html +0 -20
  91. data/repository/ninjs/docs/search/FilesE.html +0 -20
  92. data/repository/ninjs/docs/search/FilesM.html +0 -20
  93. data/repository/ninjs/docs/search/FilesN.html +0 -20
  94. data/repository/ninjs/docs/search/FunctionsA.html +0 -20
  95. data/repository/ninjs/docs/search/FunctionsC.html +0 -20
  96. data/repository/ninjs/docs/search/FunctionsE.html +0 -20
  97. data/repository/ninjs/docs/search/FunctionsI.html +0 -20
  98. data/repository/ninjs/docs/search/FunctionsM.html +0 -20
  99. data/repository/ninjs/docs/search/FunctionsR.html +0 -20
  100. data/repository/ninjs/docs/search/FunctionsS.html +0 -20
  101. data/repository/ninjs/docs/search/FunctionsSymbols.html +0 -20
  102. data/repository/ninjs/docs/search/FunctionsU.html +0 -20
  103. data/repository/ninjs/docs/search/GeneralA.html +0 -20
  104. data/repository/ninjs/docs/search/GeneralC.html +0 -20
  105. data/repository/ninjs/docs/search/GeneralD.html +0 -20
  106. data/repository/ninjs/docs/search/GeneralE.html +0 -20
  107. data/repository/ninjs/docs/search/GeneralF.html +0 -20
  108. data/repository/ninjs/docs/search/GeneralI.html +0 -20
  109. data/repository/ninjs/docs/search/GeneralM.html +0 -20
  110. data/repository/ninjs/docs/search/GeneralN.html +0 -20
  111. data/repository/ninjs/docs/search/GeneralR.html +0 -20
  112. data/repository/ninjs/docs/search/GeneralS.html +0 -20
  113. data/repository/ninjs/docs/search/GeneralSymbols.html +0 -20
  114. data/repository/ninjs/docs/search/GeneralT.html +0 -20
  115. data/repository/ninjs/docs/search/GeneralU.html +0 -20
  116. data/repository/ninjs/docs/search/GeneralV.html +0 -20
  117. data/repository/ninjs/docs/search/NoResults.html +0 -15
  118. data/repository/ninjs/docs/search/VariablesD.html +0 -20
  119. data/repository/ninjs/docs/search/VariablesN.html +0 -20
  120. data/repository/ninjs/docs/search/VariablesR.html +0 -20
  121. data/repository/ninjs/docs/search/VariablesT.html +0 -20
  122. data/repository/ninjs/docs/styles/main.css +0 -828
  123. data/repository/nullconsole.js +0 -7
  124. data/repository/qunit/assets/css/qunit.css +0 -196
  125. data/repository/qunit/qunit.js +0 -1374
  126. data/repository/selectivizr/1.0.js +0 -5
  127. data/repository/selectivizr/latest.js +0 -1
  128. data/repository/syntaxhighlighter/all.js +0 -11
  129. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCore.css +0 -226
  130. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreDefault.css +0 -328
  131. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreDjango.css +0 -331
  132. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreEclipse.css +0 -339
  133. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreEmacs.css +0 -324
  134. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreFadeToGrey.css +0 -328
  135. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreMDUltra.css +0 -324
  136. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreMidnight.css +0 -324
  137. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreRDark.css +0 -324
  138. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeDefault.css +0 -117
  139. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeDjango.css +0 -120
  140. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeEclipse.css +0 -128
  141. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeEmacs.css +0 -113
  142. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeFadeToGrey.css +0 -117
  143. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeMDUltra.css +0 -113
  144. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeMidnight.css +0 -113
  145. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeRDark.css +0 -113
  146. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCore.scss +0 -216
  147. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreDefault.scss +0 -2
  148. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreDjango.scss +0 -2
  149. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreEclipse.scss +0 -2
  150. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreEmacs.scss +0 -2
  151. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreFadeToGrey.scss +0 -2
  152. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreMDUltra.scss +0 -2
  153. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreMidnight.scss +0 -2
  154. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreRDark.scss +0 -2
  155. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeDefault.scss +0 -7
  156. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeDjango.scss +0 -36
  157. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeEclipse.scss +0 -48
  158. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeEmacs.scss +0 -32
  159. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeFadeToGrey.scss +0 -36
  160. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeMDUltra.scss +0 -32
  161. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeMidnight.scss +0 -32
  162. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeRDark.scss +0 -32
  163. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_theme_template.scss +0 -120
  164. data/repository/syntaxhighlighter/shAutoloader.js +0 -17
  165. data/repository/syntaxhighlighter/shBrushAS3.js +0 -59
  166. data/repository/syntaxhighlighter/shBrushAppleScript.js +0 -75
  167. data/repository/syntaxhighlighter/shBrushBash.js +0 -59
  168. data/repository/syntaxhighlighter/shBrushCSharp.js +0 -65
  169. data/repository/syntaxhighlighter/shBrushColdFusion.js +0 -100
  170. data/repository/syntaxhighlighter/shBrushCpp.js +0 -97
  171. data/repository/syntaxhighlighter/shBrushCss.js +0 -91
  172. data/repository/syntaxhighlighter/shBrushDelphi.js +0 -55
  173. data/repository/syntaxhighlighter/shBrushDiff.js +0 -41
  174. data/repository/syntaxhighlighter/shBrushErlang.js +0 -52
  175. data/repository/syntaxhighlighter/shBrushGroovy.js +0 -67
  176. data/repository/syntaxhighlighter/shBrushJScript.js +0 -52
  177. data/repository/syntaxhighlighter/shBrushJava.js +0 -57
  178. data/repository/syntaxhighlighter/shBrushJavaFX.js +0 -58
  179. data/repository/syntaxhighlighter/shBrushPerl.js +0 -72
  180. data/repository/syntaxhighlighter/shBrushPhp.js +0 -88
  181. data/repository/syntaxhighlighter/shBrushPlain.js +0 -33
  182. data/repository/syntaxhighlighter/shBrushPowerShell.js +0 -74
  183. data/repository/syntaxhighlighter/shBrushPython.js +0 -64
  184. data/repository/syntaxhighlighter/shBrushRuby.js +0 -55
  185. data/repository/syntaxhighlighter/shBrushSass.js +0 -94
  186. data/repository/syntaxhighlighter/shBrushScala.js +0 -51
  187. data/repository/syntaxhighlighter/shBrushSql.js +0 -66
  188. data/repository/syntaxhighlighter/shBrushVb.js +0 -56
  189. data/repository/syntaxhighlighter/shBrushXml.js +0 -69
  190. data/repository/syntaxhighlighter/shCore.js +0 -17
  191. data/repository/syntaxhighlighter/shLegacy.js +0 -17
@@ -1,33 +1,29 @@
1
1
  var spec = new QSpec('NinjsModule');
2
2
 
3
3
  spec.should('return the module when adding a module', function() {
4
- var test_app = new NinjsApplication('myapp');
5
- var module = test_app.add_module('mymod');
6
- equals(module, test_app.mymod, 'returns the module when adding a module');
4
+ var test_app = new NinjsApplication('myapp');
5
+ var module = test_app.add_module('mymod');
6
+ console.log(module);
7
+ equals(module, test_app.mymod, 'returns the module when adding a module');
7
8
  });
8
9
 
9
10
  spec.should("have the correct defaults", function() {
10
- var testapp = new NinjsApplication();
11
- testapp.add_module('testmodule');
12
-
13
- // properties
14
- ok(is_defined(testapp.testmodule.run_tests), 'testapp.testmodule.run_tests is defined');
15
- equals(testapp.testmodule.run_tests, false, 'testapp.testmodule.run_tests defaults to false');
16
- ok(is_defined(testapp.testmodule.data), "testapp.testmodule.data is defined");
17
- ok(is_defined(testapp.testmodule.name), 'testapp.testmodule.name is defined');
18
- equals(testapp.testmodule.name, 'testmodule', 'testapp.testmodule.name is correct');
19
- ok(is_defined(testapp.testmodule.tests), 'testapp.testmodule.tests is defined');
20
- ok(is_array(testapp.testmodule.tests), 'testapp.testmodule.tests is_array');
21
- ok(testapp.testmodule.tests.is_empty(), 'testapp.testmodule.tests is empty');
22
-
23
- // methods
24
- ok(is_defined(testapp.testmodule.actions), 'testapp.testmodule.actions is defined');
25
- ok(is_typeof(Function, testapp.testmodule.actions), "testapp.testmodule.actions is a valid Function");
26
- ok(is_defined(testapp.testmodule.run), 'testapp.testmodule.run is defined');
27
- ok(is_typeof(Function, testapp.testmodule.run), "testapp.testmodule.run is a valid Function");
28
- ok(is_defined(testapp.testmodule.execute), 'testmodule.testapp.execute is defined');
29
- ok(is_defined(testapp.testmodule.elements), 'testapp.testmodule.elements is defined');
30
- ok(is_defined(testapp.testmodule.set_data), 'testapp.testmodule.set_data is defined');
11
+ var testapp = new NinjsApplication();
12
+ testapp.add_module('testmodule');
13
+
14
+ // properties
15
+ ok(is_defined(testapp.testmodule.data), "testapp.testmodule.data is defined");
16
+ ok(is_defined(testapp.testmodule.name), 'testapp.testmodule.name is defined');
17
+ equals(testapp.testmodule.name, 'testmodule', 'testapp.testmodule.name is correct');
18
+
19
+ // methods
20
+ ok(is_defined(testapp.testmodule.actions), 'testapp.testmodule.actions is defined');
21
+ ok(is_typeof(Function, testapp.testmodule.actions), "testapp.testmodule.actions is a valid Function");
22
+ ok(is_defined(testapp.testmodule.run), 'testapp.testmodule.run is defined');
23
+ ok(is_typeof(Function, testapp.testmodule.run), "testapp.testmodule.run is a valid Function");
24
+ ok(is_defined(testapp.testmodule.execute), 'testmodule.testapp.execute is defined');
25
+ ok(is_defined(testapp.testmodule.elements), 'testapp.testmodule.elements is defined');
26
+ ok(is_defined(testapp.testmodule.set_data), 'testapp.testmodule.set_data is defined');
31
27
  });
32
28
 
33
29
  spec.run_all();
@@ -35,41 +31,41 @@ spec.run_all();
35
31
  // Qunit waits for DOM to load before running tests
36
32
  // to test DOM wait feature, we need to run some code outside the tests
37
33
  (function() {
38
- var spec = new QSpec('NinjsModule');
39
-
40
- var testapp = new NinjsApplication();
41
- testapp.add_module('testmodule');
42
- testapp.testmodule.actions = function() {
43
- // append an element to be sure the DOM is ready for manipulation and test for the element's existence
44
- $('body').append('<div id="made-by-actions"/>');
45
-
46
- spec.should("run the module actions", function() {
47
- equals($('#made-by-actions').length, 1,'testapp.test.actions ran after DOM was ready');
48
- });
49
-
50
- spec.run_all();
51
- };
52
-
53
- testapp.testmodule.run();
34
+ var spec = new QSpec('NinjsModule');
35
+
36
+ var testapp = new NinjsApplication();
37
+ testapp.add_module('testmodule');
38
+ testapp.testmodule.actions = function() {
39
+ // append an element to be sure the DOM is ready for manipulation and test for the element's existence
40
+ $('body').append('<div id="made-by-actions"/>');
41
+
42
+ spec.should("run the module actions", function() {
43
+ equals($('#made-by-actions').length, 1,'testapp.test.actions ran after DOM was ready');
44
+ });
45
+
46
+ spec.run_all();
47
+ };
48
+
49
+ testapp.testmodule.run();
54
50
  }());
55
51
 
56
52
  // Qunit waits for DOM to load before running tests
57
53
  // to test DOM wait feature, we need to run some code outside the tests
58
54
  (function() {
59
- spec.should('set elements', function() {
60
- this.app = new NinjsApplication('myapp');
61
- var mod = this.app.add_module('mymod');
62
-
63
-
64
- mod.dom.ready(function() {
65
- mod.elements({
66
- body: $('body')
67
- });
68
-
69
- equals(mod.elements('body').length, 1, 'mod.elements("body") has length of 1');
70
- equals(mod.elements('body').text(), $('body').text(), 'mod.elements("body").text() = $("body").text()');
71
- });
72
- });
73
-
74
- spec.run_all();
55
+ spec.should('set elements', function() {
56
+ this.app = new NinjsApplication('myapp');
57
+ var mod = this.app.add_module('mymod');
58
+
59
+
60
+ mod.dom.ready(function() {
61
+ mod.elements({
62
+ body: $('body')
63
+ });
64
+
65
+ equals(mod.elements('body').length, 1, 'mod.elements("body") has length of 1');
66
+ equals(mod.elements('body').text(), $('body').text(), 'mod.elements("body").text() = $("body").text()');
67
+ });
68
+ });
69
+
70
+ spec.run_all();
75
71
  }());
@@ -1,12 +1,12 @@
1
- Array.method('is_empty', function() {
1
+ Array.prototype.is_empty = function() {
2
2
  return is_empty(this);
3
- });
3
+ };
4
4
 
5
- Array.method('not_empty', function() {
5
+ Array.prototype.not_empty = function() {
6
6
  return is_not_empty(this);
7
- });
7
+ };
8
8
 
9
- Array.method('each', function(callback) {
9
+ Array.prototype.each = function(callback) {
10
10
  if(is_undefined(callback)) {
11
11
  throw new SyntaxError("Array.each(callback): callback is undefined");
12
12
  }
@@ -15,9 +15,9 @@ Array.method('each', function(callback) {
15
15
  var args = [this[i], i];
16
16
  callback.apply(this, args);
17
17
  }
18
- });
18
+ };
19
19
 
20
- Array.method('contains', function(suspect) {
20
+ Array.prototype.contains = function(suspect) {
21
21
  var matches = [];
22
22
  this.each(function(value, index) {
23
23
  if(value === suspect) {
@@ -26,4 +26,4 @@ Array.method('contains', function(suspect) {
26
26
  });
27
27
 
28
28
  return matches.not_empty() ? matches : false;
29
- });
29
+ };
@@ -0,0 +1,59 @@
1
+ var Cookie = function(name, data, exp) {
2
+ if (is_undefined(name)) {
3
+ throw new SyntaxError('new Cookie(name, data[, exp]): name is undefined');
4
+ }
5
+
6
+ function set_exp(days) {
7
+ var date = new Date();
8
+ date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
9
+ var expires = "; expires=" + date.toGMTString();
10
+ }
11
+
12
+ this.name = name;
13
+
14
+ unless(this.read(), function() {
15
+ if (is_undefined(data)) {
16
+ this.data = '';
17
+ }
18
+ else {
19
+ this.data = data;
20
+ }
21
+
22
+ if (is_defined(days)) {
23
+ this.exp = set_exp(days);
24
+ }
25
+ else {
26
+ this.exp = '';
27
+ }
28
+ });
29
+
30
+ this.save();
31
+ };
32
+
33
+ Cookie.prototype.save = function() {
34
+ document.cookie = this.name + "=" + this.data + this.exp + "; path=/";
35
+ };
36
+
37
+ Cookie.prototype.read = function() {
38
+ var nameEQ = this.name + "=";
39
+ var ca = document.cookie.split(';');
40
+ var length = ca.length;
41
+
42
+ for (var i = 0; i < length; i++) {
43
+ var c = ca[i];
44
+ while (c.charAt(0) == ' ') {
45
+ c = c.substring(1, c.length);
46
+ }
47
+ if (c.indexOf(nameEQ) === 0) {
48
+ return c.substring(nameEQ.length,c.length);
49
+ }
50
+ }
51
+
52
+ return null;
53
+ };
54
+
55
+ Cookie.prototype.remove = function() {
56
+ this.data = '';
57
+ this.exp = -1;
58
+ this.save();
59
+ };
@@ -10,7 +10,7 @@ CSS.rgb2hex = function(r,g,b) {
10
10
  else {
11
11
  rgb = false;
12
12
  }
13
-
13
+
14
14
  if (rgb) {
15
15
  r = parseInt(rgb[0], 10);
16
16
  g = parseInt(rgb[1], 10);
@@ -26,26 +26,26 @@ CSS.rgb2hex = function(r,g,b) {
26
26
 
27
27
  CSS.hex2rgb = function(hex) {
28
28
  hex = hex.replace('#', '');
29
-
29
+
30
30
  var rgb = [];
31
-
31
+
32
32
  rgb[0] = parseInt(hex.substring(0,2), 16);
33
33
  rgb[1] = parseInt(hex.substring(2,4), 16);
34
34
  rgb[2] = parseInt(hex.substring(4,6), 16);
35
-
35
+
36
36
  rgb.red = rgb[0];
37
37
  rgb.green = rgb[1];
38
38
  rgb.blue = rgb[2];
39
-
39
+
40
40
  rgb.to_s = function() {
41
41
  return 'rgb(' + rgb.red +', ' + rgb.green + ', ' + rgb.blue + ')';
42
42
  };
43
-
43
+
44
44
  rgb.each = function(callback) {
45
45
  for (var i = 0; i < 3; i++) {
46
46
  callback.call(this, rgb[i]);
47
47
  }
48
48
  };
49
-
49
+
50
50
  return rgb;
51
51
  };
@@ -1,4 +1,4 @@
1
- Number.method('to_hex', function() {
1
+ Number.prototype.to_hex = function() {
2
2
  if (this === 0) {
3
3
  return "00";
4
4
  }
@@ -8,4 +8,4 @@ Number.method('to_hex', function() {
8
8
  n = Math.min(n, 255);
9
9
  n = Math.round(n);
10
10
  return chars.charAt((n - n % 16)/16) + chars.charAt(n % 16);
11
- });
11
+ };
@@ -1,29 +1,29 @@
1
- String.method('is_empty', function() {
1
+ String.prototype.is_empty = function() {
2
2
  return (this.length < 1) ? true : false;
3
- });
3
+ };
4
4
 
5
- String.method('not_empty', function() {
5
+ String.prototype.not_empty = function() {
6
6
  return (this.length < 1) ? false : true;
7
- });
7
+ };
8
8
 
9
- String.method('is_numeric', function() {
9
+ String.prototype.is_numeric = function() {
10
10
  var pattern = /^(\.|-)?\d+(?:\.\d*)?(?:e[+\-]?\d+)?$/i;
11
11
  return pattern.test(this);
12
- });
12
+ };
13
13
 
14
- String.method('trim', function() {
14
+ String.prototype.trim = function() {
15
15
  return this.replace(/^\s+|\s+$/g, "");
16
- });
16
+ };
17
17
 
18
- String.method('ltrim', function() {
18
+ String.prototype.ltrim = function() {
19
19
  return this.replace(/^\s+/,"");
20
- });
20
+ };
21
21
 
22
- String.method('rtrim', function() {
22
+ String.prototype.rtrim = function() {
23
23
  return this.replace(/\s+$/,"");
24
- });
24
+ };
25
25
 
26
- String.method('each', function(callback) {
26
+ String.prototype.each = function(callback) {
27
27
  if(is_undefined(callback)) {
28
28
  throw new SyntaxError("String.each(callback): callback is undefined");
29
29
  }
@@ -32,30 +32,30 @@ String.method('each', function(callback) {
32
32
  var args = [this.charAt(i), i];
33
33
  callback.apply(this, args);
34
34
  }
35
- });
35
+ };
36
36
 
37
- String.method('capitalize', function() {
37
+ String.prototype.capitalize = function() {
38
38
  return this.substr(0, 1).toUpperCase() + this.substr(1);
39
- });
39
+ };
40
40
 
41
- String.method('reverse', function() {
41
+ String.prototype.reverse = function() {
42
42
  return this.split('').reverse().join('');
43
- });
43
+ };
44
44
 
45
- String.method('to_n', function() {
45
+ String.prototype.to_n = function() {
46
46
  return parseFloat(this);
47
- });
47
+ };
48
48
 
49
- String.method('pluck', function(needle) {
49
+ String.prototype.pluck = function(needle) {
50
50
  var pattern = new RegExp(needle, 'g');
51
51
  return this.replace(pattern, '');
52
- });
52
+ };
53
53
 
54
- String.method('single_space', function() {
54
+ String.prototype.single_space = function() {
55
55
  var no_hard_spaces = this.replace(/\&nbsp\;/g, ' ');
56
56
  return no_hard_spaces.replace(/\s+/g, ' ');
57
- });
57
+ };
58
58
 
59
- String.method('compress', function() {
59
+ String.prototype.compress = function() {
60
60
  return this.replace(/\s+/g, '');
61
- });
61
+ };
data/spec/cli_spec.rb CHANGED
@@ -2,158 +2,160 @@ require 'spec_helper'
2
2
 
3
3
  describe 'CLI' do
4
4
  before :each do
5
- @bin = "#{File.expand_path('../bin')}/ninjs"
5
+ @bin = "#{Ninjs::BASE_DIR}/bin/ninjs"
6
6
  end
7
7
 
8
8
  after :each do
9
- FileUtils.rm_rf 'application'
10
- FileUtils.rm_rf 'modules'
11
- FileUtils.rm_rf 'elements'
12
- FileUtils.rm_rf 'models'
13
- FileUtils.rm_rf 'lib'
14
- FileUtils.rm_rf 'plugins'
15
- FileUtils.rm_rf 'tests'
16
- FileUtils.rm_rf 'ninjs.conf'
17
- FileUtils.rm_rf 'js' if File.exists? 'js'
9
+ FileUtils.rm_rf "#{SPEC_DIR}/application"
10
+ FileUtils.rm_rf "#{SPEC_DIR}/modules"
11
+ FileUtils.rm_rf "#{SPEC_DIR}/elements"
12
+ FileUtils.rm_rf "#{SPEC_DIR}/models"
13
+ FileUtils.rm_rf "#{SPEC_DIR}/lib"
14
+ FileUtils.rm_rf "#{SPEC_DIR}/plugins"
15
+ FileUtils.rm_rf "#{SPEC_DIR}/tests"
16
+ FileUtils.rm_rf "#{SPEC_DIR}/ninjs.conf"
17
+ FileUtils.rm_rf "#{SPEC_DIR}/js" if File.exists? "#{SPEC_DIR}/js"
18
18
  end
19
19
 
20
20
  it 'should create a new application' do
21
- suppress_output { `#{@bin} create myapp` }
21
+ suppress_output do
22
+ %x(cd #{SPEC_DIR}; #{@bin} create myapp)
23
+ end
22
24
 
23
- 'ninjs.conf'.should be_same_file_as 'fixtures/ninjs.conf'
25
+ "#{SPEC_DIR}/ninjs.conf".should be_same_file_as "#{SPEC_DIR}/fixtures/ninjs.conf"
24
26
 
25
- File.directory?("application").should be_true
26
- File.directory?("elements").should be_true
27
- File.directory?("lib").should be_true
28
- File.directory?("models").should be_true
29
- File.directory?("modules").should be_true
30
- File.directory?("plugins").should be_true
31
- File.directory?("tests").should be_true
27
+ File.directory?("#{SPEC_DIR}/application").should be_true
28
+ File.directory?("#{SPEC_DIR}/elements").should be_true
29
+ File.directory?("#{SPEC_DIR}/lib").should be_true
30
+ File.directory?("#{SPEC_DIR}/models").should be_true
31
+ File.directory?("#{SPEC_DIR}/modules").should be_true
32
+ File.directory?("#{SPEC_DIR}/plugins").should be_true
33
+ File.directory?("#{SPEC_DIR}/tests").should be_true
32
34
 
33
- File.exists?(File.expand_path("lib/nin.js")).should be_true
34
- File.exists?(File.expand_path("lib/utilities.js")).should be_true
35
+ File.exists?("#{SPEC_DIR}/lib/nin.js").should be_true
36
+ File.exists?("#{SPEC_DIR}/lib/utilities.js").should be_true
35
37
 
36
- File.exists?(File.expand_path("application/myapp.js")).should be_true
37
- application_file_content = File.open("application/myapp.js").readlines
38
+ File.exists?("#{SPEC_DIR}/application/myapp.js").should be_true
39
+ application_file_content = File.open("#{SPEC_DIR}/application/myapp.js").readlines
38
40
  application_file_content.shift
39
- application_file_content.join('').should == File.open('fixtures/myapp.initial.js').readlines.join('')
41
+ application_file_content.join('').should == File.open("#{SPEC_DIR}/fixtures/myapp.initial.js").readlines.join('')
40
42
 
41
- File.exists?(File.expand_path("tests")).should be_true
42
- File.exists?(File.expand_path("tests/index.html")).should be_true
43
- File.exists?(File.expand_path("tests/application.test.js")).should be_true
44
- File.exists?(File.expand_path("tests/array.utilities.test.js")).should be_true
45
- File.exists?(File.expand_path("tests/existence.test.js")).should be_true
46
- File.exists?(File.expand_path("tests/extension.test.js")).should be_true
47
- File.exists?(File.expand_path("tests/module.test.js")).should be_true
48
- File.exists?(File.expand_path("tests/qspec.js")).should be_true
49
- File.exists?(File.expand_path("tests/string.utilities.test.js")).should be_true
43
+ File.exists?("#{SPEC_DIR}/tests").should be_true
44
+ File.exists?("#{SPEC_DIR}/tests/index.html").should be_true
45
+ File.exists?("#{SPEC_DIR}/tests/application.test.js").should be_true
46
+ File.exists?("#{SPEC_DIR}/tests/array.utilities.test.js").should be_true
47
+ File.exists?("#{SPEC_DIR}/tests/existence.test.js").should be_true
48
+ File.exists?("#{SPEC_DIR}/tests/extension.test.js").should be_true
49
+ File.exists?("#{SPEC_DIR}/tests/module.test.js").should be_true
50
+ File.exists?("#{SPEC_DIR}/tests/qspec.js").should be_true
51
+ File.exists?("#{SPEC_DIR}/tests/string.utilities.test.js").should be_true
50
52
  end
51
53
 
52
54
  it 'should create a new application in a subdirectory' do
53
- suppress_output { `#{@bin} create myapp js` }
54
-
55
- 'js/ninjs.conf'.should be_same_file_as 'fixtures/ninjs.conf'
55
+ suppress_output { %x(cd #{SPEC_DIR} && #{@bin} create myapp js) }
56
+
57
+ "#{SPEC_DIR}/js/ninjs.conf".should be_same_file_as "#{SPEC_DIR}/fixtures/ninjs.conf"
56
58
 
57
- File.directory?("js/application").should be_true
58
- File.directory?("js/elements").should be_true
59
- File.directory?("js/lib").should be_true
60
- File.directory?("js/models").should be_true
61
- File.directory?("js/modules").should be_true
62
- File.directory?("js/plugins").should be_true
63
- File.directory?("js/tests").should be_true
59
+ File.directory?("#{SPEC_DIR}/js/application").should be_true
60
+ File.directory?("#{SPEC_DIR}/js/elements").should be_true
61
+ File.directory?("#{SPEC_DIR}/js/lib").should be_true
62
+ File.directory?("#{SPEC_DIR}/js/models").should be_true
63
+ File.directory?("#{SPEC_DIR}/js/modules").should be_true
64
+ File.directory?("#{SPEC_DIR}/js/plugins").should be_true
65
+ File.directory?("#{SPEC_DIR}/js/tests").should be_true
64
66
 
65
- File.exists?(File.expand_path("js/lib/nin.js")).should be_true
66
- File.exists?(File.expand_path("js/lib/utilities.js")).should be_true
67
+ File.exists?("#{SPEC_DIR}/js/lib/nin.js").should be_true
68
+ File.exists?("#{SPEC_DIR}/js/lib/utilities.js").should be_true
67
69
 
68
- File.exists?(File.expand_path("js/application/myapp.js")).should be_true
69
- application_file_content = File.open("js/application/myapp.js").readlines
70
+ File.exists?("#{SPEC_DIR}/js/application/myapp.js").should be_true
71
+ application_file_content = File.open("#{SPEC_DIR}/js/application/myapp.js").readlines
70
72
  application_file_content.shift
71
- application_file_content.join('').should == File.open('fixtures/myapp.initial.js').readlines.join('')
73
+ application_file_content.join('').should == File.open("#{SPEC_DIR}/fixtures/myapp.initial.js").readlines.join('')
72
74
 
73
- File.exists?(File.expand_path("js/tests")).should be_true
74
- File.exists?(File.expand_path("js/tests/index.html")).should be_true
75
- File.exists?(File.expand_path("js/tests/application.test.js")).should be_true
76
- File.exists?(File.expand_path("js/tests/array.utilities.test.js")).should be_true
77
- File.exists?(File.expand_path("js/tests/existence.test.js")).should be_true
78
- File.exists?(File.expand_path("js/tests/extension.test.js")).should be_true
79
- File.exists?(File.expand_path("js/tests/module.test.js")).should be_true
80
- File.exists?(File.expand_path("js/tests/qspec.js")).should be_true
81
- File.exists?(File.expand_path("js/tests/string.utilities.test.js")).should be_true
75
+ File.exists?("#{SPEC_DIR}/js/tests").should be_true
76
+ File.exists?("#{SPEC_DIR}/js/tests/index.html").should be_true
77
+ File.exists?("#{SPEC_DIR}/js/tests/application.test.js").should be_true
78
+ File.exists?("#{SPEC_DIR}/js/tests/array.utilities.test.js").should be_true
79
+ File.exists?("#{SPEC_DIR}/js/tests/existence.test.js").should be_true
80
+ File.exists?("#{SPEC_DIR}/js/tests/extension.test.js").should be_true
81
+ File.exists?("#{SPEC_DIR}/js/tests/module.test.js").should be_true
82
+ File.exists?("#{SPEC_DIR}/js/tests/qspec.js").should be_true
83
+ File.exists?("#{SPEC_DIR}/js/tests/string.utilities.test.js").should be_true
82
84
  end
83
85
 
84
86
  it 'should compile the application' do
85
- suppress_output { `#{@bin} create myapp` }
87
+ suppress_output { %x(cd #{SPEC_DIR} && #{@bin} create myapp) }
86
88
 
87
- FileUtils.cp 'fixtures/hello.module.js', File.expand_path('modules')
88
- FileUtils.cp 'fixtures/hello.elements.js', File.expand_path('elements')
89
- FileUtils.cp 'fixtures/hello.model.js', File.expand_path('models')
90
- FileUtils.cp 'fixtures/foo.module.js', File.expand_path('modules')
91
- FileUtils.cp 'fixtures/foo.elements.js', File.expand_path('elements')
92
- FileUtils.cp 'fixtures/foo.model.js', File.expand_path('models')
89
+ FileUtils.cp "#{SPEC_DIR}/fixtures/hello.module.js", "#{SPEC_DIR}/modules"
90
+ FileUtils.cp "#{SPEC_DIR}/fixtures/hello.elements.js", "#{SPEC_DIR}/elements"
91
+ FileUtils.cp "#{SPEC_DIR}/fixtures/hello.model.js", "#{SPEC_DIR}/models"
92
+ FileUtils.cp "#{SPEC_DIR}/fixtures/foo.module.js", "#{SPEC_DIR}/modules"
93
+ FileUtils.cp "#{SPEC_DIR}/fixtures/foo.elements.js", "#{SPEC_DIR}/elements"
94
+ FileUtils.cp "#{SPEC_DIR}/fixtures/foo.model.js", "#{SPEC_DIR}/models"
93
95
 
94
- suppress_output { `#{@bin} compile` }
96
+ suppress_output { %x(cd #{SPEC_DIR} && #{@bin} compile) }
95
97
 
96
- File.exists?('application/hello.js').should be_true
97
- File.exists?('application/foo.js').should be_true
98
+ File.exists?("#{SPEC_DIR}/application/hello.js").should be_true
99
+ File.exists?("#{SPEC_DIR}/application/foo.js").should be_true
98
100
  end
99
101
 
100
102
  it 'should update the application' do
101
- suppress_output { `#{@bin} create myapp` }
103
+ suppress_output { %x(cd #{SPEC_DIR} && #{@bin} create myapp) }
102
104
 
103
- File.open('lib/nin.js', 'w+') do |file|
105
+ File.open("#{SPEC_DIR}/lib/nin.js", 'w+') do |file|
104
106
  file << 'changed'
105
107
  end
106
108
 
107
- suppress_output { `#{@bin} update` }
109
+ suppress_output { %x(cd #{SPEC_DIR} && #{@bin} update) }
108
110
 
109
- 'lib/nin.js'.should be_same_file_as 'fixtures/nin.js'
111
+ "#{SPEC_DIR}/lib/nin.js".should be_same_file_as "#{SPEC_DIR}/fixtures/nin.js"
110
112
  end
111
113
 
112
114
  it 'should generate a module file' do
113
115
  suppress_output do
114
- `#{@bin} create myapp`
115
- `#{@bin} generate module mymodule`
116
+ %x(cd #{SPEC_DIR} && #{@bin} create myapp)
117
+ %x(cd #{SPEC_DIR} && #{@bin} generate module mymodule)
116
118
  end
117
119
 
118
- 'modules/mymodule.module.js'.should be_same_file_as 'fixtures/mymodule.module.js'
120
+ "#{SPEC_DIR}/modules/mymodule.module.js".should be_same_file_as "#{SPEC_DIR}/fixtures/mymodule.module.js"
119
121
  end
120
122
 
121
123
  it 'should generate a module file with an alias' do
122
124
  suppress_output do
123
- `#{@bin} create myapp`
124
- `#{@bin} generate module mymodule -a`
125
+ %x(cd #{SPEC_DIR} && #{@bin} create myapp)
126
+ %x(cd #{SPEC_DIR} && #{@bin} generate module mymodule -a)
125
127
  end
126
128
 
127
- 'modules/mymodule.module.js'.should be_same_file_as 'fixtures/mymodule.alias.module.js'
129
+ "#{SPEC_DIR}/modules/mymodule.module.js".should be_same_file_as "#{SPEC_DIR}/fixtures/mymodule.alias.module.js"
128
130
  end
129
131
 
130
132
  it 'should generate an elements file' do
131
133
  suppress_output do
132
- `#{@bin} create myapp`
133
- `#{@bin} generate elements mymodule`
134
+ %x(cd #{SPEC_DIR} && #{@bin} create myapp)
135
+ %x(cd #{SPEC_DIR} && #{@bin} generate elements mymodule)
134
136
  end
135
137
 
136
- 'elements/mymodule.elements.js'.should be_same_file_as 'fixtures/mymodule.elements.js'
138
+ "#{SPEC_DIR}/elements/mymodule.elements.js".should be_same_file_as "#{SPEC_DIR}/fixtures/mymodule.elements.js"
137
139
  end
138
140
 
139
141
  it 'should generate a model file' do
140
142
  suppress_output do
141
- `#{@bin} create myapp`
142
- `#{@bin} generate model mymodule`
143
+ %x(cd #{SPEC_DIR} && #{@bin} create myapp)
144
+ %x(cd #{SPEC_DIR} && #{@bin} generate model mymodule)
143
145
  end
144
146
 
145
- 'models/mymodule.model.js'.should be_same_file_as 'fixtures/mymodule.model.js'
147
+ "#{SPEC_DIR}/models/mymodule.model.js".should be_same_file_as "#{SPEC_DIR}/fixtures/mymodule.model.js"
146
148
  end
147
149
 
148
150
  it 'should generate a module file with dependencies' do
149
151
  suppress_output do
150
- `#{@bin} create myapp`
151
- `#{@bin} generate module mymodule -em`
152
+ %x(cd #{SPEC_DIR} && #{@bin} create myapp)
153
+ %x(cd #{SPEC_DIR} && #{@bin} generate module mymodule -em)
152
154
  end
153
155
 
154
- 'modules/mymodule.module.js'.should be_same_file_as 'fixtures/mymodule.dependencies.module.js'
155
- 'elements/mymodule.elements.js'.should be_same_file_as 'fixtures/mymodule.elements.js'
156
- 'models/mymodule.model.js'.should be_same_file_as 'fixtures/mymodule.model.js'
156
+ "#{SPEC_DIR}/modules/mymodule.module.js".should be_same_file_as "#{SPEC_DIR}/fixtures/mymodule.dependencies.module.js"
157
+ "#{SPEC_DIR}/elements/mymodule.elements.js".should be_same_file_as "#{SPEC_DIR}/fixtures/mymodule.elements.js"
158
+ "#{SPEC_DIR}/models/mymodule.model.js".should be_same_file_as "#{SPEC_DIR}/fixtures/mymodule.model.js"
157
159
  end
158
160
 
159
161
  end