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
@@ -2,7 +2,7 @@ module NibJS
2
2
  module Version
3
3
 
4
4
  MAJOR = 1
5
- MINOR = 0
5
+ MINOR = 1
6
6
  TINY = 0
7
7
 
8
8
  def self.to_s
@@ -14,7 +14,7 @@ variables:
14
14
  upper:
15
15
  NibJS
16
16
  version:
17
- 1.0.0
17
+ 1.1.0
18
18
  summary:
19
19
  nib.js - Package and embed node.js or coffeescript libraries in the browser
20
20
  description: |-
@@ -1,124 +1,121 @@
1
1
  exports.NibJS = {
2
2
 
3
- #
4
- # Package builders.
5
- #
6
- # Package builders are simply unary functions registered via NibJS.define.
7
- # These functions are expected to build the package thanks to a Builder
8
- # instance that they receive as first argument.
9
- #
10
- # @see define
11
- # @see Builder
12
- #
13
- pkgBuilders: []
3
+ #
4
+ # Package builders.
5
+ #
6
+ # Package builders are simply unary functions registered via NibJS.define.
7
+ # These functions are expected to build the package thanks to a Builder
8
+ # instance that they receive as first argument.
9
+ #
10
+ # @see define
11
+ # @see Builder
12
+ #
13
+ pkgBuilders: []
14
+
15
+ #
16
+ # Built packages.
17
+ #
18
+ # Once the package are built (lazily, at first 'require' invocation), the
19
+ # results is put in the following array for subsequent requiring.
20
+ #
21
+ packages: []
14
22
 
15
- #
16
- # Built packages.
17
- #
18
- # Once the package are built (lazily, at first 'require' invocation), the
19
- # results is put in the following array for subsequent requiring.
20
- #
21
- packages: []
23
+ #
24
+ # Checks if a package is known.
25
+ #
26
+ hasPackage: (name)->
27
+ NibJS.pkgBuilders[name]? || NibJS.packages[name]?
28
+
29
+ #
30
+ # Defines a package via a name and a builder function.
31
+ #
32
+ # Builder functions are expected to build the package thanks to a Builder
33
+ # instance received as first argument. They are expected to make the first
34
+ # require to the package index file.
35
+ #
36
+ # Example:
37
+ # NibJS.define('foo', function(nibjs){
38
+ # nibjs.register('bar', function(exports, require){
39
+ # /* content of bar.js comes here */
40
+ # });
41
+ # nibjs.register('index', function(exports, require){
42
+ # /* content of index.js come here */
43
+ # });
44
+ # /* Load the package at end */
45
+ # nibjs.require('index');
46
+ # });
47
+ #
48
+ define: (name, buildFn)->
49
+ NibJS.pkgBuilders[name] = buildFn
22
50
 
23
- #
24
- # Defines a package via a name and a builder function.
25
- #
26
- # Builder functions are expected to build the package thanks to a Builder
27
- # instance received as first argument. They are expected to make the first
28
- # require to the package index file.
29
- #
30
- # Example:
31
- # NibJS.define('foo', function(nibjs){
32
- # nibjs.register('bar', function(exports, require){
33
- # /* content of bar.js comes here */
34
- # });
35
- # nibjs.register('index', function(exports, require){
36
- # /* content of index.js come here */
37
- # });
38
- # /* Load the package at end */
39
- # nibjs.require('index');
40
- # });
41
- #
42
- define: (name, buildFn)->
43
- NibJS.pkgBuilders[name] = buildFn
51
+ #
52
+ # Returns a package, building it if required (equivalent to Node's _require_).
53
+ #
54
+ # Example:
55
+ # Foo = NibJS.require('foo')
56
+ # Foo.Bar = ...
57
+ #
58
+ require: (name)->
59
+ NibJS.packages[name] ?= NibJS._build_one(name)
44
60
 
45
- #
46
- # Returns a package, building it if required (equivalent to Node's _require_).
47
- #
48
- # Example:
49
- # Foo = NibJS.require('foo')
50
- # Foo.Bar = ...
51
- #
52
- require: (name)->
53
- NibJS.packages[name] ?= NibJS._build_one(name)
54
-
55
- #
56
- # Internal implementation of require, when invoked the first time on
57
- # a given library.
58
- #
59
- _build_one: (name)->
61
+ #
62
+ # Internal implementation of require, when invoked the first time on
63
+ # a given library.
64
+ #
65
+ _build_one: (name)->
66
+ if NibJS.pkgBuilders[name]
60
67
  builder = new Builder
61
68
  NibJS.pkgBuilders[name](builder)
69
+ else
70
+ throw new Exception("NibJS error: no module '#{name}' has been previously registered.")
62
71
 
63
- # Application control
64
- pending: []
72
+ }
65
73
 
