js2 0.0.8 → 0.0.9
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/Changelog +3 -0
- data/Manifest.txt +13 -28
- data/Rakefile +19 -19
- data/bin/js2 +48 -41
- data/lib/javascript/sel_marker.js2 +3 -3
- data/lib/js2/config.rb +6 -1
- data/lib/js2/{process/file_handler.rb → file_handler.rb} +15 -19
- data/lib/js2/foo.js2.haml +3 -0
- data/lib/js2/{process/haml_engine.rb → haml_engine.rb} +1 -1
- data/lib/js2/{parser/haml.rb → haml_parser.rb} +20 -7
- data/lib/js2/js2.js +108 -0
- data/lib/js2/js2bootstrap.js2 +455 -0
- data/lib/js2/parser.rb +3542 -0
- data/lib/js2/processor.rb +14 -65
- data/lib/js2/replace.rb +106 -0
- data/lib/js2/{decorator/test.rb → sel_decorator.rb} +11 -14
- data/{meta/c_tokenizer.rl.erb → lib/js2/tokenizer.rl.erb} +155 -123
- data/lib/js2/tree.rb +340 -0
- data/lib/js2/universe.rb +101 -0
- data/lib/js2.rb +31 -77
- data/lib/tasks/js2.rake +1 -1
- metadata +15 -29
- data/lib/js2/ast/class_node.rb +0 -105
- data/lib/js2/ast/comment_node.rb +0 -2
- data/lib/js2/ast/haml_node.rb +0 -22
- data/lib/js2/ast/include_node.rb +0 -11
- data/lib/js2/ast/inherited_node.rb +0 -7
- data/lib/js2/ast/member_node.rb +0 -18
- data/lib/js2/ast/method_node.rb +0 -29
- data/lib/js2/ast/module_node.rb +0 -6
- data/lib/js2/ast/node.rb +0 -14
- data/lib/js2/ast/nodes.rb +0 -123
- data/lib/js2/ast/stuff_node.rb +0 -6
- data/lib/js2/decorator/app.rb +0 -7
- data/lib/js2/decorator/cleanser.rb +0 -54
- data/lib/js2/decorator/standard.rb +0 -103
- data/lib/js2/parser/fast.rb +0 -3959
- data/lib/js2/process/universe.rb +0 -89
- data/lib/js2/test/selenium.rb +0 -109
- data/lib/js2/test/selenium_element.rb +0 -234
- data/lib/js2/test/selenium_helper.rb +0 -27
- data/lib/js2bootstrap.js2 +0 -274
- data/meta/replace.rb +0 -126
data/lib/js2/tree.rb
ADDED
@@ -0,0 +1,340 @@
|
|
1
|
+
class JS2::Node < Array
|
2
|
+
attr_accessor :start_idx, :static
|
3
|
+
SEL = JS2::SelDecorator.new
|
4
|
+
|
5
|
+
def initialize (start_idx, string, static = false)
|
6
|
+
@static = static
|
7
|
+
@stack = []
|
8
|
+
@start_idx = start_idx
|
9
|
+
@current_idx = @start_idx
|
10
|
+
@string = string
|
11
|
+
end
|
12
|
+
|
13
|
+
def set_child (node)
|
14
|
+
len = node.start_idx - @current_idx
|
15
|
+
if len > 0
|
16
|
+
self << @string[@current_idx, len]
|
17
|
+
end
|
18
|
+
|
19
|
+
self << node
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
def stop_child (idx)
|
24
|
+
@current_idx = idx
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_s
|
28
|
+
ret = []
|
29
|
+
last_idx = self.length - 1
|
30
|
+
|
31
|
+
self.each_with_index do |s, i|
|
32
|
+
if i == 0
|
33
|
+
ret << self.first_string(s)
|
34
|
+
elsif i == last_idx
|
35
|
+
ret << self.last_string(s)
|
36
|
+
else
|
37
|
+
ret << s.to_s
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
if last_idx == 0
|
42
|
+
ret << self.last_string('')
|
43
|
+
end
|
44
|
+
|
45
|
+
return ret.join('')
|
46
|
+
end
|
47
|
+
|
48
|
+
def first_string (s)
|
49
|
+
return s.to_s
|
50
|
+
end
|
51
|
+
|
52
|
+
def last_string (s)
|
53
|
+
return s.to_s
|
54
|
+
end
|
55
|
+
|
56
|
+
def mark (idx)
|
57
|
+
len = idx - @current_idx
|
58
|
+
if len > 0
|
59
|
+
self << @string[@current_idx, len]
|
60
|
+
end
|
61
|
+
|
62
|
+
@current_idx = idx
|
63
|
+
end
|
64
|
+
|
65
|
+
def stop (idx)
|
66
|
+
len = idx - @current_idx
|
67
|
+
if len > 0
|
68
|
+
self << @string[@current_idx, len]
|
69
|
+
end
|
70
|
+
self.setup!
|
71
|
+
end
|
72
|
+
|
73
|
+
def setup!
|
74
|
+
end
|
75
|
+
|
76
|
+
def reset
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
class JS2::Stuff < JS2::Node
|
81
|
+
def to_s
|
82
|
+
str = super
|
83
|
+
str = SEL.translate(str, nil, false)
|
84
|
+
return str
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
class JS2::Class < JS2::Node
|
89
|
+
REGEX = /^(\s*class|module)\s+([\w\.]+)\s+(extends\s+([\w\.]+))?\s*\{(.*)/m
|
90
|
+
attr_accessor :name, :extends
|
91
|
+
|
92
|
+
def setup!
|
93
|
+
m = self[0].match(REGEX)
|
94
|
+
@name = m[2]
|
95
|
+
@extends = m[4]
|
96
|
+
@start = m[5]
|
97
|
+
end
|
98
|
+
|
99
|
+
def createName
|
100
|
+
return 'createClass'
|
101
|
+
end
|
102
|
+
|
103
|
+
def first_string (s)
|
104
|
+
extends = nil
|
105
|
+
if @extends
|
106
|
+
extends = "#{@name}.oo('extends', #{@extends});"
|
107
|
+
end
|
108
|
+
|
109
|
+
return %|JS2.OO.#{createName}("#{@name}"); #{extends} (function (K) {var self=K; var _super=JS2.OO['super']; #{@start}|
|
110
|
+
end
|
111
|
+
|
112
|
+
def last_string (s)
|
113
|
+
return s.to_s + ")(#{@name});"
|
114
|
+
end
|
115
|
+
|
116
|
+
def to_s
|
117
|
+
str = super
|
118
|
+
str = SEL.translate(str, @name, true)
|
119
|
+
return str
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
class JS2::Property < JS2::Node
|
124
|
+
REGEX = /(\s*)property(\s+)([\w+,\s]+\w)(\s*)/
|
125
|
+
def setup!
|
126
|
+
m = first.match(REGEX)
|
127
|
+
@space = m[1]
|
128
|
+
@mid_space = m[2]
|
129
|
+
@list = m[3].split(/,/).collect { |i| i.strip }
|
130
|
+
@end_space = m[4]
|
131
|
+
end
|
132
|
+
|
133
|
+
def to_s
|
134
|
+
return %|#{@space}K.oo('property',#{@mid_space}[ #{@list.collect { |i| "'#{i}'" }.join(',')} ]);|
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
class JS2::Accessor < JS2::Node
|
139
|
+
REGEX = /(\s*)accessor(\s+)([\w+,\s]+\w)(\s*)/
|
140
|
+
def setup!
|
141
|
+
m = first.match(REGEX)
|
142
|
+
@space = m[1]
|
143
|
+
@mid_space = m[2]
|
144
|
+
@list = m[3].split(/,/).collect { |i| i.strip }
|
145
|
+
@end_space = m[4]
|
146
|
+
end
|
147
|
+
|
148
|
+
def to_s
|
149
|
+
return %|#{@space}K.oo('accessor',#{@mid_space}[ #{@list.collect { |i| "'#{i}'" }.join(',')} ]);|
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
|
155
|
+
class JS2::Foreach < JS2::Node
|
156
|
+
# start var iterator array
|
157
|
+
REGEX = /(\s*)foreach\s*\(\s*var\s*([\$\w]+)(\s*:\s*([\$\w]))?\s*in\s*([^\s]+)\s*\)/
|
158
|
+
attr_accessor :iterator, :item, :array
|
159
|
+
@@inc = 0
|
160
|
+
|
161
|
+
def setup!
|
162
|
+
m = first.match(REGEX)
|
163
|
+
@start = m[1]
|
164
|
+
@item = m[2]
|
165
|
+
@iterator = m[4]
|
166
|
+
@array = m[5]
|
167
|
+
end
|
168
|
+
|
169
|
+
def first_string (s)
|
170
|
+
it = iterator
|
171
|
+
|
172
|
+
unless iterator
|
173
|
+
it = 'it' + @@inc.to_s
|
174
|
+
@@inc += 1
|
175
|
+
end
|
176
|
+
|
177
|
+
len = it + '__len'
|
178
|
+
arr = it + '__arr'
|
179
|
+
|
180
|
+
return %(#{@start}for (var #{it}=0,#{@item},#{arr}=#{@array},#{len}=#{arr}.length; (#{@item}=#{arr}[#{it}]) || #{it}<#{len}; #{it}++))
|
181
|
+
end
|
182
|
+
|
183
|
+
def self.reset
|
184
|
+
@@inc = 0
|
185
|
+
end
|
186
|
+
|
187
|
+
end
|
188
|
+
|
189
|
+
class JS2::Module < JS2::Class
|
190
|
+
def createName
|
191
|
+
return 'createModule'
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
class JS2::Private < JS2::Node
|
196
|
+
def to_s
|
197
|
+
return first.sub(/private/m, '// private')
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
class JS2::Include < JS2::Node
|
204
|
+
def first_string (s)
|
205
|
+
return s.sub(/include\s*/, "K.oo('include', ").sub(/;$/, ');');
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
class JS2::Member < JS2::Node
|
210
|
+
def first_string (s)
|
211
|
+
method = 'member'
|
212
|
+
|
213
|
+
if s.match(/^(\s*)(static)\s*/)
|
214
|
+
method = 'staticMember'
|
215
|
+
s = s.sub(/static\s*/, '')
|
216
|
+
end
|
217
|
+
|
218
|
+
return s.sub(/var\s*([\$\w]+)/) { "K.oo('#{method}', '" + $1 + "'" }.sub(/;$/, ');').sub(/\s*=/, ', ');
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
class JS2::Curry < JS2::Node
|
223
|
+
REGEX = %r|^curry\s*([^\{]*)?\{(.*)$|m
|
224
|
+
REGEX_WITH = %r|with\s+\(([^)]*)\)|
|
225
|
+
REGEX_ARGS = %r|^\s*\(([^)]*)\)|
|
226
|
+
|
227
|
+
def setup!
|
228
|
+
m = first.match(REGEX)
|
229
|
+
@decl = m[1].strip
|
230
|
+
@stop = m[2]
|
231
|
+
|
232
|
+
@args = ''
|
233
|
+
@in_scoped = ''
|
234
|
+
@scoped = ''
|
235
|
+
|
236
|
+
if m = @decl.match(REGEX_WITH)
|
237
|
+
in_scoped = m[1].split(',').collect { |v| v.strip }
|
238
|
+
scoped = in_scoped.collect { |v| v == 'this' ? 'self' : v }
|
239
|
+
if in_scoped.length
|
240
|
+
@scoped = scoped.join(', ')
|
241
|
+
@in_scoped = in_scoped.join(', ')
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
if m = @decl.match(%r|^\s*\(([^)]*)\)|)
|
246
|
+
@args = m[1].strip
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
def first_string (s)
|
251
|
+
return %|(function (#{@scoped}) { return function (#{@args}) {#{@stop}|
|
252
|
+
end
|
253
|
+
|
254
|
+
def last_string (s)
|
255
|
+
return s + %|})(#{@in_scoped})|
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
class JS2::Method < JS2::Node
|
260
|
+
REGEX = /^(\s*)(static\s+)?function\s+([\$\w\.]+)\s*\(([^)]*)\)\s*\{(.*)/m
|
261
|
+
attr_accessor :name, :args
|
262
|
+
|
263
|
+
def setup!
|
264
|
+
m = self[0].match(REGEX)
|
265
|
+
@space = m[1]
|
266
|
+
@static = m[2]
|
267
|
+
@name = m[3]
|
268
|
+
@args = m[4]
|
269
|
+
@start = m[5]
|
270
|
+
end
|
271
|
+
|
272
|
+
def first_string (s)
|
273
|
+
m = static ? 'staticMember' : 'method'
|
274
|
+
return %|#{@space}K.oo('#{m}', "#{@name}", function (#{args}) {#{@start}|
|
275
|
+
end
|
276
|
+
|
277
|
+
def last_string (s)
|
278
|
+
return %|#{s});|
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
class JS2::Ignore < JS2::Node
|
283
|
+
def to_s
|
284
|
+
return ''
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
|
289
|
+
|
290
|
+
class JS2::ParserHelper
|
291
|
+
attr_accessor :filename, :classes, :extra
|
292
|
+
|
293
|
+
TYPES = {
|
294
|
+
:CLASS => JS2::Class,
|
295
|
+
:FOREACH => JS2::Foreach,
|
296
|
+
:INCLUDE => JS2::Include,
|
297
|
+
:METHOD => JS2::Method,
|
298
|
+
:MEMBER => JS2::Member,
|
299
|
+
:MODULE => JS2::Module,
|
300
|
+
:STUFF => JS2::Stuff,
|
301
|
+
:STATIC => JS2::Ignore,
|
302
|
+
:PRIVATE => JS2::Private,
|
303
|
+
:CURRY => JS2::Curry,
|
304
|
+
:PROPERTY => JS2::Property,
|
305
|
+
:ACCESSOR => JS2::Accessor
|
306
|
+
}
|
307
|
+
|
308
|
+
def initialize (code)
|
309
|
+
@code = code
|
310
|
+
@stack = [ JS2::Stuff.new(0, @code) ]
|
311
|
+
@classes = []
|
312
|
+
@extra = []
|
313
|
+
end
|
314
|
+
|
315
|
+
def mark_node (idx)
|
316
|
+
@stack.last.mark(idx)
|
317
|
+
end
|
318
|
+
|
319
|
+
def start_node (type, start_idx, static = false)
|
320
|
+
klass = TYPES[type] || JS2::Node
|
321
|
+
new_node = klass.new(start_idx, @code, static)
|
322
|
+
if type == :CLASS || type == :MODULE
|
323
|
+
@classes.push(new_node)
|
324
|
+
end
|
325
|
+
|
326
|
+
@stack.last.set_child(new_node)
|
327
|
+
@stack.push << new_node
|
328
|
+
end
|
329
|
+
|
330
|
+
def stop_node (stop_idx)
|
331
|
+
last = @stack.pop
|
332
|
+
last.stop(stop_idx) if last
|
333
|
+
@stack.last.stop_child(stop_idx) if @stack.last
|
334
|
+
end
|
335
|
+
|
336
|
+
def to_s
|
337
|
+
return @stack.collect { |i| i.to_s }.join('') + (extra.empty? ? '' : ("\n" + extra.join("\n")))
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
data/lib/js2/universe.rb
ADDED
@@ -0,0 +1,101 @@
|
|
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
|
+
next unless template
|
71
|
+
|
72
|
+
trees = @tree_lookup[klass_name]
|
73
|
+
filename = trees.first.filename
|
74
|
+
|
75
|
+
str = " (function (K) { K.oo('method', 'getTemplate', function () { return #{template.to_json} }) })(#{klass_name});"
|
76
|
+
to_write = @file_handler.get_js_filename(filename)
|
77
|
+
File.open(to_write, 'a') do |fh|
|
78
|
+
fh << str
|
79
|
+
end
|
80
|
+
|
81
|
+
if config['make_compilation']
|
82
|
+
compilation = [ filename ]
|
83
|
+
|
84
|
+
if config['include']
|
85
|
+
compilation += config['include'].collect { |name| @tree_lookup[name].collect { |t| t.filename } }.flatten
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
template.each do |t|
|
90
|
+
klass_name = t['class']
|
91
|
+
trees = @tree_lookup[klass_name]
|
92
|
+
compilation += trees.collect { |t| t.filename }
|
93
|
+
end
|
94
|
+
|
95
|
+
@compilations[filename] = compilation
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
end
|
data/lib/js2.rb
CHANGED
@@ -1,95 +1,49 @@
|
|
1
1
|
$:.unshift(File.dirname(__FILE__)) unless
|
2
2
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
3
|
|
4
|
-
module Js2
|
5
|
-
VERSION = '0.0.8'
|
6
|
-
end
|
7
4
|
|
8
5
|
module JS2
|
9
|
-
|
10
|
-
end
|
11
|
-
module AST
|
12
|
-
end
|
13
|
-
module Process
|
14
|
-
end
|
15
|
-
module Decorator
|
16
|
-
end
|
17
|
-
module Test
|
18
|
-
end
|
19
|
-
|
6
|
+
VERSION = '0.0.9'
|
20
7
|
end
|
21
8
|
|
22
|
-
$:.unshift File.dirname(__FILE__) # For use/testing when no gem is installed
|
23
|
-
|
24
|
-
# for others
|
25
|
-
require 'js2/processor'
|
26
|
-
require 'js2/daemon'
|
27
9
|
require 'js2/config'
|
10
|
+
require 'js2/daemon'
|
11
|
+
require 'js2/processor'
|
12
|
+
require 'js2/sel_decorator'
|
28
13
|
|
29
|
-
|
30
|
-
require 'js2/parser
|
31
|
-
require 'js2/
|
32
|
-
|
33
|
-
# process
|
34
|
-
require 'js2/process/haml_engine'
|
35
|
-
require 'js2/process/file_handler'
|
36
|
-
require 'js2/process/universe'
|
37
|
-
|
38
|
-
# ast
|
39
|
-
require 'js2/ast/node'
|
40
|
-
require 'js2/ast/class_node'
|
41
|
-
require 'js2/ast/comment_node'
|
42
|
-
require 'js2/ast/haml_node'
|
43
|
-
require 'js2/ast/inherited_node'
|
44
|
-
require 'js2/ast/stuff_node'
|
45
|
-
require 'js2/ast/member_node'
|
46
|
-
require 'js2/ast/method_node'
|
47
|
-
require 'js2/ast/module_node'
|
48
|
-
require 'js2/ast/include_node'
|
49
|
-
require 'js2/ast/nodes'
|
50
|
-
|
51
|
-
# decorator
|
52
|
-
require 'js2/decorator/standard'
|
53
|
-
require 'js2/decorator/test'
|
54
|
-
require 'js2/decorator/cleanser'
|
55
|
-
|
56
|
-
require 'yaml'
|
57
|
-
|
58
|
-
# test
|
59
|
-
require 'js2/test/selenium'
|
60
|
-
require 'js2/test/selenium_helper'
|
61
|
-
require 'js2/test/selenium_element'
|
14
|
+
require 'js2/tree'
|
15
|
+
require 'js2/parser'
|
16
|
+
require 'js2/file_handler'
|
17
|
+
require 'js2/universe'
|
62
18
|
|
63
|
-
|
64
|
-
def self.config
|
65
|
-
return @@config
|
66
|
-
end
|
19
|
+
$:.unshift File.dirname(__FILE__)
|
67
20
|
|
68
|
-
|
69
|
-
|
70
|
-
|
21
|
+
begin
|
22
|
+
require 'rubygems'
|
23
|
+
require 'json'
|
24
|
+
rescue Exception => e
|
25
|
+
raise "JS2 Requires RubyGems and JSON gems"
|
26
|
+
end
|
71
27
|
|
72
|
-
|
73
|
-
|
74
|
-
|
28
|
+
begin
|
29
|
+
require 'haml'
|
30
|
+
require 'sass'
|
31
|
+
require 'js2/haml_parser'
|
32
|
+
require 'js2/haml_engine'
|
33
|
+
rescue Exception => e
|
34
|
+
puts "HAML is not installed deactivating support"
|
35
|
+
end
|
75
36
|
|
76
|
-
def self.daemon (params)
|
77
|
-
return JS2::Process::Daemon.new(params)
|
78
|
-
end
|
79
37
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
38
|
+
if JS2::HamlParser
|
39
|
+
# for haml filter
|
40
|
+
module JS2
|
41
|
+
include Haml::Filters::Base
|
84
42
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
return "<script>" + decorator.draw_nodes(nodes) + "</script>"
|
90
|
-
end
|
43
|
+
def render (text)
|
44
|
+
parser = ::JS2::Parser.new
|
45
|
+
tree = parser.parse(text)
|
46
|
+
return '<script language="Javascript">' + tree.to_s + "</script>"
|
91
47
|
end
|
92
|
-
rescue Exception
|
93
|
-
puts "No haml filter support"
|
94
48
|
end
|
95
49
|
end
|
data/lib/tasks/js2.rake
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: js2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Su
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-01-29 00:00:00 +08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -69,37 +69,23 @@ files:
|
|
69
69
|
- examples/test.yml
|
70
70
|
- lib/javascript/sel_marker.js2
|
71
71
|
- lib/javascript/test.js2
|
72
|
-
- lib/
|
72
|
+
- lib/tasks/js2.rake
|
73
73
|
- lib/js2.rb
|
74
|
-
- lib/js2/ast/class_node.rb
|
75
|
-
- lib/js2/ast/comment_node.rb
|
76
|
-
- lib/js2/ast/haml_node.rb
|
77
|
-
- lib/js2/ast/include_node.rb
|
78
|
-
- lib/js2/ast/inherited_node.rb
|
79
|
-
- lib/js2/ast/member_node.rb
|
80
|
-
- lib/js2/ast/method_node.rb
|
81
|
-
- lib/js2/ast/module_node.rb
|
82
|
-
- lib/js2/ast/node.rb
|
83
|
-
- lib/js2/ast/nodes.rb
|
84
|
-
- lib/js2/ast/stuff_node.rb
|
85
74
|
- lib/js2/config.rb
|
86
75
|
- lib/js2/daemon.rb
|
87
|
-
- lib/js2/
|
88
|
-
- lib/js2/
|
89
|
-
- lib/js2/
|
90
|
-
- lib/js2/
|
91
|
-
- lib/js2/
|
92
|
-
- lib/js2/
|
93
|
-
- lib/js2/
|
94
|
-
- lib/js2/process/haml_engine.rb
|
95
|
-
- lib/js2/process/universe.rb
|
76
|
+
- lib/js2/file_handler.rb
|
77
|
+
- lib/js2/foo.js2.haml
|
78
|
+
- lib/js2/haml_engine.rb
|
79
|
+
- lib/js2/haml_parser.rb
|
80
|
+
- lib/js2/js2.js
|
81
|
+
- lib/js2/js2bootstrap.js2
|
82
|
+
- lib/js2/parser.rb
|
96
83
|
- lib/js2/processor.rb
|
97
|
-
- lib/js2/
|
98
|
-
- lib/js2/
|
99
|
-
- lib/js2/
|
100
|
-
- lib/
|
101
|
-
-
|
102
|
-
- meta/replace.rb
|
84
|
+
- lib/js2/replace.rb
|
85
|
+
- lib/js2/sel_decorator.rb
|
86
|
+
- lib/js2/tokenizer.rl.erb
|
87
|
+
- lib/js2/tree.rb
|
88
|
+
- lib/js2/universe.rb
|
103
89
|
- bin/js2
|
104
90
|
- website/index.txt
|
105
91
|
has_rdoc: true
|