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,6 +1,8 @@
1
1
  name: myapp
2
2
  src_dir: modules
3
3
  dest_dir: application
4
+ asset_root: ../ # relative to project root
4
5
  output: expanded
5
6
  dependencies: ['<jquery/latest>']
6
7
  autoload: ['../lib/utilities']
8
+ module_alias: mod
@@ -0,0 +1,8 @@
1
+ name: myapp
2
+ src_dir: modules
3
+ dest_dir: application
4
+ asset_root: . # relative to project root
5
+ output: expanded
6
+ dependencies: ['<jquery/latest>']
7
+ autoload: ['../lib/utilities']
8
+ module_alias: m
@@ -3,29 +3,29 @@ require "spec_helper"
3
3
  describe Ninjs::Generator do
4
4
  before :each do
5
5
  @config = {
6
- :project => Ninjs::Project.new('myapp'),
7
- :type => 'module',
8
- :name => 'mymodule',
9
- :alias => nil,
10
- :dest => 'application',
11
- :src => 'elements',
12
- :dependencies => { :elements => false, :model => false }
6
+ project: Ninjs::Project.new({ name: 'myapp', root: SPEC_DIR }),
7
+ type: 'module',
8
+ name: 'mymodule',
9
+ alias: nil,
10
+ dest: 'application',
11
+ src: 'elements',
12
+ dependencies: { elements: false, model: false }
13
13
  }
14
14
 
15
15
  @test_dirs = %w(modules elements models)
16
16
  @test_dirs.each do |dir|
17
- FileUtils.mkdir(dir)
17
+ FileUtils.mkdir("#{SPEC_DIR}/#{dir}")
18
18
  end
19
19
 
20
- File.open('ninjs.conf', 'w+') do |file|
21
- file << File.open('fixtures/ninjs.conf').readlines.join('')
20
+ File.open("#{SPEC_DIR}/ninjs.conf", 'w+') do |file|
21
+ file << File.open("#{SPEC_DIR}/fixtures/ninjs.conf").readlines.join('')
22
22
  end
23
23
  end
24
24
 
25
25
  after :each do
26
- FileUtils.rm_rf 'ninjs.conf'
26
+ FileUtils.rm_rf "#{SPEC_DIR}/ninjs.conf"
27
27
  @test_dirs.each do |dir|
28
- FileUtils.rm_rf dir
28
+ FileUtils.rm_rf "#{SPEC_DIR}/#{dir}"
29
29
  end
30
30
  end
31
31
 
@@ -33,7 +33,7 @@ describe Ninjs::Generator do
33
33
  generator = Ninjs::Generator.new(@config)
34
34
  suppress_output { generator.generate }
35
35
 
36
- 'modules/mymodule.module.js'.should be_same_file_as 'fixtures/mymodule.module.js'
36
+ "#{SPEC_DIR}/modules/mymodule.module.js".should be_same_file_as "#{SPEC_DIR}/fixtures/mymodule.module.js"
37
37
  end
38
38
 
39
39
  it 'should generate a module with an alias' do
@@ -43,7 +43,7 @@ describe Ninjs::Generator do
43
43
  generator = Ninjs::Generator.new(@config)
44
44
  suppress_output { generator.generate }
45
45
 
46
- 'modules/mymodule.module.js'.should be_same_file_as 'fixtures/mymodule.alias.module.js'
46
+ "#{SPEC_DIR}/modules/mymodule.module.js".should be_same_file_as "#{SPEC_DIR}/fixtures/mymodule.alias.module.js"
47
47
  end
48
48
 
49
49
  it 'should should generate an elements file' do
@@ -51,7 +51,7 @@ describe Ninjs::Generator do
51
51
  generator = Ninjs::Generator.new(@config)
52
52
  suppress_output { generator.generate }
53
53
 
54
- 'elements/mymodule.elements.js'.should be_same_file_as 'fixtures/mymodule.elements.js'
54
+ "#{SPEC_DIR}/elements/mymodule.elements.js".should be_same_file_as "#{SPEC_DIR}/fixtures/mymodule.elements.js"
55
55
  end
56
56
 
57
57
  it 'should should generate a model file' do
@@ -59,24 +59,35 @@ describe Ninjs::Generator do
59
59
  generator = Ninjs::Generator.new(@config)