66
- running: []
74
+ class Exception extends Error
75
+ constructor: (@message)->
67
76
 
68
- ready: (fn)->
69
- NibJS.pending.push(fn)
77
+ #
78
+ # Intra-package builder, passed as first argument of NibJS.define
79
+ #
80
+ # This builder helps registrering functions for building individual
81
+ # files, as well as requiring them.
82
+ #
83
+ class Builder
70
84
 
71
- start: ()->
72
- for fn in NibJS.pending
73
- NibJS.running.push(fn())
74
- NibJS.pending = []
75
-
76
- isRunning: (fn)->
77
- for c in NibJS.running
78
- return true if c is fn
79
- return false
80
-
81
- }
85
+ #
86
+ # Builds a builder instance
87
+ #
88
+ constructor: ()->
89
+ @builders = []
90
+ @built = []
82
91
 
83
92
  #
84
- # Intra-package builder, passed as first argument of NibJS.define
93
+ # Register a builder function for _file_.
85
94
  #
86
- # This builder helps registrering functions for building individual
87
- # files, as well as requiring them.
95
+ # The builder function will be called when the file will be required later.
96
+ # It takes two parameters as arguments, exports and require. The first one
97
+ # allows the file to exports artifacts while the second one mimics the
98
+ # Node's require function.
88
99
  #
89
- class Builder
100
+ register: (file, builder)=>
101
+ @builders[file] = builder
90
102
 
91
- #
92
- # Builds a builder instance
93
- #
94
- constructor: ()->
95
- @builders = []
96
- @built = []
97
-
98
- #
99
- # Register a builder function for _file_.
100
- #
101
- # The builder function will be called when the file will be required later.
102
- # It takes two parameters as arguments, exports and require. The first one
103
- # allows the file to exports artifacts while the second one mimics the
104
- # Node's require function.
105
- #
106
- register: (file, builder)=>
107
- @builders[file] = builder
103
+ #
104
+ # Mimics Node's require in the context of this building.
105
+ #
106
+ # This function returns the result of requiring _file_, building it with
107
+ # the function previously registered (if not previously done).
108
+ #
109
+ require: (file)=>
110
+ @built[file] ?= this.build_file(file)
108
111
 
