nibjs 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. data/CHANGELOG.md +11 -0
  2. data/Gemfile.lock +1 -1
  3. data/Manifest.txt +2 -1
  4. data/README.md +10 -0
  5. data/Rakefile +1 -1
  6. data/dist/nibjs-1.0.0.js +74 -0
  7. data/dist/nibjs-1.0.0.min.js +7 -0
  8. data/dist/nibjs-1.1.0.js +74 -0
  9. data/dist/nibjs-1.1.0.min.js +7 -0
  10. data/examples/1-basic/basic.js +27 -0
  11. data/examples/1-basic/build +7 -0
  12. data/examples/1-basic/illustrate.png +0 -0
  13. data/examples/1-basic/index.html +56 -0
  14. data/examples/1-basic/lib/App.js +9 -0
  15. data/examples/1-basic/lib/StringUtils.js +7 -0
  16. data/examples/1-basic/lib/index.js +2 -0
  17. data/examples/2-coffee/build +7 -0
  18. data/examples/2-coffee/coffee.js +24 -0
  19. data/examples/2-coffee/illustrate.png +0 -0
  20. data/examples/2-coffee/index.html +57 -0
  21. data/examples/2-coffee/lib/App.coffee +9 -0
  22. data/examples/2-coffee/lib/StringUtils.coffee +6 -0
  23. data/examples/2-coffee/lib/index.coffee +2 -0
  24. data/examples/3-embedded-coffee/build +7 -0
  25. data/examples/3-embedded-coffee/embedded-coffee.coffee +25 -0
  26. data/examples/3-embedded-coffee/illustrate.png +0 -0
  27. data/examples/3-embedded-coffee/index.html +68 -0
  28. data/examples/3-embedded-coffee/lib/App.coffee +9 -0
  29. data/examples/3-embedded-coffee/lib/StringUtils.coffee +6 -0
  30. data/examples/3-embedded-coffee/lib/index.coffee +2 -0
  31. data/examples/4-coffee-join/build +7 -0
  32. data/examples/4-coffee-join/coffee-join.js +19 -0
  33. data/examples/4-coffee-join/illustrate.png +0 -0
  34. data/examples/4-coffee-join/index.html +55 -0
  35. data/examples/4-coffee-join/lib/App.coffee +7 -0
  36. data/examples/4-coffee-join/lib/StringUtils.coffee +6 -0
  37. data/examples/4-coffee-join/lib/index.coffee +2 -0
  38. data/examples/5-standalone/build +7 -0
  39. data/examples/5-standalone/illustrate.png +0 -0
  40. data/examples/5-standalone/index.html +52 -0
  41. data/examples/5-standalone/lib/App.coffee +7 -0
  42. data/examples/5-standalone/lib/StringUtils.coffee +6 -0
  43. data/examples/5-standalone/lib/index.coffee +2 -0
  44. data/examples/5-standalone/standalone.js +94 -0
  45. data/examples/README.md +43 -0
  46. data/examples/commons.rb +11 -0
  47. data/{test/integration/integration_test.rb → examples/handler.rb} +5 -12
  48. data/examples/illustrate.png +0 -0
  49. data/examples/illustrations.graffle +4382 -0
  50. data/examples/index.html +32 -0
  51. data/examples/public/TestSuite.coffee +43 -0
  52. data/examples/public/TestSuite.js +53 -0
  53. data/examples/public/coffee-script.js +8 -0
  54. data/examples/public/forkme.png +0 -0
  55. data/examples/public/leftnav.png +0 -0
  56. data/examples/public/leftnav_bw.png +0 -0
  57. data/examples/public/nibjs.js +74 -0
  58. data/examples/public/rightnav.png +0 -0
  59. data/examples/public/rightnav_bw.png +0 -0
  60. data/examples/public/style.css +82 -0
  61. data/examples/public/test-false.png +0 -0
  62. data/examples/public/test-pending.gif +0 -0
  63. data/examples/public/test-true.png +0 -0
  64. data/lib/nibjs/main.rb +104 -79
  65. data/lib/nibjs/version.rb +1 -1
  66. data/nibjs.noespec +1 -1
  67. data/src/nibjs.coffee +104 -107
  68. data/tasks/analytics.txt +10 -0
  69. data/tasks/examples.rake +25 -0
  70. data/tasks/gh-pages.rake +15 -0
  71. data/tasks/test.rake +2 -3
  72. data/test/command/footer.js +1 -0
  73. data/test/command/sc_coffee_6.exp +106 -0
  74. data/test/command/sc_coffee_7.exp +151 -0
  75. data/test/command/sc_common_6.exp +1 -0
  76. data/test/command/sc_common_7.exp +33 -0
  77. data/test/command/sc_common_8.exp +107 -0
  78. data/test/command/sc_common_9.exp +7 -0
  79. data/test/command/scenarios.rb +24 -0
  80. data/test/jasmine/assumption_spec.coffee +23 -0
  81. data/test/jasmine/nibjs_spec.coffee +14 -15
  82. data/test/nibjs.js +33 -33
  83. metadata +81 -14
  84. data/test/integration/index.html +0 -42
  85. data/test/integration/integration_test.coffee +0 -29
  86. data/test/integration/integration_test.js +0 -34
  87. data/test/integration/jquery-1.4.4.min.js +0 -167