60
60
  suppress_output { generator.generate }
61
61
 
62
- 'models/mymodule.model.js'.should be_same_file_as 'fixtures/mymodule.model.js'
62
+ "#{SPEC_DIR}/models/mymodule.model.js".should be_same_file_as "#{SPEC_DIR}/fixtures/mymodule.model.js"
63
63
  end
64
64
 
65
65
  it 'should generate a module file with dependencies' do
66
66
  generator = Ninjs::Generator.new({
67
- :project => Ninjs::Project.new('myapp'),
68
- :type => 'module',
69
- :name => 'mymodule',
70
- :alias => nil,
71
- :dest => 'application',
72
- :src => 'modules',
73
- :dependencies => { :elements => true, :model => true }
67
+ project: Ninjs::Project.new({ name: 'myapp', root: SPEC_DIR}),
68
+ type: 'module',
69
+ name: 'mymodule',
70
+ alias: nil,
71
+ dest: 'application',
72
+ src: 'modules',
73
+ dependencies: { elements: true, model: true }
74
74
  })
75
75
  suppress_output { generator.generate }
76
76
 
77
- 'modules/mymodule.module.js'.should be_same_file_as 'fixtures/mymodule.dependencies.module.js'
78
- 'elements/mymodule.elements.js'.should be_same_file_as 'fixtures/mymodule.elements.js'
79
- 'models/mymodule.model.js'.should be_same_file_as 'fixtures/mymodule.model.js'
77
+ "#{SPEC_DIR}/modules/mymodule.module.js".should be_same_file_as "#{SPEC_DIR}/fixtures/mymodule.dependencies.module.js"
78
+ "#{SPEC_DIR}/elements/mymodule.elements.js".should be_same_file_as "#{SPEC_DIR}/fixtures/mymodule.elements.js"
79
+ "#{SPEC_DIR}/models/mymodule.model.js".should be_same_file_as "#{SPEC_DIR}/fixtures/mymodule.model.js"
80
80
  end
81
81
 
82
+ it 'should generate a module file with a dynamic alias' do
83
+ new_conf = File.open("#{SPEC_DIR}/fixtures/updated.ninjs.conf", "r").readlines.join("")
84
+ File.open("#{SPEC_DIR}/ninjs.conf", "w+") do |file|
85
+ file << new_conf
86
+ end
87
+ @config[:project].config.read
88
+ generator = Ninjs::Generator.new(@config)
89
+ suppress_output { generator.generate }
90
+
91
+ "#{SPEC_DIR}/modules/mymodule.module.js".should be_same_file_as "#{SPEC_DIR}/fixtures/mymodule.module_alias.module.js"
92
+ end
82
93
  end
data/spec/ninjs_spec.rb CHANGED
@@ -1,16 +1,16 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Ninjs do
4
- it 'should have the correct BASE_DIR' do
5
- Ninjs::BASE_DIR.should == File.expand_path('../')
4
+ it 'should have a BASE_DIR constant' do
5
+ Ninjs::BASE_DIR.should_not be_nil
6
6
  end
7
7
 
8
- it 'should have the correct LIB_DIR' do
9
- Ninjs::LIB_DIR.should === File.expand_path('../lib')
8
+ it 'should have a LIB_DIR constant' do
9
+ Ninjs::LIB_DIR.should_not be_nil
10
10
  end
11
11
 
12
- it 'should have the correct ROOT_DIR' do
13
- Ninjs::ROOT_DIR.should === File.expand_path(Dir.getwd)
12
+ it 'should have a ROOT_DIR' do
13
+ Ninjs::ROOT_DIR.should_not be_nil
14
14
  end
15
15
 
16
16
  it 'should have the correct VERSION' do
data/spec/project_spec.rb CHANGED
@@ -1,243 +1,251 @@
1
1
  require "spec_helper.rb"
2
2
 
3
3
  describe Ninjs::Project do
4
+
4
5
  it "should exist" do
5
6
  Ninjs::Project.should_not be_nil
6
7
  end
7
-
8
+
8
9
  it "should have a @root setter method" do