109
- #
110
- # Mimics Node's require in the context of this building.
111
- #
112
- # This function returns the result of requiring _file_, building it with
113
- # the function previously registered (if not previously done).
114
- #
115
- require: (file)=>
116
- @built[file] ?= this.build_file(file)
117
-
118
- #
119
- # Private functions that ensures the building of a file.
120
- #
121
- build_file: (file)=>
122
- exports = {}
123
- @builders[file](exports, this.require)
124
- exports
112
+ #
113
+ # Private functions that ensures the building of a file.
114
+ #
115
+ build_file: (file)=>
116
+ if @builders[file]?
117
+ file_exp = {}
118
+ @builders[file](file_exp, this.require)
119
+ file_exp
120
+ else
121
+ throw new Exception("NibJS error: no such file #{file}")
@@ -0,0 +1,10 @@
1
+ <script type="text/javascript">
2
+ var _gaq = _gaq || [];
3
+ _gaq.push(['_setAccount', 'UA-16520635-4']);
4
+ _gaq.push(['_trackPageview']);
5
+ (function() {
6
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
7
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
8
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
9
+ })();
10
+ </script>
@@ -0,0 +1,25 @@
1
+ def each_example
2
+ Dir[_('examples/*')].each{|dir|
3
+ next unless File.directory?(dir)
4
+ next if File.basename(dir) == "public"
5
+ File.basename(dir) =~ /\d-(.*)$/
6
+ js_file = File.join(dir, "#{$1}.js")
7
+ yield(dir, js_file)
8
+ }
9
+ end
10
+
11
+ desc "Cleans the examples test suite"
12
+ task :"examples:clean" do
13
+ require 'fileutils'
14
+ FileUtils.rm_rf _('examples/public/TestSuite.js')
15
+ each_example{|dir, js_file| FileUtils.rm_rf js_file}
16
+ end
17
+
18
+ desc "Rebuilds the whole examples test suite"
19
+ task :"examples:build" => :"examples:clean" do
20
+ shell_safe_exec("coffee --compile --bare #{_('examples/public/TestSuite.coffee')}")
21
+ dist(_('examples/public/nibjs.js'))
22
+ each_example do |dir, js_file|
23
+ shell_safe_exec(File.join(dir, "build"))
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ desc "Builds the github pages"
2
+ task :pages do
3
+ shell_safe_exec("cp -R #{_('examples/*')} #{_('gh-pages')}")
4
+ shell_safe_exec("rm -rf #{_('gh-pages/illustrations.graffle')}")
5
+
6
+ analytics = File.read(File.expand_path('../analytics.txt', __FILE__))
7
+ analytics.gsub!(/^/m, ' ')
8
+ Dir[_("gh-pages/**/index.html")].each{|file|
9
+ puts "On #{file}"
10
+ content = File.read(file)
11
+ content.gsub!(/^\s*<\/body>/, analytics + " </body>")
12
+ File.open(file, 'w'){|io| io << content}
13
+ }
14
+ shell_safe_exec("cd #{_('gh-pages')} && git commit -a -m 'Regenerated doc.' && git push origin")
15
+ end
@@ -42,12 +42,11 @@ begin
42
42
  end
43
43
 
44
44
  desc "Run integration tests"
45
- task :"test:integration" do
46
- shell_safe_exec("coffee --compile #{_('test/integration')}")
45
+ task :"test:integration" => :"examples:build" do
47
46
  puts "#"*100
48
47
  puts "Please open the URL below in your browser"
49
48
  puts "#"*100
50
- puts shell_safe_exec("ruby #{_('test/integration/integration_test.rb')}").inspect
49
+ puts shell_safe_exec("ruby #{_('examples/handler.rb')}").inspect
51
50
  end
52
51
 
53
52
  desc "Bootstrap the test suite (rebuild command/*.exp)"
