ninjs 0.13.8 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/VERSION +1 -1
  2. data/bin/ninjs +2 -1
  3. data/lib/ninjs/command.rb +1 -1
  4. data/lib/ninjs/generator.rb +14 -10
  5. data/lib/ninjs/project.rb +7 -4
  6. data/ninjs.gemspec +20 -7
  7. data/repository/ninjs/core/application.js +24 -43
  8. data/repository/ninjs/core/dom.js +139 -0
  9. data/repository/ninjs/core/existence.js +121 -277
  10. data/repository/ninjs/core/extend.js +35 -77
  11. data/repository/ninjs/core/module.js +101 -116
  12. data/repository/ninjs/core/nin.js +7 -4
  13. data/repository/ninjs/tests/application.test.js +24 -0
  14. data/repository/ninjs/tests/array.utilities.test.js +55 -0
  15. data/repository/ninjs/tests/existence.test.js +64 -0
  16. data/repository/ninjs/tests/extension.test.js +38 -0
  17. data/repository/ninjs/tests/index.html +11 -5
  18. data/repository/ninjs/tests/module.test.js +75 -0
  19. data/repository/ninjs/tests/qspec.js +26 -0
  20. data/repository/ninjs/tests/{ninjs.utilities.test.js → string.utilities.test.js} +14 -66
  21. data/spec/cli_spec.rb +159 -0
  22. data/spec/command_spec.rb +226 -2
  23. data/spec/fixtures/compressed.myapp.js +40 -20
  24. data/spec/fixtures/myapp.initial.js +383 -488
  25. data/spec/fixtures/myapp.js +379 -484
  26. data/spec/fixtures/mymodule.alias.module.js +10 -0
  27. data/spec/fixtures/mymodule.dependencies.module.js +13 -0
  28. data/spec/fixtures/mymodule.elements.js +5 -0
  29. data/spec/fixtures/mymodule.model.js +3 -0
  30. data/spec/fixtures/mymodule.module.js +10 -0
  31. data/spec/fixtures/nin.js +428 -0
  32. data/spec/generator_spec.rb +58 -10
  33. data/spec/project_spec.rb +11 -7
  34. metadata +59 -9
  35. data/repository/ninjs/tests/ninjs.test.js +0 -188
  36. data/repository/ninjs/tests/qunit/qunit.css +0 -197
  37. data/repository/ninjs/tests/qunit/qunit.js +0 -1415
@@ -5,30 +5,78 @@ describe Ninjs::Generator do
5
5
  @config = {
6
6
  :project => Ninjs::Project.new('myapp'),
7
7
  :type => 'module',
8
- :name => 'mymod',
8
+ :name => 'mymodule',
9
9
  :alias => nil,
10
10
  :dest => 'application',
11
- :src => 'modules',
11
+ :src => 'elements',
12
12
  :dependencies => { :elements => false, :model => false }
13
13
  }
14
14
 
15
- @test_dirs = %w(application modules elements models)
15
+ @test_dirs = %w(modules elements models)
16
16
  @test_dirs.each do |dir|
17
17
  FileUtils.mkdir(dir)
18
18
  end
19
19
 
20
+ File.open('ninjs.conf', 'w+') do |file|
21
+ file << File.open('fixtures/ninjs.conf').readlines.join('')
22
+ end
20
23
  end
21
24
 
22
25
  after :each do
23
- FileUtils.rm('modules/mymod.module.js')
26
+ FileUtils.rm_rf 'ninjs.conf'
24
27
  @test_dirs.each do |dir|
25
- FileUtils.rmdir(dir)
28
+ FileUtils.rm_rf dir
26
29
  end
27
30
  end
28
31
 
