comb 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ test/output.js
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.version = Comb::VERSION
8
8
  s.authors = ["Ryan Allen"]
9
9
  s.email = ["ryan@yeahnah.org"]
10
- s.homepage = ""
10
+ s.homepage = "https://github.com/ryan-allen/comb"
11
11
  s.summary = %q{Assembler for modular client-side apps.}
12
12
  s.description = %q{Brings file-based module support to client-side JavaScript applications.}
13
13
 
@@ -1,36 +1,78 @@
1
- require_relative "comb/version"
1
+ require_relative 'comb/version'
2
2
  require 'time'
3
3
 
4
- module Comb
5
- def self.assemble(path)
6
- out = []
7
- library_path = path
8
- out << "// generated by comb on #{Time.now.utc.iso8601}"
9
- out << <<-eos
10
- var modules = function() {
11
- var registry = {}
12
- return {
13
- register: function(name, module) {
14
- registry[name] = module
15
- },
16
- require: function(name) {
17
- return registry[name]()
18
- }
19
- }
20
- }()
21
- var require = modules.require
4
+ class Comb
5
+ def self.assemble(path_to_modules)
6
+ new(path_to_modules).assemble
7
+ end
8
+
9
+ private
10
+
11
+ def initialize(path_to_modules)
12
+ # instance vars are just global vars in sheeps clothing
13
+ @path_to_modules = path_to_modules
14
+ @output = []
15
+ @timestamp = Time.new.utc.iso8601 # baaaaaaaaaaa
16
+ end
17
+
18
+ public
19
+
20
+ def assemble
21
+ mark_start_of_output
22
+ append_require_snippet
23
+ for_each_js_module do |name, code|
24
+ append_to_output(name, code)
25
+ end
26
+ mark_end_of_output
27
+ return_output
28
+ end
29
+
30
+ private
31
+
32
+ def mark_start_of_output
33
+ @output << "// generated by comb on #{@timestamp}"
34
+ end
35
+
36
+ def append_require_snippet
37
+ @output << (<<-eos
38
+ var require = function(module) {
39
+ return require.registry[module]()
40
+ }
41
+ require.registry = {}
42
+ require.register = function(module, code) {
43
+ require.registry[module] = code
44
+ }
22
45
  eos
23
- Dir.glob(library_path + '/**/*.js').each do |path|
24
- file = path.gsub(library_path, '').gsub(/^\//, '')
25
- mod = file.gsub(/\.js$/, '')
26
- out << <<-eos
27
- // #{file} => #{mod}
28
- modules.register('#{mod}', function() {
29
- #{File.open(path) { |f| f.read }.split("\n").collect { |line| " #{line}" }.join("\n")}
46
+ ).chomp
47
+ end
48
+
49
+ def for_each_js_module
50
+ Dir.glob(@path_to_modules + '/**/*.js').each do |path|
51
+ # get the module 'name' by removing the path and the extension
52
+ name = path.gsub(@path_to_modules, '').gsub(/^\//, '').gsub(/\.js$/, '')
53
+ code = File.open(path) { |f| f.read }
54
+ yield name, code
55
+ end
56
+ end
57
+
58
+ def append_to_output(name, code)
59
+ @output << (<<-eos
60
+ require.register('#{name}', function() {
61
+ #{indent_code(code)}
30
62
  })
31
63
  eos
32
- end
33
- out << "// end of comb output"
34
- out.join("\n")
64
+ ).chomp
65
+ end
66
+
67
+ def indent_code(code)
68
+ code.split("\n").collect { |line| " #{line}" }.join("\n")
69
+ end
70
+
71
+ def mark_end_of_output
72
+ @output << "// end of comb output at #{@timestamp}"
73
+ end
74
+
75
+ def return_output
76
+ @output.join("\n")
35
77
  end
36
78
  end
@@ -1,3 +1,3 @@
1
- module Comb
2
- VERSION = "0.0.3"
1
+ class Comb
2
+ VERSION = '0.0.4'
3
3
  end
@@ -1,5 +1,5 @@
1
1
  <script type="text/javascript" src="output.js"></script>
2
2
  <script type="text/javascript">
3
3
  var app = require('app')
4
- app.run()
4
+ app.run() // two alerts should fire
5
5
  </script>
@@ -1,8 +1,8 @@
1
- exports.run = function() {
2
- var textbox = require('widgets/textbox')
3
- var emailbox = require('widgets/emailbox')
4
- var uri = require('utils/uri')
5
- alert(uri.bestUri)
6
- var bdays = require('utils/date')
7
- bdays.whatsMyBday()
1
+ return {
2
+ run: function() {
3
+ var uri = require('utils/uri')
4
+ var bdays = require('utils/date')
5
+ alert(uri.bestUri)
6
+ bdays.whatsMyBday() // calls alert itself
7
+ }
8
8
  }
@@ -1,7 +1,9 @@
1
+ // most useful date module in the history of mankind
2
+
1
3
  var myBday = '24/11/1982'
2
4
 
3
5
  var whatsMyBday = function() {
4
6
  alert(myBday)
5
7
  }
6
8
 
7
- exports.whatsMyBday = whatsMyBday
9
+ return {whatsMyBday: whatsMyBday}
@@ -1 +1,5 @@
1
- exports.bestUri = 'yeahnah.org'
1
+ // most useful uri library in the history of the universe
2
+
3
+ var bestUri = 'yeahnah.org'
4
+
5
+ return {bestUri: bestUri}
@@ -0,0 +1,37 @@
1
+ // generated by comb on 2011-12-29T00:05:24Z
2
+ var require = function(module) {
3
+ return require.registry[module]()
4
+ }
5
+ require.registry = {}
6
+ require.register = function(module, code) {
7
+ require.registry[module] = code
8
+ }
9
+ require.register('app', function() {
10
+ return {
11
+ run: function() {
12
+ var uri = require('utils/uri')
13
+ var bdays = require('utils/date')
14
+ alert(uri.bestUri)
15
+ bdays.whatsMyBday() // calls alert itself
16
+ }
17
+ }
18
+ })
19
+ require.register('utils/date', function() {
20
+ // most useful date module in the history of mankind
21
+
22
+ var myBday = '24/11/1982'
23
+
24
+ var whatsMyBday = function() {
25
+ alert(myBday)
26
+ }
27
+
28
+ return {whatsMyBday: whatsMyBday}
29
+ })
30
+ require.register('utils/uri', function() {
31
+ // most useful uri library in the history of the universe
32
+
33
+ var bestUri = 'yeahnah.org'
34
+
35
+ return {bestUri: bestUri}
36
+ })
37
+ // end of comb output at 2011-12-29T00:05:24Z
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-28 00:00:00.000000000Z
12
+ date: 2011-12-29 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: Brings file-based module support to client-side JavaScript applications.
15
15
  email:
@@ -30,15 +30,10 @@ files:
30
30
  - test/README
31
31
  - test/container.html
32
32
  - test/js/app.js
33
- - test/js/controllers/articles.js
34
- - test/js/controllers/edit.js
35
33
  - test/js/utils/date.js
36
34
  - test/js/utils/uri.js
37
- - test/js/widgets/combos/megatable.js
38
- - test/js/widgets/emailbox.js
39
- - test/js/widgets/textbox.js
40
- - test/output.js
41
- homepage: ''
35
+ - test/output.js.example
36
+ homepage: https://github.com/ryan-allen/comb
42
37
  licenses: []
43
38
  post_install_message:
44
39
  rdoc_options: []
@@ -66,11 +61,6 @@ test_files:
66
61
  - test/README
67
62
  - test/container.html
68
63
  - test/js/app.js
69
- - test/js/controllers/articles.js
70
- - test/js/controllers/edit.js
71
64
  - test/js/utils/date.js
72
65
  - test/js/utils/uri.js
73
- - test/js/widgets/combos/megatable.js
74
- - test/js/widgets/emailbox.js
75
- - test/js/widgets/textbox.js
76
- - test/output.js
66
+ - test/output.js.example
@@ -1 +0,0 @@
1
- // articles...
@@ -1 +0,0 @@
1
- // edit controller
@@ -1 +0,0 @@
1
- // lol mega table
@@ -1 +0,0 @@
1
- // lol an email box, does nothing
@@ -1,4 +0,0 @@
1
- exports.name = 'textbox'
2
- exports.make = function() {
3
- // macking an textbox
4
- }
@@ -1,78 +0,0 @@
1
- // generated by comb on 2011-12-28T03:11:08Z
2
- var modules = function() {
3
- var registry = {}
4
- return {
5
- register: function(name, module) {
6
- registry[name] = module
7
- },
8
- require: function(name) {
9
- return registry[name]()
10
- }
11
- }
12
- }()
13
- var require = modules.require
14
- // app.js => app
15
- modules.register('app', function() {
16
- var exports = {}
17
- exports.run = function() {
18
- var textbox = require('widgets/textbox')
19
- var emailbox = require('widgets/emailbox')
20
- var uri = require('utils/uri')
21
- alert(uri.bestUri)
22
- var bdays = require('utils/date')
23
- bdays.whatsMyBday()
24
- }
25
- return exports
26
- })
27
- // controllers/articles.js => controllers/articles
28
- modules.register('controllers/articles', function() {
29
- var exports = {}
30
- // articles...
31
- return exports
32
- })
33
- // controllers/edit.js => controllers/edit
34
- modules.register('controllers/edit', function() {
35
- var exports = {}
36
- // edit controller
37
- return exports
38
- })
39
- // utils/date.js => utils/date
40
- modules.register('utils/date', function() {
41
- var exports = {}
42
- var myBday = '24/11/1982'
43
-
44
- var whatsMyBday = function() {
45
- alert(myBday)
46
- }
47
-
48
- exports.whatsMyBday = whatsMyBday
49
- return exports
50
- })
51
- // utils/uri.js => utils/uri
52
- modules.register('utils/uri', function() {
53
- var exports = {}
54
- exports.bestUri = 'yeahnah.org'
55
- return exports
56
- })
57
- // widgets/combos/megatable.js => widgets/combos/megatable
58
- modules.register('widgets/combos/megatable', function() {
59
- var exports = {}
60
- // lol mega table
61
- return exports
62
- })
63
- // widgets/emailbox.js => widgets/emailbox
64
- modules.register('widgets/emailbox', function() {
65
- var exports = {}
66
- // lol an email box, does nothing
67
- return exports
68
- })
69
- // widgets/textbox.js => widgets/textbox
70
- modules.register('widgets/textbox', function() {
71
- var exports = {}
72
- exports.name = 'textbox'
73
- exports.make = function() {
74
- // macking an textbox
75
- }
76
- return exports
77
- })
78
- // end of comb output