9
- suppress_output { @project = Ninjs::Project.new 'myapp' }
10
- @project.root = File.expand_path(Dir.getwd)
11
- @project.root.should == File.expand_path(Dir.getwd)
10
+ suppress_output { @project = Ninjs::Project.new({ name: 'myapp' }) }
11
+ @project.root = SPEC_DIR
12
+ @project.root.should == SPEC_DIR
12
13
  end
13
-
14
+
14
15
  context 'Instantiation without an existing config file' do
15
16
  before :each do
16
- suppress_output { @project = Ninjs::Project.new 'myapp' }
17
+ suppress_output do
18
+ @project = Ninjs::Project.new({ name: 'myapp', root: SPEC_DIR })
19
+ end
17
20
  end
18
-
21
+
19
22
  after :each do
20
- File.delete 'ninjs.conf' if File.exists? 'ninjs.conf'
23
+ File.delete "#{SPEC_DIR}/ninjs.conf" if File.exists? "#{SPEC_DIR}/ninjs.conf"
21
24
  end
22
-
25
+
23
26
  it 'should raise an error if initialized without a name' do
24
- File.delete 'ninjs.conf' if File.exists? 'ninjs.conf'
25
- lambda{ project = Ninjs::Project.new }.should raise_error(ArgumentError)
26
- end
27
-
28
- it 'should have a root variable' do
29
- @project.root.should == File.expand_path(Dir.getwd)
30
- end
31
-
32
- it 'should have an empty modules array' do
33
- @project.modules.should == Array.new
34
- end
35
-
36
- it 'should have a config object' do
37
- @project.config.should_not be_nil
38
- end
39
-
40
- it 'should set the config.name property' do
41
- @project.config.name.should == 'myapp'
42
- end
43
- end
44
-
27
+ File.delete "#{SPEC_DIR}/ninjs.conf" if File.exists? "#{SPEC_DIR}/ninjs.conf"
28
+ lambda{ project = Ninjs::Project.new(root: SPEC_DIR) }.should raise_error(ArgumentError)
29
+ end
30
+
31
+ it 'should have a root variable' do
32
+ @project.root.should == SPEC_DIR
33
+ end
34
+
35
+ it 'should have an empty modules array' do
36
+ @project.modules.should == Array.new
37
+ end
38
+
39
+ it 'should have a config object' do
40
+ @project.config.should_not be_nil
41
+ end
42
+
43
+ it 'should set the config.name property' do
44
+ @project.config.name.should == 'myapp'
45
+ end
46
+ end # Instantiation without an existing config file
47
+
45
48
  context "Instantiation with an existing config file" do
46
- before :each do
47
- File.open File.expand_path("ninjs.conf"), 'w' do |file|
48
- file << %Q{name: something\noutput: expanded\ndependencies: ["<jquery/latest>"]\nautoload: ["../lib/utilities"]\nsrc_dir: classes\ndest_dir: compiled}
49
- end
50
- @project = Ninjs::Project.new
51
- end
52
-
53
- after :each do
54
- File.delete "ninjs.conf"
55
- end
56
-
57
- it 'should have a valid config object' do
58
- @project.config.should_not be_nil
59
- @project.config.name.should == 'something'
60
- @project.config.output.should == 'expanded'
61
- @project.config.dependencies.should == ["<jquery/latest>"]
62
- @project.config.autoload.should == ["../lib/utilities"]
63
- @project.config.src_dir.should == 'classes'
64
- @project.config.dest_dir.should == 'compiled'
65
- end
66
- end
49
+ before :each do
50
+ File.open "#{SPEC_DIR}/ninjs.conf", 'w' do |file|
51
+ file << %Q{name: something\noutput: expanded\ndependencies: ["<jquery/latest>"]\nautoload: ["../lib/utilities"]\nsrc_dir: classes\ndest_dir: compiled}
52
+ end
53
+
54
+ @project = Ninjs::Project.new({ root: SPEC_DIR })
55
+ end
56
+
57
+ after :each do
58
+ File.delete "#{SPEC_DIR}/ninjs.conf"
59
+ end
60
+
61
+ it 'should have a valid config object' do
62
+ @project.config.should_not be_nil
63
+ @project.config.name.should == 'something'
64
+ @project.config.output.should == 'expanded'
65
+ @project.config.dependencies.should == ["<jquery/latest>"]
66
+ @project.config.autoload.should == ["../lib/utilities"]
67
+ @project.config.src_dir.should == 'classes'
68
+ @project.config.dest_dir.should == 'compiled'
69
+ end
70
+ end # Instantiation with an existing config file
67
71
 