@@ -0,0 +1 @@
1
+ /* and this is a footer */
@@ -0,0 +1,106 @@
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('fixture', function(nibjs) {
77
+ nibjs.register('./app', function(exports, require) {
78
+ var App;
79
+ exports.App = App = (function() {
80
+ function App() {}
81
+ App.prototype.say_hello = function() {
82
+ return "Hello from App";
83
+ };
84
+ return App;
85
+ })();
86
+ return exports;
87
+ });
88
+ nibjs.register('./dependent', function(exports, require) {
89
+ var App, Dependent;
90
+ App = require('./app').App;
91
+ exports.Dependent = Dependent = (function() {
92
+ function Dependent() {}
93
+ Dependent.prototype.say_hello = function() {
94
+ return "Hello from Dependent";
95
+ };
96
+ return Dependent;
97
+ })();
98
+ return exports;
99
+ });
100
+ nibjs.register('./index', function(exports, require) {
101
+ exports.App = require('./app').App;
102
+ exports.Dependent = require('./dependent').Dependent;
103
+ return exports;
104
+ });
105
+ return nibjs.require('./index');
106
+ });
@@ -0,0 +1,151 @@
1
+ NibJSBuild = (exports)->
2
+ exports.NibJS = {
3
+
4
+ #
5
+ # Package builders.
6
+ #
7
+ # Package builders are simply unary functions registered via NibJS.define.
8
+ # These functions are expected to build the package thanks to a Builder
9
+ # instance that they receive as first argument.
10
+ #
11
+ # @see define
12
+ # @see Builder
13
+ #
14
+ pkgBuilders: []
15
+
16
+ #
17
+ # Built packages.
18
+ #
19
+ # Once the package are built (lazily, at first 'require' invocation), the
20
+ # results is put in the following array for subsequent requiring.
21
+ #
22
+ packages: []
23
+
24
+ #
25
+ # Checks if a package is known.
26
+ #
27
+ hasPackage: (name)->
28
+ NibJS.pkgBuilders[name]? || NibJS.packages[name]?
29
+
30
+ #
31
+ # Defines a package via a name and a builder function.
32
+ #
33
+ # Builder functions are expected to build the package thanks to a Builder
34
+ # instance received as first argument. They are expected to make the first
35
+ # require to the package index file.
36
+ #
37
+ # Example:
38
+ # NibJS.define('foo', function(nibjs){
39
+ # nibjs.register('bar', function(exports, require){
40
+ # /* content of bar.js comes here */
41
+ # });
42
+ # nibjs.register('index', function(exports, require){
43
+ # /* content of index.js come here */
44
+ # });
45
+ # /* Load the package at end */
46
+ # nibjs.require('index');
47
+ # });
48
+ #
49
+ define: (name, buildFn)->
50
+ NibJS.pkgBuilders[name] = buildFn
51
+
52
+ #
53
+ # Returns a package, building it if required (equivalent to Node's _require_).
54
+ #
55
+ # Example:
56
+ # Foo = NibJS.require('foo')
57
+ # Foo.Bar = ...
58
+ #
59
+ require: (name)->
60
+ NibJS.packages[name] ?= NibJS._build_one(name)
61
+
62
+ #
63
+ # Internal implementation of require, when invoked the first time on
64
+ # a given library.
65
+ #
66
+ _build_one: (name)->
67
+ if NibJS.pkgBuilders[name]
68
+ builder = new Builder
69
+ NibJS.pkgBuilders[name](builder)
70
+ else
71
+ throw new Exception("NibJS error: no module '#{name}' has been previously registered.")
72
+
73
+ }
74
+
75
+ class Exception extends Error
76
+ constructor: (@message)->
77
+
78
+ #
79
+ # Intra-package builder, passed as first argument of NibJS.define
80
+ #
81
+ # This builder helps registrering functions for building individual
82
+ # files, as well as requiring them.
83
+ #
84
+ class Builder
85
+
86
+ #
87
+ # Builds a builder instance
88
+ #
89
+ constructor: ()->
90
+ @builders = []
91
+ @built = []
92
+
93
+ #
94
+ # Register a builder function for _file_.
95
+ #
96
+ # The builder function will be called when the file will be required later.
97
+ # It takes two parameters as arguments, exports and require. The first one
98
+ # allows the file to exports artifacts while the second one mimics the
99
+ # Node's require function.
100
+ #
101
+ register: (file, builder)=>
102
+ @builders[file] = builder
103
+
104
+ #
105
+ # Mimics Node's require in the context of this building.
106
+ #
107
+ # This function returns the result of requiring _file_, building it with
108
+ # the function previously registered (if not previously done).
109
+ #
110
+ require: (file)=>
111
+ @built[file] ?= this.build_file(file)
112
+
113
+ #
114
+ # Private functions that ensures the building of a file.
115
+ #
116
+ build_file: (file)=>
117
+ if @builders[file]?
118
+ file_exp = {}
119
+ @builders[file](file_exp, this.require)
120
+ file_exp
121
+ else
122
+ throw new Exception("NibJS error: no such file #{file}")
123
+ NibJSBuild(this)
124
+
125
+
126
+ NibJS.define 'fixture', (nibjs)->
127
+ nibjs.register './app', (exports, require)->
128
+ exports.App = class App
129
+
130
+ say_hello: ->
131
+ "Hello from App"
132
+
133
+ return exports
134
+
135
+ nibjs.register './dependent', (exports, require)->
136
+ {App} = require('./app')
137
+
138
+ exports.Dependent = class Dependent
139
+
140
+ say_hello: ->
141
+ "Hello from Dependent"
142
+
143
+ return exports
144
+
145
+ nibjs.register './index', (exports, require)->
146
+ exports.App = require('./app').App
147
+ exports.Dependent = require('./dependent').Dependent
148
+ return exports
149
+
150
+ nibjs.require './index'
151
+ fixture = NibJS.require 'fixture'