29
- #it 'should should generate a module file' do
30
- # generator = Ninjs::Generator.new(@config)
31
- # generator.project.proj
32
- # generator.generate
33
- #end
32
+ it 'should should generate a module file' do
33
+ generator = Ninjs::Generator.new(@config)
34
+ suppress_output { generator.generate }
35
+
36
+ 'modules/mymodule.module.js'.should be_same_file_as 'fixtures/mymodule.module.js'
37
+ end
38
+
39
+ it 'should generate a module with an alias' do
40
+ @config[:type] = 'module'
41
+ @config[:alias] = 'app'
42
+
43
+ generator = Ninjs::Generator.new(@config)
44
+ suppress_output { generator.generate }
45
+
46
+ 'modules/mymodule.module.js'.should be_same_file_as 'fixtures/mymodule.alias.module.js'
47
+ end
48
+
49
+ it 'should should generate an elements file' do
50
+ @config[:type] = 'elements'
51
+ generator = Ninjs::Generator.new(@config)
52
+ suppress_output { generator.generate }
53
+
54
+ 'elements/mymodule.elements.js'.should be_same_file_as 'fixtures/mymodule.elements.js'
55
+ end
56
+
57
+ it 'should should generate a model file' do
58
+ @config[:type] = 'model'
59
+ generator = Ninjs::Generator.new(@config)
60
+ suppress_output { generator.generate }
61
+
62
+ 'models/mymodule.model.js'.should be_same_file_as 'fixtures/mymodule.model.js'
63
+ end
64
+
65
+ it 'should generate a module file with dependencies' do
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 }
74
+ })
75
+ suppress_output { generator.generate }
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'
80
+ end
81
+
34
82
  end
data/spec/project_spec.rb CHANGED
@@ -64,7 +64,7 @@ describe Ninjs::Project do
64
64
  @project.config.dest_dir.should == 'compiled'
65
65
  end
66
66
  end
67
-
67
+
68
68
  context "Project Creation" do
69
69
  before :each do
70
70
  suppress_output do
@@ -96,6 +96,7 @@ describe Ninjs::Project do
96
96
  it 'should create a ninjs lib file' do
97
97
  suppress_output { @project.create_ninjs_lib_file }
98
98
  File.exists?(File.expand_path("lib/nin.js")).should be_true
99
+ 'lib/nin.js'.should be_same_file_as 'fixtures/nin.js'
99
100
  end
100
101
 
101
102
  it 'should create a utilities file' do
@@ -117,16 +118,19 @@ describe Ninjs::Project do
117
118
 
118
119
  it 'should import test files' do
119
120
  suppress_output { @project.import_test_files }
121
+
120
122
  File.exists?(File.expand_path("tests")).should be_true
121
- File.exists?(File.expand_path("tests/qunit")).should be_true
122
123
  File.exists?(File.expand_path("tests/index.html")).should be_true
123
- File.exists?(File.expand_path("tests/ninjs.test.js")).should be_true
124
- File.exists?(File.expand_path("tests/ninjs.utilities.test.js")).should be_true
125
- File.exists?(File.expand_path("tests/qunit/qunit.js")).should be_true
126
- File.exists?(File.expand_path("tests/qunit/qunit.css")).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
127
131
  end
128
132
  end
129
-
133
+
130
134
  context 'Project management' do
131
135
  before :each do
132
136
  suppress_output do
metadata CHANGED
@@ -1,8 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ninjs
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.13.8
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 14
8
+ - 0
9
+ version: 0.14.0
6
10
  platform: ruby
7
11
  authors:
8
12
  - Dayton Nolan
@@ -10,7 +14,7 @@ autorequire:
10
14
  bindir: bin
11
15
  cert_chain: []
12
16
 
13
- date: 2011-06-02 00:00:00 -05:00
17
+ date: 2011-06-05 00:00:00 -05:00
14
18
  default_executable: ninjs
15
19
  dependencies:
16
20
  - !ruby/object:Gem::Dependency
@@ -20,6 +24,8 @@ dependencies:
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
23
29
  version: "0"
24
30
  type: :runtime
25
31
  prerelease: false
@@ -31,6 +37,8 @@ dependencies:
31
37
  requirements:
32
38
  - - ">="
