aml 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 99123f17f26debf93e4218deeaba35d2d22caeac
4
- data.tar.gz: ef412c33d163c79d6e4a91d34563280062846a53
3
+ metadata.gz: 269daf118df596cb722b1e749453e59a03c24fd7
4
+ data.tar.gz: 21f56707e802f9a1f8183b1abc65d3aee99f76b9
5
5
  SHA512:
6
- metadata.gz: fc9d6ee0f6bfd5c4567f87bb58381d634bcad4057e5b494429a6d28f357f73b1ab743bba0a3d4c104bbe04818df5f79bf4ea88c1af847ae6bf2b175111a0e384
7
- data.tar.gz: 3908079e214a5517704ac033acc20034851791cf41be7962f53c81f7b15eecdcebae7c55d78a15f0a2a4e96ae3d5c0bf5ce64c2ab2661fe60cd8adc833a2ddae
6
+ metadata.gz: 1d3fc6f980e8141150b6d496840d1e71c82287eb16506aca3192c401b09b808593658be1e2ec358473dfbae3d381fd01e503ae9319931d9a39ad8a716f2166dd
7
+ data.tar.gz: 1995da921b1f8e4822575c52b375ca5b535648a5421f140df37334c72ee6e231620a1cc6358696517a54e278b8ddae868f1abfccd1937b60ff87e178f9aa3fe5
data/lib/aml.rb CHANGED
@@ -27,7 +27,7 @@ module AbstractMarkupLanguage
27
27
  @basePath = basePath
28
28
  watchFile = File.basename(argument.read('watch'))
29
29
  @watchFile = watchFile
30
- #AML Config Arguments
30
+ #Arguments from aml-config
31
31
  configFile = File.join(basePath,'aml-config')
32
32
  argument.parse(File.read(configFile)) if File.exist?(configFile)
33
33
  #Arguments
@@ -35,20 +35,25 @@ module AbstractMarkupLanguage
35
35
  argument.create_if_empty('basePath',basePath)
36
36
  argument.create_if_empty('fileExtension','html')
37
37
  argument.create_if_empty('fileOutput',"#{File.basename(argument.read('watch'), ".*")}.#{argument.read('fileExtension')}")
38
- argument.create_if_empty('selfClosing',"area,base,basefont,bgsound,br,col,frame,hr,img,isindex,input,keygen,link,meta,param,source,track,wbr")
39
- argument.create_if_empty('sortAttribute','true')
40
- argument.create_if_empty('singleQuote','false')
41
- argument.create_if_empty('errorLimit','5')
42
38
  argument.create_if_empty('aml-watch-instance', "#{instance}")
39
+
40
+ argument.create_if_empty('selfClosing',"area,base,basefont,bgsound,br,col,frame,hr,img,isindex,input,keygen,link,meta,param,source,track,wbr")
43
41
 
44
42
  parse = Parse.new(argument.read('basePath'), argument.read('watch'))
45
43
  files = []
46
44
 
45
+ #Watch Partials
47
46
  parse.watch.each do |this|
48
47
  file = File.join(basePath, this[:bundle] ? File.join(this[:bundle],'partial') : this[:partial] ? 'partial' : '' , this[:file])
49
48
  files << file
50
49
  end
51
50
 
51
+ #Watch Mixins
52
+ parse.mixin.each do |this|
53
+ file = File.join(basePath, this[:bundle] ? File.join(this[:bundle]) : this[:partial] ? 'partial' : '' , this[:file]) if this[:bundle] != false
54
+ files << file if file != nil
55
+ end
56
+
52
57
  #Define Core Bundle's Methods, Mixins, & Variables...
53
58
  core_definition = false
54
59
  if(File.exists?(File.join(File.dirname(File.expand_path(__FILE__)),'aml','core','mixin.aml')))
@@ -58,6 +63,7 @@ module AbstractMarkupLanguage
58
63
  else
59
64
  error.log('core',false,'mixin.aml',false,'file does not exist')
60
65
  end
66
+
61
67
  if(File.exists?(File.join(File.dirname(File.expand_path(__FILE__)),'aml','core','method.rb')))
62
68
  begin
63
69
  class_eval File.read(File.join(File.dirname(File.expand_path(__FILE__)),'aml','core','method.rb'))
@@ -102,29 +108,27 @@ module AbstractMarkupLanguage
102
108
  end
103
109
  end
104
110
 
