reunion 0.0.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.
data/bin/reunion ADDED
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'reunion'
4
+
5
+ kClientPath = File.join(File.dirname(__FILE__), '..', 'client', 'require.js')
6
+
7
+ # user input
8
+ filearg = ARGV[0]
9
+
10
+ if !filearg then
11
+ puts 'file argument required'
12
+ exit -1
13
+ end
14
+
15
+ filename = File.expand_path(filearg)
16
+
17
+ def render(deps, ids)
18
+ flat = Hash.new
19
+
20
+ deps.each do |dep|
21
+ id = dep['id']
22
+ path = dep['path']
23
+
24
+ real_id = ids[path]
25
+ if real_id then
26
+ puts 'require.alias' + real_id + ':' + id if real_id != id
27
+ next
28
+ end
29
+
30
+ real_id = ids[path] = id
31
+
32
+ # render children first
33
+ render(dep['deps'], ids)
34
+
35
+ src = File.read(path)
36
+ puts 'require.m[\'' + real_id + '\'] = function(module, exports) {'
37
+ puts src
38
+ puts '};'
39
+ end
40
+ end
41
+
42
+ ## rendering ##
43
+
44
+ puts '(function(window) {';
45
+ puts 'var global = window;';
46
+ require_src = File.read(kClientPath)
47
+
48
+ puts require_src
49
+
50
+ deps = required(filename)
51
+
52
+ ids = Hash.new
53
+ ids[filename] = '__main__'
54
+ render(deps, ids)
55
+
56
+ puts 'require.m[\'__main__\'] = function(module, exports) {'
57
+ puts File.read(filename)
58
+ puts '};'
59
+
60
+ puts 'return require(\'__main__\');'
61
+ puts '})(window);'
62
+
63
+ # vim: ft=ruby
data/client/require.js ADDED
@@ -0,0 +1,12 @@
1
+ var require = function(name) {
2
+ var fn = require.m[name];
3
+ if (fn.mod) {
4
+ return fn.mod.exports;
5
+ }
6
+
7
+ var mod = fn.mod = { exports: {} };
8
+ fn(mod, mod.exports);
9
+ return mod.exports;
10
+ };
11
+
12
+ require.m = {};
data/lib/detective.rb ADDED
@@ -0,0 +1,26 @@
1
+ require 'rkelly'
2
+
3
+ def detective(src)
4
+ parser = RKelly::Parser.new
5
+ ast = parser.parse(src)
6
+
7
+ reqs = Array.new
8
+
9
+ ast.each do |node|
10
+ next if node.class != RKelly::Nodes::FunctionCallNode
11
+
12
+ next if node.value.class != RKelly::Nodes::ResolveNode
13
+ name_node = node.value
14
+
15
+ next if name_node.value != 'require'
16
+ args_node = node.arguments
17
+
18
+ req_id = args_node.value[0].value
19
+ next if req_id.class != String
20
+
21
+ reqs.push req_id.gsub(/'/, '')
22
+ end
23
+
24
+ return reqs
25
+ end
26
+
data/lib/required.rb ADDED
@@ -0,0 +1,28 @@
1
+ require 'detective'
2
+
3
+ def required(filename)
4
+ contents = File.read(filename)
5
+ base = File.dirname(filename)
6
+
7
+ deps = Array.new
8
+
9
+ detective(contents).each do |req_id|
10
+ path = File.expand_path(req_id, base)
11
+
12
+ idx_path = File.join(path, 'index.js')
13
+ path += '.js' if File.extname(path).empty?
14
+
15
+ dep = Hash.new
16
+ dep['id'] = req_id
17
+
18
+ # try to load index path if regular doesn't exit
19
+ path = idx_path if !File.exists? path
20
+
21
+ dep['path'] = path
22
+ dep['deps'] = required(path)
23
+
24
+ deps.push dep
25
+ end
26
+
27
+ return deps
28
+ end
data/lib/reunion.rb ADDED
@@ -0,0 +1 @@
1
+ require 'required'
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reunion
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 0
10
+ version: 0.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Roman Shtylman
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-11-30 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rkelly
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - "="
27
+ - !ruby/object:Gem::Version
28
+ hash: 25
29
+ segments:
30
+ - 1
31
+ - 0
32
+ - 7
33
+ version: 1.0.7
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ description:
37
+ email: shtylman@gmail.com
38
+ executables:
39
+ - reunion
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - lib/detective.rb
46
+ - lib/required.rb
47
+ - lib/reunion.rb
48
+ - bin/reunion
49
+ - client/require.js
50
+ homepage:
51
+ licenses: []
52
+
53
+ post_install_message:
54
+ rdoc_options: []
55
+
56
+ require_paths:
57
+ - lib
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ hash: 3
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ requirements: []
78
+
79
+ rubyforge_project:
80
+ rubygems_version: 1.8.24
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Bring your javascript files together. In a peaceful way.
84
+ test_files: []
85
+