68
72
  context "Project Creation" do
69
- before :each do
70
- suppress_output do
71
- @project = Ninjs::Project.new 'myapp'
72
- @project.create_project_scaffold
73
- end
74
- end
75
-
76
- after :each do
77
- FileUtils.rm_rf "application"
78
- FileUtils.rm_rf "elements"
79
- FileUtils.rm_rf "lib"
80
- FileUtils.rm_rf "models"
81
- FileUtils.rm_rf "modules"
82
- FileUtils.rm_rf "plugins"
83
- FileUtils.rm_rf "tests"
84
- end
85
-
86
- it 'should create a project directory structure' do
87
- File.directory?("application").should be_true
88
- File.directory?("elements").should be_true
89
- File.directory?("lib").should be_true
90
- File.directory?("models").should be_true
91
- File.directory?("modules").should be_true
92
- File.directory?("plugins").should be_true
93
- File.directory?("tests").should be_true
94
- end
95
-
96
- it 'should create a ninjs lib file' do
97
- suppress_output { @project.create_ninjs_lib_file }
98
- File.exists?(File.expand_path("lib/nin.js")).should be_true
99
- 'lib/nin.js'.should be_same_file_as 'fixtures/nin.js'
100
- end
101
-
102
- it 'should create a utilities file' do
103
- suppress_output { @project.create_utility_lib_file }
104
- File.exists?(File.expand_path("lib/utilities.js")).should be_true
105
- end
106
-
107
- it 'should create an application file' do
108
- suppress_output do
109
- @project.create_ninjs_lib_file
110
- @project.create_ninjs_application_file
111
- end
112
-
113
- File.exists?(File.expand_path("application/myapp.js")).should be_true
114
- application_file_content = File.open("application/myapp.js").readlines
115
- application_file_content.shift
116
- application_file_content.join('').should == File.open('fixtures/myapp.initial.js').readlines.join('')
117
- end
118
-
119
- it 'should import test files' do
120
- suppress_output { @project.import_test_files }
121
-
122
- File.exists?(File.expand_path("tests")).should be_true
123
- File.exists?(File.expand_path("tests/index.html")).should be_true
124
- File.exists?(File.expand_path("tests/application.test.js")).should be_true
125
- File.exists?(File.expand_path("tests/array.utilities.test.js")).should be_true
126
- File.exists?(File.expand_path("tests/existence.test.js")).should be_true
127
- File.exists?(File.expand_path("tests/extension.test.js")).should be_true
128
- File.exists?(File.expand_path("tests/module.test.js")).should be_true
129
- File.exists?(File.expand_path("tests/qspec.js")).should be_true
130
- File.exists?(File.expand_path("tests/string.utilities.test.js")).should be_true
131
- end
132
- end
73
+ before :each do
74
+ suppress_output do
75
+ @project = Ninjs::Project.new({ name: 'myapp', root: SPEC_DIR })
76
+ @project.create_project_scaffold
77
+ end
78
+ end
79
+
80
+ after :each do
81
+ FileUtils.rm_rf "#{SPEC_DIR}/application"
82
+ FileUtils.rm_rf "#{SPEC_DIR}/elements"
83
+ FileUtils.rm_rf "#{SPEC_DIR}/lib"
84
+ FileUtils.rm_rf "#{SPEC_DIR}/models"
85
+ FileUtils.rm_rf "#{SPEC_DIR}/modules"
86
+ FileUtils.rm_rf "#{SPEC_DIR}/plugins"
87
+ FileUtils.rm_rf "#{SPEC_DIR}/tests"
88
+ end
89
+
90
+ it 'should create a project directory structure' do
91
+ File.directory?("#{SPEC_DIR}/application").should be_true
92
+ File.directory?("#{SPEC_DIR}/elements").should be_true
93
+ File.directory?("#{SPEC_DIR}/lib").should be_true
94
+ File.directory?("#{SPEC_DIR}/models").should be_true
95
+ File.directory?("#{SPEC_DIR}/modules").should be_true
96
+ File.directory?("#{SPEC_DIR}/plugins").should be_true
97
+ File.directory?("#{SPEC_DIR}/tests").should be_true
98
+ end
99
+
100
+ it 'should create a ninjs lib file' do
101
+ suppress_output { @project.create_ninjs_lib_file }
102
+ File.exists?("#{SPEC_DIR}/lib/nin.js").should be_true
103
+ "#{SPEC_DIR}/lib/nin.js".should be_same_file_as "#{SPEC_DIR}/fixtures/nin.js"
104
+ end
105
+
106
+ it 'should create a utilities file' do
107
+ suppress_output { @project.create_utility_lib_file }
108
+ File.exists?("#{SPEC_DIR}/lib/utilities.js").should be_true
109
+ end
110
+
111
+ it 'should create an application file' do
112
+ suppress_output do
113
+ @project.create_ninjs_lib_file
114
+ @project.create_ninjs_application_file
115
+ end
116
+
117
+ File.exists?("#{SPEC_DIR}/application/myapp.js").should be_true
118
+ application_file_content = File.open("#{SPEC_DIR}/application/myapp.js").readlines
119
+ application_file_content.shift
120
+ application_file_content.join('').should == File.open("#{SPEC_DIR}/fixtures/myapp.initial.js").readlines.join('')
121
+ end
122
+
123
+ it 'should import test files' do
124
+ suppress_output { @project.import_test_files }
125
+
126
+ File.exists?("#{SPEC_DIR}/tests").should be_true
127
+ File.exists?("#{SPEC_DIR}/tests/index.html").should be_true
128
+ File.exists?("#{SPEC_DIR}/tests/application.test.js").should be_true
129
+ File.exists?("#{SPEC_DIR}/tests/array.utilities.test.js").should be_true
130
+ File.exists?("#{SPEC_DIR}/tests/existence.test.js").should be_true
131
+ File.exists?("#{SPEC_DIR}/tests/extension.test.js").should be_true
132
+ File.exists?("#{SPEC_DIR}/tests/module.test.js").should be_true
133
+ File.exists?("#{SPEC_DIR}/tests/qspec.js").should be_true
134
+ File.exists?("#{SPEC_DIR}/tests/string.utilities.test.js").should be_true
135
+ end
136
+ end # Project Creation
133
137
 