33
39
  - !ruby/object:Gem::Version
40
+ segments:
41
+ - 0
34
42
  version: "0"
35
43
  type: :runtime
36
44
  prerelease: false
@@ -42,6 +50,10 @@ dependencies:
42
50
  requirements:
43
51
  - - "="
44
52
  - !ruby/object:Gem::Version
53
+ segments:
54
+ - 1
55
+ - 0
56
+ - 2
45
57
  version: 1.0.2
46
58
  type: :runtime
47
59
  prerelease: false
@@ -53,6 +65,8 @@ dependencies:
53
65
  requirements:
54
66
  - - ">="
55
67
  - !ruby/object:Gem::Version
68
+ segments:
69
+ - 0
56
70
  version: "0"
57
71
  type: :development
58
72
  prerelease: false
@@ -64,6 +78,10 @@ dependencies:
64
78
  requirements:
65
79
  - - ~>
66
80
  - !ruby/object:Gem::Version
81
+ segments:
82
+ - 1
83
+ - 0
84
+ - 0
67
85
  version: 1.0.0
68
86
  type: :development
69
87
  prerelease: false
@@ -75,6 +93,10 @@ dependencies:
75
93
  requirements:
76
94
  - - ~>
77
95
  - !ruby/object:Gem::Version
96
+ segments:
97
+ - 1
98
+ - 5
99
+ - 2
78
100
  version: 1.5.2
79
101
  type: :development
80
102
  prerelease: false
@@ -86,6 +108,8 @@ dependencies:
86
108
  requirements:
87
109
  - - ">="
88
110
  - !ruby/object:Gem::Version
111
+ segments:
112
+ - 0
89
113
  version: "0"
90
114
  type: :development
91
115
  prerelease: false
@@ -97,6 +121,8 @@ dependencies:
97
121
  requirements:
98
122
  - - ">="
99
123
  - !ruby/object:Gem::Version
124
+ segments:
125
+ - 0
100
126
  version: "0"
101
127
  type: :development
102
128
  prerelease: false
@@ -108,6 +134,8 @@ dependencies:
108
134
  requirements:
109
135
  - - ">="
110
136
  - !ruby/object:Gem::Version
137
+ segments:
138
+ - 0
111
139
  version: "0"
112
140
  type: :runtime
113
141
  prerelease: false
@@ -119,6 +147,8 @@ dependencies:
119
147
  requirements:
120
148
  - - ">="
121
149
  - !ruby/object:Gem::Version
150
+ segments:
151
+ - 0
122
152
  version: "0"
123
153
  type: :runtime
124
154
  prerelease: false
@@ -130,6 +160,8 @@ dependencies:
130
160
  requirements:
131
161
  - - ">="
132
162
  - !ruby/object:Gem::Version
163
+ segments:
164
+ - 0
133
165
  version: "0"
134
166
  type: :runtime
135
167
  prerelease: false
@@ -141,6 +173,8 @@ dependencies:
141
173
  requirements:
142
174
  - - ">="
143
175
  - !ruby/object:Gem::Version
176
+ segments:
177
+ - 0
144
178
  version: "0"
145
179
  type: :runtime
146
180
  prerelease: false
@@ -152,6 +186,8 @@ dependencies:
152
186
  requirements:
153
187
  - - ">="
154
188
  - !ruby/object:Gem::Version
189
+ segments:
190
+ - 0
155
191
  version: "0"
156
192
  type: :development
157
193
  prerelease: false
@@ -269,6 +305,7 @@ files:
269
305
  - repository/ninjs/core/.extend.pdoc.yaml
270
306
  - repository/ninjs/core/.nin.pdoc.yaml
271
307
  - repository/ninjs/core/application.js
308
+ - repository/ninjs/core/dom.js
272
309
  - repository/ninjs/core/existence.js
273
310
  - repository/ninjs/core/extend.js
274
311
  - repository/ninjs/core/module.js