111
+ #Watch or Build
105
112
  @makeFile = argument.read('fileOutput')
106
113
  compile = Compile.new(parse,argument,definition,error)
107
- if(error.count == 0)
108
- error.log_delete
109
- if argument.read('build') == 'false'
110
- #print "\r\b\e[0K#{Gem.loaded_specs['aml'].summary.to_s} is watching #{files.count-1} partial instance#{files.count-1 != 1 ? "s" : ""}""... (#{argument.read('aml-watch-instance').to_i+1}) "
111
- print "\r\b\e[0K#{Gem.loaded_specs['aml'].summary.to_s} is watching #{files.count-1} partial instance#{files.count-1 != 1 ? "s" : ""}""... (#{argument.read('aml-watch-instance').to_i+1}) "
112
- watch = Watch.new(files, arguments, argument.read('aml-watch-instance').to_i+1, argument.read('build'))
114
+ error.log_delete if error.count == 0
115
+ error.log_create if error.count > 0
116
+ if argument.read('build') == 'false'
117
+ if(error.count == 0)
118
+ print "\r\b\e[0KWatching #{files.count} file#{files.count != 1 ? "s" : ""}"" for updates... "
113
119
  else
114
- puts "Build complete..."
120
+ print "\r\b\e[0KPlease resolve all issues found in aml-error... "
115
121
  end
122
+ watch = Watch.new(files, arguments, argument.read('aml-watch-instance').to_i+1, argument.read('build'))
116
123
  else
117
- error_count = error.count == 1 ? "" : "s"
118
- if error.count <= argument.read('errorLimit').to_i
119
- error.log_delete
120
- puts error.output
124
+ if(error.count == 0)
125
+ puts "Build complete."
121
126
  else
122
- error.log_create
123
- print "\r\n#{error.count} error#{error_count} occured, please see error.log for details.\r\n"
124
- end
127
+ puts "Please resolve all issues found in aml-error."
128
+ end
125
129
  end
126
130
  else
127
- puts "Please define the --watch or --build argument."
131
+ puts argument.read('watch').to_s.length == 0 ? "Please define the --watch or --build argument." : "File not found."
128
132
  end
129
133
  end
130
134
 
@@ -1,8 +1,10 @@
1
1
  class Compile
2
2
 
3
3
  @@structure = []
4
-
4
+ @@selfClosing = []
5
+
5
6
  def initialize(parse,argument,definition,error)
7
+ @@selfClosing = argument.read('selfClosing').split(',')
6
8
  error.compile(parse,definition,error)
7
9
  if(error.count == 0)
8
10
  prepare_line_variable(parse.file[:line],definition)
@@ -19,7 +21,7 @@ class Compile
19
21
 
20
22
  structure = prepare_structure(parse.file[:line])
21
23
  structure.each do |group|
22
- recursive_close(group)
24
+ recursive_close(group,0,definition)
23
25
  end
24
26
  make = Make.new(@@structure)
25
27
  end
@@ -202,7 +204,7 @@ class Compile
202
204
  pstruct[:children]
203
205
  end
204
206
 
205
- def recursive_close(struct,index=0)
207
+ def recursive_close(struct,index=0,definition)
206
208
  next_index = struct.key?(:line) ? index+1 : index
207
209
  tab_index = "\t" * index
208
210
  opening_tag_attributes = ""
@@ -216,7 +218,10 @@ class Compile
216
218
 
217
219
  #TAG
218
220
  if(struct[:line][:type]==:tag)
219
- opening_tag_attributes = tag_line_attributes(struct[:line])
221
+
222
+ struct[:line][:close] = 'self' if @@selfClosing.include? struct[:line][:name]
223
+
224
+ opening_tag_attributes = tag_line_attributes(struct[:line],"",definition)
220
225
  opening_tag = "<#{struct[:line][:name]}#{opening_tag_attributes}>"
221
226
  closing_tag = "</#{struct[:line][:name]}>"
222
227
  if struct.key?(:line)
@@ -234,7 +239,7 @@ class Compile
234
239
  tag_text = "\r\n#{tab_index}\t#{tag_text}" if tag_text.to_s.length > 0
235
240
  @@structure << "#{tab_index}#{opening_tag}#{tag_text}" if struct.key?(:line)
236
241
  struct[:children].each do |struct_children|
237
- recursive_close(struct_children,next_index)
242
+ recursive_close(struct_children,next_index,definition)
238
243
  end
