js2 0.0.10 → 0.1.1

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 (67) hide show
  1. data/Manifest +42 -0
  2. data/README.md +65 -0
  3. data/Rakefile +19 -35
  4. data/bin/js2 +80 -66
  5. data/config/js2.yml +2 -0
  6. data/js2.gemspec +33 -0
  7. data/lib/js2/{haml_parser.rb → parser/haml.rb} +2 -2
  8. data/lib/js2/{haml_engine.rb → parser/haml_engine.rb} +1 -1
  9. data/lib/js2/parser/lexer.rb +37 -0
  10. data/lib/js2/{parser.rb → parser/tokenizer.rb} +157 -143
  11. data/lib/js2/{replace.rb → ragel/helper.rb} +16 -5
  12. data/lib/js2/ragel/tokenizer.rl +561 -0
  13. data/lib/js2/{tokenizer.rl.erb → ragel/tokenizer.rl.erb} +12 -19
  14. data/lib/js2/standard/factory.rb +289 -0
  15. data/lib/js2/standard/node.rb +75 -0
  16. data/lib/js2/util/compilation.rb +77 -0
  17. data/lib/js2/util/config.rb +84 -0
  18. data/lib/js2/util/exec.rb +34 -0
  19. data/lib/js2/util/file_handler.rb +73 -0
  20. data/lib/js2/{js2bootstrap.js2 → util/js2bootstrap.js2} +12 -68
  21. data/lib/js2/util/processor.rb +88 -0
  22. data/lib/js2/util/rdoc.rb +35 -0
  23. data/lib/js2/{sel_decorator.rb → util/sel_decorator.rb} +11 -1
  24. data/lib/js2.rb +22 -45
  25. data/test/compiled/bar.js +3 -0
  26. data/test/compiled/basic.comp.js +31 -0
  27. data/test/compiled/basic.js +27 -0
  28. data/test/compiled/foo.js +3 -0
  29. data/test/fixtures/bar.js2 +3 -0
  30. data/test/fixtures/basic.js2 +27 -0
  31. data/test/fixtures/basic.js2.haml +4 -0
  32. data/test/fixtures/basic.js2.yml +5 -0
  33. data/test/fixtures/curry.js2 +5 -0
  34. data/test/fixtures/foo.js2 +3 -0
  35. data/test/fixtures/member.js2 +14 -0
  36. data/test/fixtures/private.js2 +5 -0
  37. data/test/fixtures/property.js2 +4 -0
  38. data/test/test_helper.rb +25 -0
  39. data/test/test_js2.rb +43 -0
  40. data/wiki/features.md +106 -0
  41. data/wiki/installation.md +53 -0
  42. metadata +89 -83
  43. data/Changelog +0 -33
  44. data/History.txt +0 -4
  45. data/Manifest.txt +0 -35
  46. data/PostInstall.txt +0 -7
  47. data/README +0 -69
  48. data/README.rdoc +0 -69
  49. data/README.txt +0 -69
  50. data/examples/js2.yml +0 -8
  51. data/examples/test.yml +0 -5
  52. data/lib/javascript/sel_marker.js2 +0 -150
  53. data/lib/javascript/test.js2 +0 -73
  54. data/lib/js2/config.rb +0 -39
  55. data/lib/js2/daemon.rb +0 -35
  56. data/lib/js2/file_handler.rb +0 -91
  57. data/lib/js2/foo.js2.haml +0 -3
  58. data/lib/js2/js2.js +0 -110
  59. data/lib/js2/processor.rb +0 -112
  60. data/lib/js2/test/selenium.rb +0 -119
  61. data/lib/js2/test/selenium_element.rb +0 -234
  62. data/lib/js2/test/selenium_helper.rb +0 -27
  63. data/lib/js2/tree.rb +0 -351
  64. data/lib/js2/universe.rb +0 -123
  65. data/lib/tasks/js2.rake +0 -9
  66. data/website/index.txt +0 -86
  67. /data/{LICENSE → lib/js2/standard/class_node.rb} +0 -0