@@ -334,11 +371,14 @@ files:
334
371
  - repository/ninjs/docs/search/VariablesT.html
335
372
  - repository/ninjs/docs/styles/main.css
336
373
  - repository/ninjs/extensions/jquery.elements.js
374
+ - repository/ninjs/tests/application.test.js
375
+ - repository/ninjs/tests/array.utilities.test.js
376
+ - repository/ninjs/tests/existence.test.js
377
+ - repository/ninjs/tests/extension.test.js
337
378
  - repository/ninjs/tests/index.html
338
- - repository/ninjs/tests/ninjs.test.js
339
- - repository/ninjs/tests/ninjs.utilities.test.js
340
- - repository/ninjs/tests/qunit/qunit.css
341
- - repository/ninjs/tests/qunit/qunit.js
379
+ - repository/ninjs/tests/module.test.js
380
+ - repository/ninjs/tests/qspec.js
381
+ - repository/ninjs/tests/string.utilities.test.js
342
382
  - repository/ninjs/utilities/all.js
343
383
  - repository/ninjs/utilities/array.js
344
384
  - repository/ninjs/utilities/cookie.js
@@ -414,6 +454,7 @@ files:
414
454
  - repository/syntaxhighlighter/shBrushXml.js
415
455
  - repository/syntaxhighlighter/shCore.js
416
456
  - repository/syntaxhighlighter/shLegacy.js
457
+ - spec/cli_spec.rb
417
458
  - spec/command_spec.rb
418
459
  - spec/configuration_spec.rb
419
460
  - spec/dependencies_spec.rb
@@ -432,7 +473,13 @@ files:
432
473
  - spec/fixtures/hello.module.js
433
474
  - spec/fixtures/myapp.initial.js
434
475
  - spec/fixtures/myapp.js
476
+ - spec/fixtures/mymodule.alias.module.js
477
+ - spec/fixtures/mymodule.dependencies.module.js
478
+ - spec/fixtures/mymodule.elements.js
479
+ - spec/fixtures/mymodule.model.js
480
+ - spec/fixtures/mymodule.module.js
435
481
  - spec/fixtures/new.ninjs.conf
482
+ - spec/fixtures/nin.js
436
483
  - spec/fixtures/ninjs.conf
437
484
  - spec/generator_spec.rb
438
485
  - spec/helpers_spec.rb
@@ -455,7 +502,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
455
502
  requirements:
456
503
  - - ">="
457
504
  - !ruby/object:Gem::Version
458
- hash: 733674287232464568
505
+ hash: -1421157254201770566
459
506
  segments:
460
507
  - 0
461
508
  version: "0"
@@ -464,15 +511,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
464
511
  requirements:
465
512
  - - ">="
466
513
  - !ruby/object:Gem::Version
514
+ segments:
515
+ - 0
467
516
  version: "0"
468
517
  requirements: []
469
518
 
470
519
  rubyforge_project: nowarning
471
- rubygems_version: 1.5.2
520
+ rubygems_version: 1.3.7
472
521
  signing_key:
473
522
  specification_version: 3
474
523
  summary: ninjs is a command line application to help you write clean, modular javascript applications.
475
524
  test_files:
525
+ - spec/cli_spec.rb
476
526
  - spec/command_spec.rb
477
527
  - spec/configuration_spec.rb
478
528
  - spec/dependencies_spec.rb