239
244
  @@structure << "#{tab_index}#{closing_tag}" if struct.key?(:line)
240
245
  else
@@ -243,23 +248,27 @@ class Compile
243
248
 
244
249
  end
245
250
 
246
- def tag_line_attributes(line,base="")
251
+ def tag_line_attributes(line,base="",definition)
247
252
  if line[:type] == :tag
248
253
  line[:attributes][:id] = line[:id] if line[:id].to_s.length > 0 and line[:attributes][:id].to_s.length == 0
249
254
  line[:attributes][:class] = line[:class] if line[:class].to_s.length > 0 and line[:attributes][:class].to_s.length == 0
250
- attributes = hash_to_attribute_build(line[:attributes])
255
+ attributes = hash_to_attribute_build(line[:attributes],"",definition,line)
251
256
  attributes = " #{attributes}" if(attributes.length > 0)
252
257
  end
253
258
  end
254
259
 
255
- def hash_to_attribute_build(hash,base="")
260
+ def hash_to_attribute_build(hash,base="",definition,line)
256
261
  hash = hash.sort_by{|key, value| key}
257
262
  string = ""
258
263
  hash.each do |key, value|
259
264
  if(value.is_a?(Hash))
260
265
  value.sort_by{|key, value| key}
261
- string << "#{hash_to_attribute_build(value,"#{base}#{key}-")} "
266
+ string << "#{hash_to_attribute_build(value,"#{base}#{key}-",definition,line)} "
262
267
  else
268
+ #if key == :id
269
+ # regex = /\@\(((?<bundle>[\w|\-]+)\.)?(?<name>[\w|\-]+)\)/
270
+ # value = value.to_s.gsub(regex){definition.variable($2,line[:number],$1.to_s.length > 0 ? $1 : false).to_s} if value.to_s.length > 0
271
+ #end
263
272
  string << "#{base}#{key}=\"#{value}\" "
264
273
  end
265
274
  end
@@ -17,7 +17,7 @@ class Definition
17
17
  end
18
18
  def add(parse,scope=false,add_bundle=true,add_mixin=true,add_variable=true)
19
19
  #define bundles
20
- parse[:line].select{|k,v| k[:type] == :method or k[:type] == :partial}.each do |bundle|
20
+ parse[:line].select{|k,v| k[:type] == :method or k[:type] == :partial or k[:type] == :mixin}.each do |bundle|
21
21
  @bundle[bundle[:bundle]] = camelCase(bundle[:bundle]) if @bundle.has_key?(bundle[:bundle]) == false and bundle[:bundle] != false
22
22
  end if add_bundle
23
23
  #define mixins
@@ -1,29 +1,42 @@
1
1
  class Error
2
2
  @errors
3
+ @warnings
3
4
  def initialize
4
5
  @errors = []
6
+ @warnings = []
5
7
  end
6
- def log(bundle,partial,file,line,message)
8
+ def warnings
9
+ @warnings
10
+ end
11
+ def log(bundle,partial,file,line,message,warning=false)
7
12
  file = "partial/#{file}" if partial != false
8
13
  file = "#{bundle}/#{file}" if bundle != false
9
14
  line = line ? "::#{line}" : nil
10
- @errors << "#{file}#{line} #{message}"
15
+ text = "#{file}#{line} #{message}"
16
+ if warning
17
+ @warnings << text
18
+ else
19
+ @errors << text
20
+ end
11
21
  end
12
22
  def count
13
23
  @errors.count
14
24
  end
15
25
  def log_delete
16
26
  begin
17
- File.delete(File.join(AbstractMarkupLanguage::Base.basePath,'error.log'))
27
+ File.delete(File.join(AbstractMarkupLanguage::Base.basePath,'aml-log'))
18
28
  rescue Exception => e
19
29
  end
20
30
  end
21
31
  def log_create
22
32
  error_output = ""
23
33
  @errors.each do |error|
24
- error_output += "#{error}\r\n"
34
+ error_output += "Error: #{error}\r\n"
35
+ end
36
+ @warnings.each do |warning|
37
+ error_output += "Warning: #{warning}\r\n"
25
38
  end
26
- File.write(File.join(AbstractMarkupLanguage::Base.basePath,'error.log'),error_output)
39
+ File.write(File.join(AbstractMarkupLanguage::Base.basePath,'aml-log'),error_output)
27
40
  end