134
138
  context 'Project management' do
135
- before :each do
136
- suppress_output do
137
- @project = Ninjs::Project.new 'myapp'
138
- @project.create
139
- end
140
-
141
- FileUtils.cp 'fixtures/hello.module.js', File.expand_path('modules')
142
- FileUtils.cp 'fixtures/hello.elements.js', File.expand_path('elements')
143
- FileUtils.cp 'fixtures/hello.model.js', File.expand_path('models')
144
- FileUtils.cp 'fixtures/foo.module.js', File.expand_path('modules')
145
- FileUtils.cp 'fixtures/foo.elements.js', File.expand_path('elements')
146
- FileUtils.cp 'fixtures/foo.model.js', File.expand_path('models')
147
- end
148
-
149
- after :each do
150
- FileUtils.rm_rf 'application'
151
- FileUtils.rm_rf 'modules'
152
- FileUtils.rm_rf 'elements'
153
- FileUtils.rm_rf 'models'
154
- FileUtils.rm_rf 'lib'
155
- FileUtils.rm_rf 'plugins'
156
- FileUtils.rm_rf 'tests'
157
- FileUtils.rm_rf 'ninjs.conf'
158
- end
159
-
160
- it 'should create a config file' do
161
- 'ninjs.conf'.should be_same_file_as 'fixtures/ninjs.conf'
162
- end
163
-
164
- it 'should get modules' do
165
- @project.get_modules
166
- @project.modules.should == [
167
- "/Volumes/Storage/Development/ninjs/spec/modules/foo.module.js",
168
- "/Volumes/Storage/Development/ninjs/spec/modules/hello.module.js"
169
- ]
170
- end
171
-
172
- it 'should compile a module' do
173
- @project.compile_module File.expand_path('modules/hello.module.js'), 'hello'
174
- File.exists?('application/hello.js').should be_true
175
- 'application/hello.js'.should be_same_file_as 'fixtures/hello.js'
176
- end
177
-
178
- it 'should add modules from a directory' do
179
- @project.add_scripts_to_models(File.expand_path('modules'))
180
-
181
- @project.modules.should == [
182
- '/Volumes/Storage/Development/ninjs/spec/modules/foo.module.js',
183
- '/Volumes/Storage/Development/ninjs/spec/modules/hello.module.js'
184
- ]
185
- end
186
-
187
- it 'should compile the modules' do
188
- @project.add_scripts_to_models(File.expand_path('modules'))
189
- @project.compile_modules
139
+ before :each do
140
+ suppress_output do
141
+ @project = Ninjs::Project.new({ name: 'myapp', root: SPEC_DIR })
142
+ @project.create
143
+ end
190
144
 