@@ -1,188 +0,0 @@
1
- module("existence tests");
2
-
3
- test("existence sanity check", function() {
4
- ok(is_defined !== undefined, 'is_defined is defined');
5
- ok(is_undefined !== undefined, 'is_undefined is defined');
6
- ok(is_typeof !== undefined, 'is_typeof is defined');
7
- });
8
-
9
- test("can test for existence", function() {
10
- var nonexistent;
11
- var existent = 'I think';
12
- equals(is_defined(existent), true, 'existent variable is_defined');
13
- equals(is_defined(nonexistent), false, 'non-existent variable does not exist');
14
- });
15
-
16
- test("can test for non-existence", function() {
17
- var existent = 'I think';
18
- var nonexistent;
19
- equals(is_undefined(nonexistent), true, 'non-existent variable does not exist');
20
- equals(is_undefined(existent), false, 'existent variable does exist');
21
- });
22
-
23
- test("can check the type strictly with is_typeof", function() {
24
- var foo = function(){};
25
- var bar = {
26
- name: 'SomeObject',
27
- method: function() {}
28
- };
29
- var SomeClass = function(){};
30
- var some_instance = new SomeClass();
31
- equals(is_typeof(Number, 4), true, 'can check against Number');
32
- equals(is_typeof(String, 'Hello World'), true, 'can check against String');
33
- equals(is_typeof(Array, ['one', 'two', 'three']), true, 'can check against Array');
34
- equals(is_typeof(Function, foo), true, 'can check against Function');
35
- equals(is_typeof(Object, bar), true, 'can check against Object');
36
- equals(is_typeof(RegExp, /pattern/), true, 'can check against Regexp');
37
- equals(is_typeof(SomeClass, some_instance), true, 'can check against custom object');
38
- });
39
-
40
- module("typeof proxys");
41
-
42
- test("can check for default types", function() {
43
- var today = new Date();
44
- var easy_as = [1,2,3];
45
- var pattern = new RegExp(/pattern/);
46
-
47
- ok(is_string('hello'), 'hello is_string');
48
- ok(is_number(42), '42 is_number');
49
- ok(is_array(easy_as), 'easy_as is_array');
50
- ok(is_bool(false), 'false is_bool');
51
- ok(is_date(today), 'today is_date');
52
- ok(is_regex(pattern), 'pattern is_regex');
53
-
54
- equals(is_regex('hello'), false, 'hello fails is_regex');
55
- equals(is_date(42), false, '42 fails is_date');
56
- equals(is_bool(easy_as), false, 'easy_as fails is_bool');
57
- equals(is_array(today), false, 'today fails is_array');
58
- equals(is_number(true), false, 'true fails is_number');
59
- equals(is_string(pattern), false, 'pattern fails is_string');
60
- });
61
-
62
- test("can determine a number", function() {
63
- ok(is_numeric(2), '2 is a number');
64
- ok(is_numeric(-2), '-2 is a number');
65
- ok(is_numeric(45.6), '45.6 is a number');
66
- ok(is_numeric(-45.6), '-45.6 is a number');
67
- equals(is_numeric('45.6'), true, "'45.6 is a number'");
68
- equals(is_numeric('Hello'), false, 'Hello is not a number');
69
- });
70
-
71
- module("extend tests");
72
-
73
- test("can add a method to the prototype", function() {
74
- ok(is_defined(Function.prototype.method), "Object.prototype.method is defined");
75
-
76
- String.method('test_method', function() {
77
- return 'This is a test';
78
- });
79
-
80
- equals('Hello'.test_method(), 'This is a test', 'can create a prototype method with method');
81
- });
82
-
83
- test("can test a condition with unless", function() {
84
- var is_true = false;
85
-
86
- unless (false,
87
- function() {
88
- is_true = true;
89
- }
90
- );
91
-
92
- ok(is_true, "unless works");
93
-
94
- var does_fallback_work = false;
95
-
96
- unless (true,
97
- function() {
98
-
99
- },
100
- function() {
101
- does_fallback_work = true;
102
- }
103
- );
104
-
105
- ok(does_fallback_work, 'fallback works');
106
- });
107
-
108
- module("Ninjs application tests");
109
-
110
- test("can create a ninjs application object", function() {
111
- var testapp = new NinjsApplication();
112
- ok(is_defined(testapp), 'testapp is defined');
113
- ok(is_typeof(NinjsApplication, testapp), 'testapp is a valid NinjsApplication');
114
- });
115
-
116
- test("can create a NinjsModule", function() {
117
- var testapp = new NinjsApplication();
118
- testapp.add_module('testmodule');
119
- ok(is_defined(testapp.testmodule), 'testapp.testmodule is defined');
120
- ok(is_typeof(NinjsModule, testapp.testmodule), 'testapp.testmodule is a valid NinjsModule');
121
- });
122
-
123
- module('Ninjs Module tests');
124
-
125
- test("module defaults", function() {
126
- var testapp = new NinjsApplication();
127
- testapp.add_module('testmodule');
128
-
129
- // properties
130
- ok(is_defined(testapp.testmodule.run_tests), 'testapp.testmodule.run_tests is defined');
131
- equals(testapp.testmodule.run_tests, false, 'testapp.testmodule.run_tests defaults to false');
132
- ok(is_defined(testapp.testmodule.data), "testapp.testmodule.data is defined");
133
- ok(is_defined(testapp.testmodule.name), 'testapp.testmodule.name is defined');
134
- equals(testapp.testmodule.name, 'testmodule', 'testapp.testmodule.name is correct');
135
- ok(is_defined(testapp.testmodule.tests), 'testapp.testmodule.tests is defined');
136
- ok(is_array(testapp.testmodule.tests), 'testapp.testmodule.tests is_array');
137
- ok(testapp.testmodule.tests.is_empty(), 'testapp.testmodule.tests is empty');
138
- ok(is_defined(app), 'app is defined');
139
-
140
- // methods
141
- ok(is_defined(testapp.testmodule.actions), 'testapp.testmodule.actions is defined');
142
- ok(is_typeof(Function, testapp.testmodule.actions), "testapp.testmodule.actions is a valid Function");
143
- ok(is_defined(testapp.testmodule.run), 'testapp.testmodule.run is defined');
144
- ok(is_typeof(Function, testapp.testmodule.run), "testapp.testmodule.run is a valid Function");
145
- ok(is_defined(testapp.testmodule.call_on_ready), 'testmodule.testapp.call_on_ready is defined');
146
- ok(is_defined(testapp.testmodule.execute), 'testmodule.testapp.execute is defined');
147
- ok(is_defined(testapp.testmodule.elements), 'testapp.testmodule.elements is defined');
148
- ok(is_defined(testapp.testmodule.set_data), 'testapp.testmodule.set_data is defined');
149
- });
150
-
151
- test("add_module returns the created module", function() {
152
- var testapp = new NinjsApplication();
153
- var module = testapp.add_module('some_module');
154
- equals(module, testapp.some_module, 'hey');
155
- });
156
-
157
- // Qunit waits for DOM to load before running tests
158
- // to test DOM wait feature, we need to run some code outside the tests
159
- (function() {
160
- var testapp = new NinjsApplication();
161
- testapp.add_module('testmodule');
162
- testapp.testmodule.actions = function() {
163
- // append an element to be sure the DOM is ready for manipulation and test for the element's existence
164
- $('body').append('<div id="made-by-actions"/>');
165
-
166
- test("Ninjs module can run actions", function() {
167
- equals($('#made-by-actions').length, 1,'testapp.test.actions ran after DOM was ready');
168
- });
169
- };
170
-
171
- testapp.testmodule.run();
172
- }());
173
-
174
- // Qunit waits for DOM to load before running tests
175
- // to test DOM wait feature, we need to run some code outside the tests
176
- (function() {
177
- var testapp = new NinjsApplication();
178
- testapp.add_module('testmodule');
179
- testapp.testmodule.elements(function() {
180
- testapp.testmodule.qunit_header = $('#qunit-header');
181
- testapp.testmodule.qunit_banner = $('#qunit-banner');
182
-
183
- test('Ninjs module can cache elements', function() {
184
- equals(testapp.testmodule.qunit_header[0].tagName, 'H1', '#qunit-header returns an h1');
185
- equals(testapp.testmodule.qunit_banner[0].tagName, 'H2', '#qunit-banner returns an h2');
186
- });
187
- });
188
- }());