aml 0.0.2 → 0.0.3

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/lib/aml/parse.rb CHANGED
@@ -1,504 +1,70 @@
1
1
  class Parse
2
- @@aml = {
3
- :argumenthash => {},
4
- :argument => {
5
- :tag_attribute_sort => true,
6
- :tag_attribute_double_quote => true
7
- },
8
- :regex => {
9
- :tag => /(?<!%)%([\w|-]+)([#|\.|][\w|-]+)?([#|\.|][\w|-]+)?(\/)?(\{.+\})?(.+)?/,
10
- :mixin => /%\(([^~][\w|-]+)\)(\{.+\})?[^\{]?/,
11
- :partial => /(%)\(\~([\w|-]+)\)/,
12
- :def_mixin => /^%%([^-][\w|-]+)(\(.+\))?\{/,
13
- :end_mixin => /^\}$/,
14
- :def_var => /^\s*?\@(\w+)\s?=\s?(.+)(?=$)/,
15
- :package => /^::([\w|-]+)(\{(.+?)\})?$/,
16
- :empty => /^$/,
17
- :string => //
18
- },
19
- :argument => /@\(\:(\w+)\)/,
20
- :variable => {
21
- :store => [],
22
- :regex => /\@\((\w+)(?=\))\)/
23
- },
24
- :threeline => /<(.+)(\s.+?)?>\r\n\t{1,}(.+)\n\t{1,}<\/\1>/,
25
- :comment => {
26
- :store => [],
27
- :regex => /\s?%!--([^$]+?)--%/
28
- },
29
- :file => {
30
- :name => nil,
31
- :param => {},
32
- :path => '',
33
- :index => 0
34
- },
35
- :log => {
36
- :error => [],
37
- :warning => []
38
- },
39
- :struct => {
40
- :file => [],
41
- :mixin => [],
42
- :markup => [],
43
- :partial => [],
44
- :selftag => ['area','base','basefont','bgsound','br','col','frame','hr','img','isindex','input','keygen','link','meta','param','source','track','wbr']
2
+ def file
3
+ return @file
4
+ end
5
+ def watch
6
+ return @watch
7
+ end
8
+ def initialize(path, file)
9
+ @path = path
10
+ @regex = {
11
+ :attribute => /@\(\:(?<name>[\w|\-]+)\)/,
12
+ :comment => /%!--[^%]*--%$/,
13
+ :variable => /\@\(((?<bundle>[\w|\-]+)\.)?(?<name>[\w|\-]+)\)/,
45
14
  }
46
- }
47
-
48
- def initialize(args={})
49
- @@aml[:argumenthash] = args
50
- end
51
-
52
- def init(file=nil,args={},index=0,output_to_file=false)
53
- file_read(file)
54
- @@aml[:file][:path] = File.dirname(file)
55
- variable_structure
56
- partial_structure
57
- ##package_structure
58
- mixin_structure
59
- markup_structure
60
- markup_structure_block
61
- @@aml[:argumenthash] = args
62
- end
63
-
64
- def file_read(file)
65
- clean_structures
66
- line = 0
67
- File.open(file,"r").each_line do |string|
68
- file_structure(line+=1,string)
69
- end
70
- #puts @@aml[:struct][:file]
71
- end
72
-
73
- def clean_structures
74
- @@aml[:variable][:store] = []
75
- @@aml[:struct] = {
76
- :file => [],
77
- :mixin => [],
78
- :markup => [],
79
- :partial => [],
80
- :selftag => ['area','base','basefont','bgsound','br','col','frame','hr','img','isindex','input','keygen','link','meta','param','source','track','wbr']
15
+ @types = {
16
+ :method => LineType.new(/^(\s{1,})?::((?<bundle>[\w|\-]+)\.)?(?<name>[\w|\-]+)(\{(?<attributes>.+)\})?/),
17
+ :variable_def => LineType.new(/^(\s{1,})?\@((?<bundle>[\w|\-]+)\.)?(?<name>[\w|\-]+)\s?(\=)\s?(?<value>.+)?$/),
18
+ :mixin => LineType.new(/^(\s{1,})?%\(((?<bundle>[\w|\-]+)\.)?(?<name>[^~][\w|\-]+)\)(\{(?<attributes>.+)\})?[^\{]?/),
19
+ :mixin_def => LineType.new(/^%%(?<name>[\w|\-]+)(\((?<attributes>.+?)\))?{/),
20
+ :mixin_end => LineType.new(/^\}$/),
21
+ :partial => LineType.new(/^(\s{1,})?%\(\~((?<bundle>[\w|\-]+)\.)?(?<name>[\w|\-]+)\)(\{(?<attributes>.+)\}[^\{]?)?$/),
22
+ :tag => LineType.new(/^(\s{1,})?(?<!%)%(?<close>\/{0,2})?(?<name>[\w|\-]+)(\#(?<id_first>[\w|\-]+))?(?<class>(\.[\w|\-]+)?{1,})?(\#(?<id_last>[\w|\-]+))?(\{(?<attributes>.+)\})?(?<text>.+)?/),
23
+ :empty => LineType.new(/^$/),
24
+ :eval => LineType.new(/^(\s{1,})?==(\s{1,})(?<value>.+)?/),
25
+ :string => LineType.new(/(\s{1,})?(?<value>.+)?/)
81
26
  }
82
- end
83
-
84
- def file_structure(line,string,baseIndex=0)
85
- type = false
86
- @@aml[:regex].each do |line_type,regex|
87
- if(string.match(regex))
88
- type = line_type.to_s
89
- break
90
- end
91
- end
92
- @@aml[:struct][:file] << {:line => line, :type => type, :index => string.match(/^\t{0,}/).to_s.length+baseIndex, :within_mixin => false, :string => string.strip}
93
- end
94
-
95
- def variable_structure
96
- @@aml[:struct][:file].each do |line|
97
- if line[:string].to_s.length > 0
98
- match = line[:string].match(@@aml[:regex][:def_var])
99
- @@aml[:variable][:store] << {:line => line[:line], :name => match[1], :value => match[2]} if match
100
- end
101
- end
102
- variable_structure_replacements
103
- variable_structure_string_lines
104
- end
105
-
106
- def variable_structure_replacements
107
- @@aml[:struct][:file].each do |line|
108
- if line[:string].to_s.length > 0
109
- if(line[:string].match(@@aml[:variable][:regex]))
110
- line[:string] = line[:string].gsub(@@aml[:variable][:regex], @@aml[:variable][:store].select{|k|k[:name] == "#{$1}" and k[:line] <= line[:line]}.last[:value])
111
- end
112
- end
113
- end
114
- end
115
-
116
- def variable_structure_string_lines
117
- @@aml[:struct][:file].each do |line|
118
- if(line[:type] == 'string')
119
- string = "#{line[:string]}"
120
- type = false
121
- @@aml[:regex].each do |line_type,regex|
122
- if(line[:string].match(regex))
123
- type = line_type.to_s
124
- break
27
+ @file = {}
28
+ @watch = []
29
+ read(file, false)
30
+ end
31
+ def read(file, partial)
32
+ line_number = 0
33
+ line_struct = []
34
+ File.open(File.join(@path,file)).read.gsub(@regex[:comment],'').each_line do |line|
35
+ @types.each do |type, line_type|
36
+ if match = line_type.match?(line)
37
+ struct = Hash[match.names.zip(match.captures)]
38
+ struct = Hash[struct.map{|(k,v)| [k.to_sym,v]}]
39
+ struct[:index] = line.match(/^\t{0,}/).to_s.length
40
+ struct[:number] = line_number+=1
41
+ struct[:type] = type
42
+ match.names.each do |name|
43
+ struct[name.to_sym] = line_type.send(name.to_s, match)
125
44
  end
126
- end
127
- line[:type] = type
128
- line[:string] = string
129
- end
130
- end
131
- end
132
-
133
- def partial_structure
134
- @@aml[:struct][:file].each do |line|
135
- if(line[:type] == 'partial')
136
- match = line[:string].match(@@aml[:regex][:partial])
137
- if(@@aml[:struct][:partial].select{|k|k[:name] == match[2]}.count == 0)
138
- @@aml[:struct][:partial] << {
139
- :name => match[2],
140
- :path => File.join(@@aml[:file][:path],'~'),
141
- :exists => File.exist?("#{File.join(@@aml[:file][:path],'~','')}#{match[2]}.aml")
142
- }
143
- end
144
- end
145
- end
146
- #puts "----- Partials"
147
- #puts @@aml[:struct][:partial]
148
- #puts "-----"
149
- end
150
-
151
-
152
- def mixin_structure
153
- @@aml[:struct][:file].each do |line|
154
- if(line[:type] == 'def_mixin')
155
- match = line[:string].match(@@aml[:regex][:def_mixin])
156
- @@aml[:struct][:mixin][@@aml[:struct][:mixin].count] = {:name => match[1], :param => match[2].nil? ? false : eval("{#{match[2][1..-2]}}"), :begin_def => line[:line], :end_def => nil}
157
- elsif(line[:type] == 'end_mixin')
158
- @@aml[:struct][:mixin][@@aml[:struct][:mixin].count-1][:end_def] = line[:line]
159
- end
160
- end
161
- mixin_structure_build
162
- end
163
-
164
- def mixin_structure_build
165
- @@aml[:struct][:mixin].each_with_index do |mixin,i|
166
- within_mixin = @@aml[:struct][:file][mixin[:begin_def]..mixin[:end_def]-2]
167
- within_mixin.each do |line|
168
- line[:within_mixin] = true
169
- end
170
- @@aml[:struct][:mixin][i][:struct] = within_mixin
171
- end
172
- end
173
-
174
- def markup_structure
175
- #file_structure(@aml[:struct][:file].count+1,"\r\n") if(@aml[:struct][:file].last[:index] == 0)
176
- @@aml[:struct][:file].each do |line|
177
- if(line[:within_mixin] == false)
178
- markup_line = line.clone
179
- case line[:type]
180
- when 'tag'
181
- markup_structure_line_tag(markup_line,line[:index])
182
- when 'string'
183
- markup_structure_line_string(markup_line,line[:index])
184
- when 'mixin'
185
- markup_structure_line_mixin(markup_line,line[:index])
186
- when 'partial'
187
- markup_structure_line_partial(markup_line,line[:index])
188
- end
189
- end
190
- end
191
- end
192
-
193
- def markup_structure_line_tag(line,baseIndex)
194
- if line[:string].to_s.length > 0
195
- match = line[:string].match(@@aml[:regex][:tag])
196
- data = line.merge({:selftag => match[4].nil? == false, :param => match[5].nil? ? {} : eval("#{match[5]}"), :match => match[1..-2]})
197
- data[:param]["#{data[:match][1][0] == '#' ? 'id' : 'class'}".to_sym] = data[:match][1][1..-1] if(data[:match][1])
198
- data[:param]["#{data[:match][2][0] == '#' ? 'id' : 'class'}".to_sym] = data[:match][2][1..-1] if(data[:match][2])
199
- @@aml[:struct][:selftag].each do|tag|
200
- if(match[1] == tag)
201
- data[:selftag] = true
202
- break
203
- end
204
- end
205
- @@aml[:struct][:markup] << data
206
- if(match[6].nil? == false) then
207
- @@aml[:struct][:markup] << {:line => line[:line], :type=> 'string', :index => line[:index]+1, :within_mixin => line[:within_mixin], :string => "#{match[6].to_s.strip!}", :selftag => true, :match => []}
208
- end
209
-
210
- end
211
- end
212
-
213
- def markup_structure_line_string(line,baseIndex)
214
- #line[:string] = line[:string].gsub(@aml[:argument], get_argument_for(line,"#{$1}").to_s) if(line[:within_mixin] and line[:string].to_s.length > 0 and line[:string].match(@aml[:argument]))
215
- if(line[:within_mixin] and line[:string].to_s.length > 0)
216
- line[:string] = line[:string].gsub(@@aml[:argument]){|m|get_argument_for(line, "#{$1}".to_s)}
217
- end
218
- @@aml[:struct][:markup] << line.merge({:param => false, :selftag => true, :match => []})
219
- end
220
-
221
- def markup_structure_line_mixin(line,baseIndex)
222
- #puts "#{line[:string]} - #{baseIndex}"
223
- match = "#{line[:string]}".match(@@aml[:regex][:mixin])
224
- param = match[2].nil? ? false : eval("{#{match[2][1..-2]}}")
225
- exists = false
226
- @@aml[:struct][:mixin].each do |mixin_index|
227
- if(mixin_index[:name] == match[1])
228
- mixin_index[:struct].each do |mixin_line|
229
- markup_line = mixin_line.clone
230
- markup_line[:index] = (markup_line[:index]-1) + line[:index]
231
-
232
- markup_line[:mixin] = {
233
- :name => mixin_index[:name],
234
- :param => param
235
- }
236
-
237
- markup_line[:string] = markup_line[:string].gsub(@@aml[:argument]){|m|get_argument_for(markup_line, "#{$1}".to_s)}
238
-
239
- case markup_line[:type]
240
- when 'tag'
241
- markup_structure_line_tag(markup_line,markup_line[:index])
242
- when 'string'
243
- markup_structure_line_string(markup_line,markup_line[:index])
244
- when 'mixin'
245
- markup_structure_line_mixin(markup_line,markup_line[:index])
246
- when 'partial'
247
- markup_structure_line_partial(markup_line,markup_line[:index])
45
+ if struct[:name].to_s[0,1] == '.'
46
+ #set undefined bundle
47
+ struct[:bundle] = 'core'
48
+ struct[:name] = struct[:name][1,struct[:name].length]
248
49
  end
50
+ struct[:bundle] = false if struct[:bundle].to_s.length == 0
51
+ #set undefined method bundle
52
+ struct[:bundle] = 'core' if struct[:type] == :method and !struct[:bundle]
53
+ struct[:id] = struct[:id_first].to_s.length > 0 ? struct[:id_first] : struct[:id_last]
54
+ struct.delete(:id_first)
55
+ struct.delete(:id_last)
56
+ line_struct << Hash[struct.sort] if struct[:type] != :empty
57
+ break
249
58
  end
250
- exists = true
251
- break
252
- end
253
- end
254
- if(exists == false)
255
- #log('warning', "The mixin <#{match[1]}> called on line <#{line[:line]}> does not exist")
256
- end
257
- end
258
-
259
- def markup_structure_line_partial(line,baseIndex)
260
- match = line[:string].match(@@aml[:regex][:partial])
261
- if(@@aml[:struct][:partial].select{|k|k[:name]==match[2]}.count == 1)
262
- partial = @@aml[:struct][:partial].select{|k|k[:name]==match[2]}.first
263
- if partial[:exists]
264
- line = 0
265
- File.open(File.join("#{partial[:path]}","#{partial[:name]}.aml"),"r").each_line do |string|
266
- file_structure(line+=1,string,baseIndex)
267
- end
268
- else
269
- #log('warning', "The partial <#{match[2]}> called on line <#{line[:line]}> does not exist in path <#{partial[:path]}>.")
270
- end
271
- end
272
- end
273
-
274
- def get_argument_for(line,argument)
275
- value = line[:mixin][:param].select{|k,x|k.to_s==argument}[argument.to_sym] if(line.has_key?(:mixin) and line[:mixin].has_key?(:param) and line[:mixin][:param] != false)
276
- value = @@aml[:struct][:mixin].select{|k| line[:mixin][:name] == k[:name] and line[:line] > k[:begin_def] and line[:line] < k[:end_def]}.last[:param].select{|k,x|k.to_s==argument}[argument.to_sym] if(value.nil?)
277
- return value
278
- end
279
-
280
- def hash_to_attribute(hash)
281
- attribute = hash_to_attribute_build(hash).strip
282
- attribute = " #{attribute}" if(attribute.length > 0)
283
- end
284
-
285
- def hash_to_attribute_build(hash,base="")
286
- hash = hash.sort_by{|key, value| key}
287
- string = ""
288
- hash.each do |key, value|
289
- if(value.is_a?(Hash))
290
- value.sort_by{|key, value| key}
291
- string << "#{hash_to_attribute_build(value,"#{base}#{key}-")} "
292
- else
293
- string << "#{base}#{key}=\"#{value}\" "
294
- end
295
- end
296
- string.strip
297
- end
298
-
299
- def close_open_tag(open_tag,close=[])
300
- if(open_tag.count >= 2)
301
- if(open_tag[0][:tag] == open_tag[1][:tag])
302
- if(open_tag[0][:closing] == false and open_tag[1][:closing] != open_tag[0][:closing])
303
- close_open_tag(open_tag[2...open_tag.count],close)
304
- else
305
- close << open_tag[0]
306
- close_open_tag(open_tag[1...open_tag.count],close)
307
- end
308
- else
309
- close << open_tag[0]
310
- close_open_tag(open_tag[1...open_tag.count],close)
311
59
  end
312
- else
313
- close << open_tag[0] if(open_tag.count == 1)
314
60
  end
315
- close
316
- end
317
-
318
- def close_tags(output,high_index_force=false)
319
- high_index = 0
320
- if(high_index_force != false)
321
- high_index = high_index_force
322
- else
323
- output.each do |line|
324
- high_index = line[:index] if(line[:index] > high_index and line[:tag] != false)
325
- end
326
- end
327
- open_tag = []
328
- output.each_with_index do |line,index|
329
- if(line[:index] == high_index and line[:tag] != false)
330
- line[:number] = index
331
- open_tag << line
332
- end
333
- end
334
- tags_to_close = close_open_tag(open_tag)
335
- offset = 0
336
- tags_to_close.reverse.each do |line|
337
- closeTag = line
338
- output.each_with_index do |line,index|
339
- if(index > closeTag[:number])
340
- if(line[:index] == closeTag[:index] or line[:index] <= closeTag[:index]-1)
341
- output.insert(index, {:index => closeTag[:index], :tag => closeTag[:tag], :string => "</#{closeTag[:tag]}>"})
342
- break
343
- end
344
- end
345
- end
346
- end
347
- if(high_index > 1)
348
- output = close_tags(output,high_index-1)
349
- end
350
- output
351
- end
352
-
353
-
354
-
355
- def markup_structure_block
356
- #@@aml[:struct][:markup].each do |line|
357
- #puts "#{' '*line[:index]}#{line[:string]}\r\n"
358
- #end
359
-
360
- markup = []
361
- @@aml[:struct][:markup].each_with_index do |line,i|
362
- string = ""
363
- tag = false
364
- if(line[:match][0].nil?) then
365
- string = line[:string]
366
- else
367
- tag = line[:match][0]
368
- selftag = ''
369
- selftag = ' /' if(line[:selftag] and @@aml[:struct][:selftag].include? line[:match][0])
370
- string = "<#{line[:match][0]}#{hash_to_attribute(line[:param])}#{selftag}>"
371
- end
372
- markup << {:line => i+1, :index => line[:index], :tag => (line[:selftag]) ? false : tag, :string => string}
373
- end
374
- @@aml[:struct][:markup] = markup
375
- markup = []
376
- @@aml[:struct][:markup] = markup_block
377
-
378
- output = ''
379
- @@aml[:struct][:markup].each do |block|
380
- block = markup_block_resursive(block[:block]).reverse
381
- output += markup_block_group(block).to_s + "\r\n"
382
- end
383
- File.open("#{File.join(@@aml[:argumenthash][:basePath],@@aml[:argumenthash][:fileOutput])}", 'w'){|f| f.write(output.strip!)}
384
- end
385
-
386
- def markup_block(begin_line=0,struct=[])
387
- def_block = []
388
- end_block = false
389
- index_one = false
390
- end_line = begin_line
391
- @@aml[:struct][:markup].each_with_index do |line,i|
392
- if(line[:line] >= begin_line and end_block == false)
393
- index_one = true if(line[:index] > 0)
394
- end_block = true if(line[:index] == 0 and index_one)
395
- if(end_block == false)
396
- def_block << line
397
- end_line = line[:line]
398
- end
399
- else
400
- @@aml[:struct][:markup].delete_if{|x| x[:line] <= end_line}
401
- break
402
- end
403
- end
404
- if(@@aml[:struct][:markup].count > 0 and @@aml[:struct][:markup].select{|k|k[:line]}.last[:line] > end_line)
405
- markup_block(end_line+1,struct)
406
- end
407
- struct << {:line => {:begin=>begin_line, :end => end_line}, :block => def_block}
408
- struct.flatten.reverse
409
- end
410
-
411
- def markup_block_resursive(markup,struct=[])
412
- def_block = []
413
- last_index = 0
414
- markup.each do |line|
415
- if(line[:index] >= last_index)
416
- def_block << line
417
- last_index = line[:index]
418
- else
419
- markup_block_resursive(markup.select{|k|k[:line]>=line[:line]},struct)
420
- break
421
- end
422
- end
423
- struct << def_block
424
- end
425
-
426
- def markup_block_group(blocks)
427
- #puts blocks
428
- #puts "-"
429
- output = []
430
- zeroIndex = []
431
- lastLine = false
432
- blocks.each_with_index do |block,index|
433
-
434
- block.each_with_index do |line,i|
435
- if(line[:index]>0)
436
- #set next line
437
- nextLine = false
438
- nextLine = block[i+1] if(block.count > i+1)
439
- output << {:index => line[:index], :tag => line[:tag], :closing => false, :string => line[:string]}
440
- #close tags on same index
441
- if(nextLine and nextLine[:index] == line[:index])
442
- output << {:index => line[:index], :tag => line[:tag], :closing => true, :string => "</#{line[:tag]}>"} if(line[:tag] != false)
443
- line[:tag] = false
444
- end
445
-
446
- else
447
- #add line to zeroIndex, close tags in reverse order
448
- output << {:index => line[:index], :tag => line[:tag], :closing => false, :string => line[:string]}
449
- #line[:tag] = false
450
- zeroIndex << line
451
-
452
- if(lastLine and lastLine[:index] == 0)
453
- output << {:index => lastLine[:index], :tag => lastLine[:tag], :closing => true, :string => "</#{lastLine[:tag]}>"} if(lastLine[:tag] != false)
454
- lastLine[:tag] = false
455
- end
456
- end
457
- lastLine = line
458
- end
459
-
460
- end
461
-
462
- #close zero index tags
463
- zeroIndex = zeroIndex.drop(zeroIndex.count-1) if @@aml[:struct][:file].select{|k|k[:index] != 0}.count == 0
464
- zeroIndex.reverse.each do |line|
465
- output << {:index => line[:index], :tag=> line[:tag], :closing => true, :string => "</#{line[:tag]}>"} if(line[:tag] != false and line[:index] == 0)
466
- end
467
-
468
- #go up the chain in reverse (recursive) to find unclosed tags
469
- output = close_tags(output)
470
- sout = ""
471
- output.each do |line|
472
- sout += "#{' '*line[:index]}#{line[:string]}\r\n"
473
- end
474
- sout.strip!
475
- end
476
-
477
-
478
-
479
-
480
-
481
-
482
-
483
- def process_package
61
+ @file = {:name => file, :line => line_struct}
62
+ @watch << {:file => file, :bundle => false, :partial => false}
63
+ partial_watch(line_struct)
484
64
  end
485
-
486
- def process_partials(file)
487
- partial = []
488
- File.open(file,"r").each_line do |string|
489
- type = false
490
- @@aml[:regex].each do |line_type,regex|
491
- if(string.match(regex))
492
- type = line_type.to_s
493
- break
494
- end
495
- end
496
- if(type == 'partial')
497
- match = string.match(@@aml[:regex][:partial])
498
- partial << {:name=>match[2]}
499
- end
65
+ def partial_watch(struct)
66
+ struct.reject{|k,v| k[:type] != :partial}.each do |partial|
67
+ @watch << {:file => "#{partial[:name]}.aml", :bundle=> partial[:bundle], :partial => true}
500
68
  end
501
- partial
502
69
  end
503
-
504
70
  end
@@ -0,0 +1,8 @@
1
+ require 'aml/error'
2
+ require 'aml/argument'
3
+ require 'aml/line_type'
4
+ require 'aml/parse'
5
+ require 'aml/watch'
6
+ require 'aml/definition'
7
+ require 'aml/make'
8
+ require 'aml/compile'
data/lib/aml/watch.rb CHANGED
@@ -1,34 +1,33 @@
1
1
  class Watch
2
- def initialize
3
- end
4
-
5
- def process(filenames)
2
+ def initialize(filenames, arguments, instance, build)
3
+ @arguments = arguments
4
+ @instance = instance
6
5
  filenames = [filenames] if(filenames.kind_of?String)
7
- @last_mtimes = {}
8
- filenames.each do |filename|
9
- @last_mtimes[filename] = File.stat(filename).mtime
10
- end
11
- @filenames = filenames
12
- end
13
-
6
+ @last_mtimes = {}
7
+ filenames.each do |filename|
8
+ @last_mtimes[filename] = File.stat(filename).mtime
9
+ end
10
+ @filenames = filenames
11
+ watch
12
+ end
14
13
  def watch(sleep=1)
15
14
  loop do
16
15
  begin
17
16
  Kernel.sleep sleep until file_updated?
18
- rescue SystemExit,Interrupt
19
- puts "\r\n"
17
+ rescue SystemExit,Interrupt
18
+ puts ""
20
19
  Kernel.exit
21
20
  end
22
21
  end
23
22
  end
24
-
25
23
  def file_updated?
26
24
  @filenames.each do |filename|
27
25
  mtime = File.stat(filename).mtime
28
26
  updated = @last_mtimes[filename] < mtime
29
27
  @last_mtimes[filename] = mtime
30
28
  if(updated)
31
- AbstractMarkupLanguage::Base.new.file_update(filename)
29
+ exec("aml #{@arguments} --aml-watch-instance #{@instance}")
30
+ Kernel.exit
32
31
  return true
33
32
  end
34
33
  end
data/lib/aml-bundle.rb ADDED
@@ -0,0 +1,58 @@
1
+ require "awesome_print"
2
+ require 'fileutils'
3
+ require 'aml/argument'
4
+ module AbstractMarkupLanguage
5
+ class Bundle
6
+ def self.initialize(arguments)
7
+ argument = Argument.new(arguments)
8
+ #argument.create_action('create')
9
+ #argument.create_action('install')
10
+ #argument.create_action('update')
11
+ #argument.create_action('delete')
12
+
13
+
14
+
15
+ argument.required('name','The required --name argument has not been defined.')
16
+ if argument.has_requirements?#and directory exists false?)
17
+ basePath = File.dirname('~')
18
+
19
+ argument.create_if_empty('--','bundle')
20
+
21
+ #aml-bundle install
22
+ #aml-bundle create
23
+ #aml-bundle
24
+
25
+ argument.create_if_empty('method','')
26
+ argument.create_if_empty('mixin','')
27
+ argument.create_if_empty('partial','')
28
+ #ap argument.hash
29
+ name = {:directory => argument.read('name').downcase.gsub(' ','-'), :class => argument.read('name').gsub(' ','')}
30
+ FileUtils.mkdir_p(File.join(name[:directory],'partial'))
31
+ %w"method.rb mixin.aml".each do |file|
32
+ File.new(File.join(name[:directory],"#{file}"), 'w')
33
+ end
34
+ mixins = "%!-- #{argument.read('name')} Mixin Definitions --%"
35
+ argument.read('mixin').split(' ').each do |mixin|
36
+ mixin = mixin.split(':')
37
+ mixin_name = mixin[0]
38
+ attributes = ""
39
+ if mixin.count > 1
40
+ mixin.shift
41
+ mixin.each do |attribute|
42
+ a = attribute.split('=')
43
+ attributes +="#{a[0]}='#{a[1]}',"
44
+ end
45
+ attributes = "(#{attributes[0..-2]})"
46
+ end
47
+ mixins += "\r\n%%#{mixin_name}#{attributes}{\r\n\t\r\n}"
48
+ end
49
+ File.open(File.join(name[:directory],'mixin.aml'), 'w'){|file|file.write(mixins)}
50
+ File.open(File.join(name[:directory],'method.rb'), 'w'){|file|file.write("class #{name[:class]}\r\n\tdef self.aml\r\n\t\t\r\n\tend\r\nend")}
51
+ argument.read('partial').split(' ').each do |partial|
52
+ File.new(File.join(name[:directory],'partial',"#{partial}.aml"),'w')
53
+ end
54
+ end
55
+ end
56
+
57
+ end
58
+ end