data/lib/js2/universe.rb DELETED
@@ -1,123 +0,0 @@
1
- class JS2::Universe
2
- CWD = File.dirname(__FILE__)
3
- def initialize (fh, haml_engine)
4
- @file_handler = fh
5
- @parser = JS2::Parser.new
6
- @haml_parser = JS2::HamlParser.new(haml_engine) if JS2::HamlParser
7
- end
8
-
9
- def write
10
- @compilations = Hash.new
11
- @class_lookup = {}
12
- @tree_lookup = {}
13
- files = @file_handler.get_files
14
-
15
- trees = []
16
- files.each do |file|
17
- tree = @parser.parse_file(file)
18
- trees << tree
19
- end
20
-
21
- trees.each do |tree|
22
- tree.classes.each do |c|
23
- (@tree_lookup[c.name] ||= []) << tree
24
- @class_lookup[c.name] ||= c
25
- end
26
- end
27
-
28
- if JS2::HamlParser
29
- @file_handler.get_haml_files.each do |file|
30
- hash = @haml_parser.parse(file)
31
- hash.each_pair do |name,v|
32
- if ! @tree_lookup[name]
33
- puts "In #{file}"
34
- puts "There is no class found with this name: #{name}"
35
- else
36
- to_write = v.keys.collect { |k| "#{k.to_json}: #{v[k]}" }.join(',')
37
- @tree_lookup[name].first.extra << "#{name}.oo('setHTMLCache', {#{to_write}});"
38
- end
39
- end
40
- end
41
- end
42
-
43
- trees.each do |tree|
44
- @file_handler.write_file(tree.filename, tree.to_s)
45
- end
46
-
47
- @file_handler.get_yml_files.each do |filename|
48
- begin
49
- yml = YAML.load_file(filename)
50
- self.add_yml(yml, filename)
51
- rescue Exception => e
52
- puts "YAML Error in #{filename}:"
53
- puts e.to_s
54
- puts e.backtrace.join("\n")
55
- end
56
- end
57
-
58
- @compilations.each_pair do |filename, hash|
59
- @file_handler.write_compilation(filename, hash)
60
- end
61
-
62
- js2_file = CWD + '/js2bootstrap.js2'
63
- js2_tree = @parser.parse_file(js2_file)
64
- @file_handler.write_file('js2bootstrap.js', js2_tree.to_s, true)
65
- end
66
-
67
- def add_yml (yml, filename)
68
- yml.each_pair do |klass_name, config|
69
- template = config['template'] || []
70
-
71
- trees = @tree_lookup[klass_name]
72
- filename = trees.first.filename
73
-
74
- str = " (function (K) { K.oo('method', 'getTemplate', function () { return #{template.to_json} }) })(#{klass_name});"
75
- to_write = @file_handler.get_js_filename(filename)
76
- File.open(to_write, 'a') do |fh|
77
- fh << str
78
- end
79
-
80
- if config['make_compilation']
81
- compilation = []
82
-
83
- if config['require']
84
- compilation += config['require'].collect do |name|
85
- # if class name
86
- if @tree_lookup[name]
87
- @tree_lookup[name].collect { |t| t.filename }
88
-
89
- # assume its just a file name
90
- else
91
- [ @file_handler.write_dir + '/' + name ]
92
- end
93
- end.flatten
94
- end
95
-
96
- compilation << filename
97
-
98
- if config['include']
99
- compilation += config['include'].collect do |name|
100
- # if class name
101
- if @tree_lookup[name]
102
- @tree_lookup[name].collect { |t| t.filename }
103
-
104
- # assume its just a file name
105
- else
106
- [ @file_handler.write_dir + '/' + name ]
107
- end
108
- end.flatten
109
- end
110
-
111
- template.each do |t|
112
- klass_name = t['class']
113
- trees = @tree_lookup[klass_name]
114
- compilation += trees.collect { |t| t.filename }
115
- end
116
-
117
- @compilations[filename] = compilation
118
- end
119
- end
120
- end
121
-
122
-
123
- end
data/lib/tasks/js2.rake DELETED
@@ -1,9 +0,0 @@
1
- namespace :js2 do
2
- task :build_all => :environment do
3
- # normal stuff
4
- CONFIG_FILE = "#{RAILS_ROOT}/config/js2.yml"
5
- d = JS2::Processor.daemon_from_file(CONFIG_FILE, RAILS_ENV)
6
- d.run(1)
7
- end
8
-
9
- end
data/website/index.txt DELETED
@@ -1,86 +0,0 @@
1
- = Quick Setup =
2
-
3
- install js2:
4
- {{{
5
- sudo gem install js2
6
- js2 -h
7
- }}}
8
-
9
- in a rails app (rails root):
10
- {{{
11
- # if your js2 files reside in ./app/js2
12
- js2 --out-dir=./public/javascripts ./app/js2
13
- }}}
14
-
15
- = OO Frustrations using Javascript =
16
-
17
-
18
- For every Javascript developer that has ever wanted to create a library for his/her project, there comes a time when an Object Oriented approach is necessary (or extremely desired). Fortunately, there are a plethora of options to choose from:
19
-
20
- using prototype (not the framework) and hashes:
21
- {{{
22
- var MyClass = function () {
23
- this.member1 = "member";
24
- };
25
- MyClass.prototype = {
26
- method1: function () { alert('method1 called'); }
27
- }
28
- }}}
29
-
30
- embedding functions right in the instantiator:
31
- {{{
32
- function MyClass () {
33
- this.member1 = "member1";
34
- function method1 () {
35
- alert("method1 called");
36
- }
37
- }
38
- }}}
39
-
40
- using jQuery (or any of the js OO frameworks) by passing in hashes:
41
- {{{
42
- var MyClass = Class.create({
43
- member1: "member1",
44
- method1: function(){ alert("method1 called") },
45
- });
46
- }}}
47
-
48
- Unfortunately, these solutions are unnatural as far as Object Oriented languages are go.
49
-
50
- = JS2 Solution =
51
-
52
- JS2 language that is a superset of Javascript and the problem it tries to solve is bringing "natural" OO syntax to Javascript by adding a compilation layer.
53
-
54
- So in myClass.js2 one could write:
55
- {{{
56
- class MyClass {
57
- var member1 = "member1";
58
-
59
- function method1 () {
60
- alert("method1 called");
61
- }
62
- }}}
63
-
64
- And after compilation myClass.js (notice the .js extension vs the .js2) would be:
65
- {{{
66
- var MyClass = function () { };
67
- MyClass.prototype = {
68
- member1: "member1",
69
- method1: function () { alert("method1 called"); }
70
- }
71
- }}}
72
-
73
- One of the nice things about this solution is that it allows us to "calculate" things like mixins and inheritance at compile time rather than runtime. This compilation layer opens the doors for features such as:
74
- * Inheritance
75
- * Mixins (Ruby's multiple inheritance solution)
76
- * getters and setters
77
- * IoC (Dependency Injection)
78
- * AOP (Aspect Oriented Programming)
79
- * foreach
80
- * currying
81
- * More [Features]
82
-
83
-
84
- = Inspiration ==
85
-
86
- HAML, SASS, Ruby, Perl, jQuery, Prototype.js
File without changes