191
- 'application/hello.js'.should be_same_file_as 'fixtures/hello.js'
192
- 'application/foo.js'.should be_same_file_as 'fixtures/foo.js'
193
- end
194
-
195
- it 'should write the dependencies to a file' do
196
- FileUtils.touch 'dependencies.js'
197
-
198
- File.open(File.expand_path('dependencies.js'), 'w') do |file|
199
- @project.write_dependencies(file)
200
- end
201
-
202
- 'dependencies.js'.should be_same_file_as 'fixtures/dependencies.js'
203
-
204
- File.delete 'dependencies.js'
205
- end
206
-
207
- it 'should write the core to a file' do
208
- FileUtils.touch 'core.js'
209
-
210
- File.open('core.js', 'w') do |file|
211
- @project.write_core(file)
212
- end
213
-
214
- 'core.js'.should be_same_file_as 'fixtures/core.js'
215
-
216
- File.delete 'core.js'
217
- end
218
-
219
- it 'should write the autoloaded files to a file' do
220
- FileUtils.touch 'autoload.js'
221
-
222
- File.open('autoload.js', 'w') do |file|
223
- @project.write_autoload(file)
224
- end
225
-
226
- 'autoload.js'.should be_same_file_as 'fixtures/autoload.js'
227
-
228
- File.delete 'autoload.js'
229
- end
230
-
231
- it 'should update the application file' do
232
- suppress_output { @project.update_application_file }
233
- 'application/myapp.js'.should be_same_file_as 'fixtures/myapp.js'
234
- end
235
-
236
- it 'should compress an application' do
237
- @project.compress_application
238
- 'application/myapp.js'.should be_same_file_as 'fixtures/compressed.myapp.js'
239
- end
240
-
241
- end
145
+ FileUtils.cp "#{SPEC_DIR}/fixtures/hello.module.js", "#{SPEC_DIR}/modules"
146
+ FileUtils.cp "#{SPEC_DIR}/fixtures/hello.elements.js", "#{SPEC_DIR}/elements"
147
+ FileUtils.cp "#{SPEC_DIR}/fixtures/hello.model.js", "#{SPEC_DIR}/models"
148
+ FileUtils.cp "#{SPEC_DIR}/fixtures/foo.module.js", "#{SPEC_DIR}/modules"
149
+ FileUtils.cp "#{SPEC_DIR}/fixtures/foo.elements.js", "#{SPEC_DIR}/elements"
150
+ FileUtils.cp "#{SPEC_DIR}/fixtures/foo.model.js", "#{SPEC_DIR}/models"
151
+ FileUtils.cp "#{SPEC_DIR}/fixtures/_global.module.js", "#{SPEC_DIR}/modules"
152
+ end
153
+
154
+ after :each do
155
+ FileUtils.rm_rf "#{SPEC_DIR}/application"
156
+ FileUtils.rm_rf "#{SPEC_DIR}/modules"
157
+ FileUtils.rm_rf "#{SPEC_DIR}/elements"
158
+ FileUtils.rm_rf "#{SPEC_DIR}/models"
159
+ FileUtils.rm_rf "#{SPEC_DIR}/lib"
160
+ FileUtils.rm_rf "#{SPEC_DIR}/plugins"
161
+ FileUtils.rm_rf "#{SPEC_DIR}/tests"
162
+ FileUtils.rm_rf "#{SPEC_DIR}/ninjs.conf"
163
+ end
164
+
165
+ it 'should create a config file' do
166
+ "#{SPEC_DIR}/ninjs.conf".should be_same_file_as "#{SPEC_DIR}/fixtures/ninjs.conf"
167
+ end
168
+
169
+ it 'should get modules' do
170
+ @project.get_modules
171
+ @project.modules.include?("#{SPEC_DIR}/modules/foo.module.js").should be_true
172
+ @project.modules.include?("#{SPEC_DIR}/modules/hello.module.js").should be_true
173
+ end
174
+
175
+ it 'should compile a module' do
176
+ @project.compile_module "#{SPEC_DIR}/modules/hello.module.js", 'hello'
177
+ File.exists?("#{SPEC_DIR}/application/hello.js").should be_true
178
+ "#{SPEC_DIR}/application/hello.js".should be_same_file_as "#{SPEC_DIR}/fixtures/hello.js"
179
+ end
180
+
181
+ it 'should add modules from a directory' do
182
+ @project.add_scripts_to_models("#{SPEC_DIR}/modules")
183
+ @project.modules.include?("#{SPEC_DIR}/modules/foo.module.js").should be_true
184
+ @project.modules.include?("#{SPEC_DIR}/modules/hello.module.js").should be_true
185
+ end
186
+
187
+ it 'should compile the modules' do
188
+ @project.add_scripts_to_models("#{SPEC_DIR}/modules")
189
+ @project.compile_modules
190
+
191
+ "#{SPEC_DIR}/application/hello.js".should be_same_file_as "#{SPEC_DIR}/fixtures/hello.js"
192
+ "#{SPEC_DIR}/application/foo.js".should be_same_file_as "#{SPEC_DIR}/fixtures/foo.js"
193
+ end
194
+
195
+ it 'should not compile prefixed modules' do
196
+ @project.add_scripts_to_models("#{SPEC_DIR}/modules")
197
+ @project.compile_modules
198
+
199
+ File.exists?("#{SPEC_DIR}/application/_global.js").should_not be_true
200
+ end
201
+
202
+ it 'should write the dependencies to a file' do
203
+ FileUtils.touch "#{SPEC_DIR}/dependencies.js"
204
+
205
+ File.open("#{SPEC_DIR}/dependencies.js", 'w') do |file|
206
+ @project.write_dependencies(file)
207
+ end
208
+
209
+ "#{SPEC_DIR}/dependencies.js".should be_same_file_as "#{SPEC_DIR}/fixtures/dependencies.js"
210
+
211
+ File.delete "#{SPEC_DIR}/dependencies.js"
212
+ end
213
+
214
+ it 'should write the core to a file' do
215
+ FileUtils.touch "#{SPEC_DIR}/core.js"
216
+
217
+ File.open("#{SPEC_DIR}/core.js", 'w') do |file|
218
+ @project.write_core(file)
219
+ end
220
+
221
+ "#{SPEC_DIR}/core.js".should be_same_file_as "#{SPEC_DIR}/fixtures/core.js"
222
+
223
+ File.delete "#{SPEC_DIR}/core.js"
224
+ end
225
+
226
+ it 'should write the autoloaded files to a file' do
227
+ FileUtils.touch "#{SPEC_DIR}/autoload.js"
228
+
229
+ File.open("#{SPEC_DIR}/autoload.js", 'w') do |file|
230
+ @project.write_autoload(file)
231
+ end
232
+
233
+ "#{SPEC_DIR}/autoload.js".should be_same_file_as "#{SPEC_DIR}/fixtures/autoload.js"
234
+
235
+ File.delete "#{SPEC_DIR}/autoload.js"
236
+ end
237
+
238
+ it 'should update the application file' do
239
+ suppress_output { @project.update_application_file }
240
+ "#{SPEC_DIR}/application/myapp.js".should be_same_file_as "#{SPEC_DIR}/fixtures/myapp.js"
241
+ end
242
+
243
+ it 'should compress an application' do
244
+ @project.config.dest_dir = 'spec/application'
245
+ @project.compress_application
246
+ "#{SPEC_DIR}/application/myapp.js".should be_same_file_as "#{SPEC_DIR}/fixtures/compressed.myapp.js"
247
+ end
248
+
249
+ end # Project management
242
250
 
243
251
  end