@@ -0,0 +1,6 @@
1
+ exports.StringUtils = {
2
+
3
+ pre: (what)->
4
+ "<pre>#{what}</pre>"
5
+
6
+ }
@@ -0,0 +1,2 @@
1
+ exports.StringUtils = require('./StringUtils').StringUtils
2
+ exports.App = require('./App').App
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../commons', __FILE__)
3
+ here = File.dirname(__FILE__)
4
+ lib = File.join(here, 'lib')
5
+ options = %q{--coffee --no-coffee-compile --libname=embedded-coffee}
6
+ output = File.join(here, 'embedded-coffee.coffee')
7
+ nibjs(options, __output(output), lib)
@@ -0,0 +1,25 @@
1
+ NibJS.define 'embedded-coffee', (nibjs)->
2
+ nibjs.register './App', (exports, require)->
3
+ {StringUtils} = require('./StringUtils')
4
+
5
+ exports.App = {
6
+
7
+ runTests: ()->
8
+ $("body").append StringUtils.pre("Check 'nibjs --coffee --no-coffee-compile'")
9
+ true
10
+
11
+ }
12
+
13
+ nibjs.register './index', (exports, require)->
14
+ exports.StringUtils = require('./StringUtils').StringUtils
15
+ exports.App = require('./App').App
16
+
17
+ nibjs.register './StringUtils', (exports, require)->
18
+ exports.StringUtils = {
19
+
20
+ pre: (what)->
21
+ "<pre>#{what}</pre>"
22
+
23
+ }
24
+
25
+ nibjs.require './index'
@@ -0,0 +1,68 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
5
+ <title>NibJS - Embedded Coffee Example</title>
6
+
7
+ <!-- This is your application -->
8
+ <script src="http://code.jquery.com/jquery-1.5.min.js" type="text/javascript"></script>
9
+ <script src="../public/coffee-script.js" type="text/javascript"></script>
10
+ <script src="../public/nibjs.js" type="text/javascript"></script>
11
+ <script src="embedded-coffee.coffee" type="text/coffeescript"></script>
12
+ <script>
13
+ /* this is what we should have without coffeescript's issue 1054
14
+ https://github.com/jashkenas/coffee-script/issues/#issue/1054 */
15
+ function run(){
16
+ //
17
+ // this is how you require your application. App will now contain whatever
18
+ // your index.js has exported.
19
+ //
20
+ App = NibJS.require('embedded-coffee').App;
21
+
22
+ //
23
+ // Let me profit from your browser and run the integration tests :-)
24
+ //
25
+ TestSuite.runOne(App);
26
+ }
27
+
28
+ // this function will wait until the package has been built
29
+ function wait() {
30
+ try{ NibJS } catch (err){ setTimeout(wait, 100); return; }
31
+ if (NibJS.hasPackage('embedded-coffee')) {
32
+ run();
33
+ } else {
34
+ setTimeout(wait, 100);
35
+ }
36
+ }
37
+ $(document).ready(function(){ wait(); });
38
+ </script>
39
+
40
+ <!-- This is some to be able to run integration tests -->
41
+ <link rel="stylesheet" type="text/css" href="../public/style.css">
42
+ <script src="../public/TestSuite.js" type="text/javascript"></script>
43
+
44
+ </head>
45
+ <body>
46
+ <a id="forkme" href="http://github.com/blambeau/nib.js"></a>
47
+ <div id="content">
48
+ <div id="feedback"><img src="../public/test-pending.gif"/></div>
49
+ <h2>Or even embedding CoffeeScript directly in the browser!</h2>
50
+ <p class="comment">
51
+ In addition to the previous example, the coffeescript source of this example is compiled by the browser
52
+ instead of being prepared by nibjs at packaging time. This coffeescript/nibjs feature is useful when coffee
53
+ compiler is not easily available on the server.
54
+ </p>
55
+ <div style="text-align:center">
56
+ <img src="illustrate.png" width="80%">
57
+ </div>
58
+ <p class="comment">
59
+ Please be aware that making so is not really recommended for production use...
60
+ </p>
61
+ </div>
62
+ <div id="navigation">
63
+ <a href="../2-coffee/index.html" class="button" id="leftnav"></a>
64
+ <a href="../4-coffee-join/index.html" class="button" id="rightnav"></a>
65
+ <div style="clear:both"></div>
66
+ </div>
67
+ </body>
68
+ </html>
@@ -0,0 +1,9 @@
1
+ {StringUtils} = require('./StringUtils')
2
+
3
+ exports.App = {
4
+
5
+ runTests: ()->
6
+ $("body").append StringUtils.pre("Check 'nibjs --coffee --no-coffee-compile'")
7
+ true
8
+
9
+ }
@@ -0,0 +1,6 @@
1
+ exports.StringUtils = {
2
+
3
+ pre: (what)->
4
+ "<pre>#{what}</pre>"
5
+
6
+ }
@@ -0,0 +1,2 @@
1
+ exports.StringUtils = require('./StringUtils').StringUtils
2
+ exports.App = require('./App').App
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../commons', __FILE__)
3
+ here = File.dirname(__FILE__)
4
+ lib = File.join(here, 'lib')
5
+ options = %q{--coffee --join --libname=coffee-join}
6
+ output = File.join(here, 'coffee-join.js')
7
+ nibjs(options, __output(output), lib)
@@ -0,0 +1,19 @@
1
+ NibJS.define('coffee-join', function(nibjs) {
2
+ nibjs.register('./index', function(exports, require) {
3
+ var App, StringUtils;
4
+ App = {
5
+ runTests: function() {
6
+ $("body").append(StringUtils.pre("'nibjs --join' option is for you!"));
7
+ return true;
8
+ }
9
+ };
10
+ StringUtils = {
11
+ pre: function(what) {
12
+ return "<pre>" + what + "</pre>";
13
+ }
14
+ };
15
+ exports.StringUtils = StringUtils;
16
+ return exports.App = App;
17
+ });
18
+ return nibjs.require('./index');
19
+ });
@@ -0,0 +1,55 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
5
+ <title>NibJS - Join Example</title>
6
+
7
+ <!-- This is your application -->
8
+ <script src="http://code.jquery.com/jquery-1.5.min.js" type="text/javascript"></script>
9
+ <script src="../public/nibjs.js" type="text/javascript"></script>
10
+ <script src="coffee-join.js" type="text/javascript"></script>
11
+ <script>
12
+ $(document).ready(function(){
13
+ //
14
+ // this is how you require your application. App will now contain whatever
15
+ // your index.js has exported.
16
+ //
17
+ App = NibJS.require('coffee-join').App;
18
+ console.log(App);
19
+ //
20
+ // Let me profit from your browser and run the integration tests :-)
21
+ //
22
+ TestSuite.runOne(App);
23
+ });
24
+ </script>
25
+
26
+ <!-- This is some to be able to run integration tests -->
27
+ <link rel="stylesheet" type="text/css" href="../public/style.css">
28
+ <script src="../public/TestSuite.js" type="text/javascript"></script>
29
+
30
+ </head>
31
+ <body>
32
+ <a id="forkme" href="http://github.com/blambeau/nib.js"></a>
33
+ <div id="content">
34
+ <div id="feedback"><img src="../public/test-pending.gif"/></div>
35
+ <h2>Do exports.XXX and require('./XXX') look painful?</h2>
36
+ <p class="comment">
37
+ Sometimes, you simply want to maintain your code source "as if it were in a single file"
38
+ but still splitting different features in different files... In that case, you would like
39
+ to avoid having to exports and require everything everytime.
40
+ </p>
41
+ <div style="text-align:center">
42
+ <img src="illustrate.png" width="80%">
43
+ </div>
44
+ <p class="comment">
45
+ This should only be used if your code 1) has no name clash accross different files and 2)
46
+ has no particular dependency order.
47
+ </p>
48
+ </div>
49
+ <div id="navigation">
50
+ <a href="../3-embedded-coffee/index.html" class="button" id="leftnav"></a>
51
+ <a href="../5-standalone/index.html" class="button" id="rightnav"></a>
52
+ <div style="clear:both"></div>
53
+ </div>
54
+ </body>
55
+ </html>
@@ -0,0 +1,7 @@
1
+ App = {
2
+
3
+ runTests: ()->
4
+ $("body").append StringUtils.pre("'nibjs --join' option is for you!")
5
+ true
6
+
7
+ }
@@ -0,0 +1,6 @@
1
+ StringUtils = {
2
+
3
+ pre: (what)->
4
+ "<pre>#{what}</pre>"
5
+
6
+ }
@@ -0,0 +1,2 @@
1
+ exports.StringUtils = StringUtils
2
+ exports.App = App
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../commons', __FILE__)
3
+ here = File.dirname(__FILE__)
4
+ lib = File.join(here, 'lib')
5
+ options = %q{--coffee --join --standalone --libname=standalone}
6
+ output = File.join(here, 'standalone.js')
7
+ nibjs(options, __output(output), lib)
@@ -0,0 +1,52 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
5
+ <title>NibJS - Join Example</title>
6
+
7
+ <!-- This is your application -->
8
+ <script src="http://code.jquery.com/jquery-1.5.min.js" type="text/javascript"></script>
9
+ <script src="standalone.js" type="text/javascript"></script>
10
+ <script>
11
+ $(document).ready(function(){
12
+ //
13
+ // this is how you require your application. App will now contain whatever
14
+ // your index.js has exported.
15
+ //
16
+ App = NibJS.require('standalone').App;
17
+ console.log(App);
18
+ //
19
+ // Let me profit from your browser and run the integration tests :-)
20
+ //
21
+ TestSuite.runOne(App);
22
+ });
23
+ </script>
24
+
25
+ <!-- This is some to be able to run integration tests -->
26
+ <link rel="stylesheet" type="text/css" href="../public/style.css">
27
+ <script src="../public/TestSuite.js" type="text/javascript"></script>
28
+
29
+ </head>
30
+ <body>
31
+ <a id="forkme" href="http://github.com/blambeau/nib.js"></a>
32
+ <div id="content">
33
+ <div id="feedback"><img src="../public/test-pending.gif"/></div>
34
+ <h2>Your users don't even need NibJS as runtime dependency!</h2>
35
+ <p class="comment">
36
+ By default, you need to include <code>nibjs.js</code> to your webpage in order
37
+ to implement the CommonJS module specification. However if you plan to redistribute
38
+ your library, having NibJS as dependency may not be friendly for your own users.
39
+ </p>
40
+ <div style="text-align:center">
41
+ <img src="illustrate.png" width="80%">
42
+ </div>
43
+ <p class="comment">
44
+ In that case packaging a self-contained .js file containing NibJS itself makes sense:
45
+ </p>
46
+ </div>
47
+ <div id="navigation">
48
+ <a href="../4-coffee-join/index.html" class="button" id="leftnav"></a>
49
+ <div style="clear:both"></div>
50
+ </div>
51
+ </body>
52
+ </html>
@@ -0,0 +1,7 @@
1
+ App = {
2
+
3
+ runTests: ()->
4
+ $("body").append StringUtils.pre("This is why 'nibjs --standalone' exists!")
5
+ true
6
+
7
+ }
@@ -0,0 +1,6 @@
1
+ StringUtils = {
2
+
3
+ pre: (what)->
4
+ "<pre>#{what}</pre>"
5
+
6
+ }
@@ -0,0 +1,2 @@
1
+ exports.StringUtils = StringUtils
2
+ exports.App = App
@@ -0,0 +1,94 @@
1
+ /**
2
+ * nib.js - [Java/Coffee]script application packager from node.js conventions
3
+ *
4
+ * Copyright 2011, Bernard Lambeau
5
+ * Released under the MIT License
6
+ * http://github.com/blambeau/nib.js
7
+ */
8
+ (function(exports){
9
+ var Builder, Exception;
10
+ var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
11
+ for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
12
+ function ctor() { this.constructor = child; }
13
+ ctor.prototype = parent.prototype;
14
+ child.prototype = new ctor;
15
+ child.__super__ = parent.prototype;
16
+ return child;
17
+ }, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
18
+ exports.NibJS = {
19
+ pkgBuilders: [],
20
+ packages: [],
21
+ hasPackage: function(name) {
22
+ return (NibJS.pkgBuilders[name] != null) || (NibJS.packages[name] != null);
23
+ },
24
+ define: function(name, buildFn) {
25
+ return NibJS.pkgBuilders[name] = buildFn;
26
+ },
27
+ require: function(name) {
28
+ var _base, _ref;
29
+ return (_ref = (_base = NibJS.packages)[name]) != null ? _ref : _base[name] = NibJS._build_one(name);
30
+ },
31
+ _build_one: function(name) {
32
+ var builder;
33
+ if (NibJS.pkgBuilders[name]) {
34
+ builder = new Builder;
35
+ return NibJS.pkgBuilders[name](builder);
36
+ } else {
37
+ throw new Exception("NibJS error: no module '" + name + "' has been previously registered.");
38
+ }
39
+ }
40
+ };
41
+ Exception = (function() {
42
+ __extends(Exception, Error);
43
+ function Exception(message) {
44
+ this.message = message;
45
+ }
46
+ return Exception;
47
+ })();
48
+ Builder = (function() {
49
+ function Builder() {
50
+ this.build_file = __bind(this.build_file, this);;
51
+ this.require = __bind(this.require, this);;
52
+ this.register = __bind(this.register, this);; this.builders = [];
53
+ this.built = [];
54
+ }
55
+ Builder.prototype.register = function(file, builder) {
56
+ return this.builders[file] = builder;
57
+ };
58
+ Builder.prototype.require = function(file) {
59
+ var _base, _ref;
60
+ return (_ref = (_base = this.built)[file]) != null ? _ref : _base[file] = this.build_file(file);
61
+ };
62
+ Builder.prototype.build_file = function(file) {
63
+ var file_exp;
64
+ if (this.builders[file] != null) {
65
+ file_exp = {};
66
+ this.builders[file](file_exp, this.require);
67
+ return file_exp;
68
+ } else {
69
+ throw new Exception("NibJS error: no such file " + file);
70
+ }
71
+ };
72
+ return Builder;
73
+ })();
74
+ }).call(this, this);
75
+
76
+ NibJS.define('standalone', function(nibjs) {
77
+ nibjs.register('./index', function(exports, require) {
78
+ var App, StringUtils;
79
+ App = {
80
+ runTests: function() {
81
+ $("body").append(StringUtils.pre("This is why 'nibjs --standalone' exists!"));
82
+ return true;
83
+ }
84
+ };
85
+ StringUtils = {
86
+ pre: function(what) {
87
+ return "<pre>" + what + "</pre>";
88
+ }
89
+ };
90
+ exports.StringUtils = StringUtils;
91
+ return exports.App = App;
92
+ });
93
+ return nibjs.require('./index');
94
+ });
@@ -0,0 +1,43 @@
1
+ # NibJS - Examples
2
+
3
+ This folder contains typical use cases in using nib.js, one in each subfolder.
4
+ Each example is self-contained, and respects the following folder structure:
5
+
6
+ x-example/
7
+ build # run to (re-)build the example
8
+ example.js # generated by build using nibjs command
9
+ index.html # to be opened in your prefered browser
10
+ lib/
11
+ ... # java/coffee script source files
12
+
13
+ Examples are kept built in the sources, so that they can be executed immediately
14
+ in a browser. In other words, opening any x-example/index.html file in a browser
15
+ should work. Otherwise, please report the bug on github.
16
+
17
+ Please report any error on "github":https://github.com/blambeau/nib.js/issues
18
+
19
+ ## 1-basic
20
+
21
+ Demonstrates a simple use case where you maintain an application as well as some
22
+ utility modules and compile them as a single self-contained .js file ready for
23
+ inclusion in the browser (you don't even need to include nibjs itself in your
24
+ html file). NibJS is invoked as follows (see 1-basic/build):
25
+
26
+ nibjs --libname=basic --standalone --output=basic.js lib
27
+
28
+ ## 2-coffee
29
+
30
+ Same as the previous example, but written in coffeescript. NibJS invocation:
31
+
32
+ nibjs --coffee --libname=coffee --standalone --output=coffee.js lib
33
+
34
+ ## Credits
35
+
36
+ Icons used in examples are from www.veryicon.com, distributed under LGPL
37
+ licence with following licence information:
38
+
39
+ TITLE: Crystal Project Icons
40
+ AUTHOR: Everaldo Coelho
41
+ SITE: http://www.everaldo.com
42
+ CONTACT: everaldo@everaldo.com
43
+ LICENSE: LGPL