28
41
  def output
29
42
  @errors.each do |error|
@@ -4,7 +4,7 @@ class Make
4
4
  File.open(makeFile, 'w'){|file|
5
5
  struct_count = structure.count-1
6
6
  structure.each_with_index do |line,index|
7
- new_line = (index < struct_count) ? "\r\n" : ""
7
+ new_line = (index < struct_count) ? $/ : ""
8
8
  file.write(line+new_line) if line.strip.length > 0
9
9
  end
10
10
  }
@@ -5,6 +5,9 @@ class Parse
5
5
  def watch
6
6
  return @watch
7
7
  end
8
+ def mixin
9
+ return @mixin
10
+ end
8
11
  def initialize(path, file, partial=false, bundle=false)
9
12
  @path = path
10
13
  @regex = {
@@ -19,13 +22,14 @@ class Parse
19
22
  :mixin_def => LineType.new(/^%%(?<name>[\w|\-]+)(\((?<attributes>.+?)\))?{/),
20
23
  :mixin_end => LineType.new(/^\}$/),
21
24
  :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>.+)?/),
25
+ :tag => LineType.new(/^(\s{1,})?(?<!%)%(?<close>\/{0,2})?(?<name>[\w|\-]+)(\#(?<id_first>(\@\(([\w|-]+\.)?)?[\w|\-]+(\))?))?(?<class>(\.[\w|\-]+)?{1,})?(\#(?<id_last>[\w|\-]+))?(\{(?<attributes>.+)\})?(?<text>.+)?/),
23
26
  :empty => LineType.new(/^$/),
24
27
  :eval => LineType.new(/^(\s{1,})?==(\s{1,})(?<value>.+)?/),
25
28
  :string => LineType.new(/(\s{1,})?(?<value>.+)?/)
26
29
  }
27
30
  @file = {}
28
31
  @watch = []
32
+ @mixin = []
29
33
  read(file, partial, bundle)
30
34
  end
31
35
  def read(file, partial, bundle)
@@ -62,10 +66,16 @@ class Parse
62
66
  @file = {:name => file, :line => line_struct}
63
67
  @watch << {:file => file, :bundle => false, :partial => false}
64
68
  partial_watch(line_struct)
69
+ mixin_watch(line_struct)
65
70
  end
66
71
  def partial_watch(struct)
67
72
  struct.reject{|k,v| k[:type] != :partial}.each do |partial|
68
73
  @watch << {:file => "#{partial[:name]}.aml", :bundle=> partial[:bundle], :partial => true}
69
74
  end
70
75
  end
76
+ def mixin_watch(struct)
77
+ struct.reject{|k,v| k[:type] != :mixin}.each do |partial|
78
+ @mixin << {:file => "mixin.aml", :bundle=> partial[:bundle], :partial => false} if partial[:bundle] != 'core'
79
+ end
80
+ end
71
81
  end
@@ -5,7 +5,7 @@ class Watch
5
5
  filenames = [filenames] if(filenames.kind_of?String)
6
6
  @last_mtimes = {}
7
7
  filenames.each do |filename|
8
- @last_mtimes[filename] = File.stat(filename).mtime
8
+ @last_mtimes[filename] = File.stat(filename).mtime if File.exists?(filename)
9
9
  end
10
10
  @filenames = filenames
11
11
  watch
@@ -22,13 +22,15 @@ class Watch
22
22
  end
23
23
  def file_updated?
24
24
  @filenames.each do |filename|
25
- mtime = File.stat(filename).mtime
26
- updated = @last_mtimes[filename] < mtime
27
- @last_mtimes[filename] = mtime
28
- if(updated)
29
- exec("aml #{@arguments} --aml-watch-instance #{@instance}")
30
- Kernel.exit!
31
- return true
25
+ if File.exists?(filename)
26
+ mtime = File.stat(filename).mtime
27
+ updated = @last_mtimes[filename] < mtime
28
+ @last_mtimes[filename] = mtime
29
+ if(updated)
30
+ exec("aml #{@arguments} --aml-watch-instance #{@instance}")
31
+ Kernel.exit!
32
+ return true
33
+ end
32
34
  end
33
35
  end
34
36
  return false
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Esquivias
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-01 00:00:00.000000000 Z
11
+ date: 2014-02-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Abstract Markup Language is a robust and feature rich markup language
14
14
  designed to avoid repetition and promote clear, well-indented markup.