aml 0.1.0 → 0.1.1

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: d46123901065fe56b8a4c50b0f238a15ca7e59ff
4
- data.tar.gz: 4a9a0cf2415bc9e6685aef3d7715c284b5051859
3
+ metadata.gz: 4af0b2c9bbd9723b035c8f29956a1ac9872ef2b1
4
+ data.tar.gz: 4f9c97308477ad6c0beff75c2b66a829c8e34751
5
5
  SHA512:
6
- metadata.gz: 9c59f3a70af0b23062c3c5be6ece1d05661a330b64661a5decf137021f583d3ffaf66e25297f9626eb333d8dc1100a535819a58f7a30dbefb66e4413ea8b7a64
7
- data.tar.gz: 1b90d8a2e4dd82266714ff9d526cdf67d7f2ae764d41d9a6e3058c9fe3f44e783512b365b7b275fef0ca779b7b924d0b7506f6e6e03ab81e25b87512b68d4fea
6
+ metadata.gz: 4a312f58c7c93767a29b67102814404f98c13f78ed6ae6770a32c9972acadd0eea01f8df59563db238563ec716b8d4b001d86654d9cedd7691958bdad13ac971
7
+ data.tar.gz: f098df54530764d179c90085318d2e65dd0793b330e8d10354f61f8aa0eec758bdfdcf89c767c952b1399fd658c07edd5e08c530c35b50dc14418acf50214ca0
data/lib/aml/argument.rb CHANGED
@@ -46,7 +46,7 @@ class Argument
46
46
  end
47
47
 
48
48
  def create(name,value)
49
- @@argumental[name.to_sym] = value.strip if(value.length > 0)
49
+ @@argumental[name.to_sym] = value.strip #if(value.length > 0)
50
50
  end
51
51
 
52
52
  def create_if_empty(name,value)
@@ -57,6 +57,10 @@ class Argument
57
57
  @@argumental[name.to_sym]
58
58
  end
59
59
 
60
+ def defined(name)
61
+ @@argumental.select{|k,v| k.to_s == name}.count > 0
62
+ end
63
+
60
64
  def update(name,value)
61
65
  create(name,value)
62
66
  end
data/lib/aml/compile.rb CHANGED
@@ -19,21 +19,62 @@ class Compile
19
19
  prepare_partial_structure(parse.file[:line],definition)
20
20
  prepare_method_structure(parse.file[:line],definition)
21
21
 
22
+ prepare_string_line_merge(parse.file[:line])
23
+
22
24
  structure = prepare_structure(parse.file[:line])
25
+
26
+ recursive_merge_lines(structure)
27
+
23
28
  structure.each do |group|
24
- recursive_close(group,0,definition)
29
+ recursive_close(group,0,definition,0)
25
30
  end
31
+
26
32
  make = Make.new(@@structure)
27
33
  end
28
34
  end
29
35
 
36
+ def recursive_merge_lines(struct,count=0)
37
+ struct.each_with_index do |group,struct_index|
38
+ group.each_with_index do |line,gindex|
39
+ if line.first == :line
40
+ if line.last[:type] == :string and line.last[:merge]
41
+ next_line = struct[struct_index+1].first
42
+ if next_line.first == :line and next_line.last[:type] == :string
43
+ line.last[:value] += next_line.last[:value]
44
+ line.last[:merge] = next_line.last[:merge]
45
+ line.last[:merge] = struct_index+1 == struct.count ? false : line.last[:merge]
46
+ struct.delete_at struct_index+1
47
+ else
48
+ line.last[:merge] = false
49
+ end
50
+ count +=1 if line.last[:merge]
51
+ end
52
+ else
53
+ recursive_merge_lines(line.last)
54
+ end
55
+ end
56
+ end
57
+ recursive_merge_lines(struct) if count > 0
58
+ end
59
+
60
+ def prepare_string_line_merge(lines)
61
+ regex = /\%\+\+$/
62
+ lines.each_with_index do |line,index|
63
+ if(line[:type] == :string)
64
+ line[:merge] = line[:value].to_s.match(regex) != nil
65
+ line[:value] = line[:value].to_s.gsub(regex,'') if line[:merge]
66
+ end
67
+ end
68
+ lines
69
+ end
70
+
30
71
  def prepare_method_structure(lines,definition)
31
72
  lines.each_with_index do |line,index|
32
73
  if line[:type] == :method
33
74
  line[:type] = :string
34
75
  bundle = line[:bundle]
35
76
  bundle = "Core" if bundle == 'core'
36
- line[:value] = AbstractMarkupLanguage::Base.const_get(bundle).method(line[:name]).call(line[:index],line[:attributes])
77
+ line[:value] = AbstractMarkupLanguage::Base.const_get(bundle).method(line[:name]).call(line[:index],line[:attributes]) + line[:value]
37
78
  end
38
79
  end
39
80
  lines
@@ -94,10 +135,10 @@ class Compile
94
135
 
95
136
  def post_prepare_line_variable(line)
96
137
  types = {
97
- :method => LineType.new(/^(\s{1,})?::((?<bundle>[\w|\-]+)\.)?(?<name>[\w|\-]+)(\{(?<attributes>.+)\})?/),
138
+ :method => LineType.new(/^(\s{1,})?::((?<bundle>[\w|\-]+)\.)?(?<name>[\w|\-]+)(\{(?<attributes>.+)\})?(?<value>.+)?/),
98
139
  :mixin => LineType.new(/^(\s{1,})?%\(((?<bundle>[\w|\-]+)\.)?(?<name>[^~][\w|\-]+)\)(\{(?<attributes>.+)\})?[^\{]?/),
99
140
  :partial => LineType.new(/^(\s{1,})?%\(\~((?<bundle>[\w|\-]+)\.)?(?<name>[\w|\-]+)\)(\{(?<attributes>.+)\}[^\{]?)?$/),
100
- :tag => LineType.new(/^(\s{1,})?(?<!%)%(?<close>\/{0,2})?(?<name>[\w|\-]+)(\#(?<id_first>[\w|\-]+))?(?<class>(\.[\w|\-]+)?{1,})?(\#(?<id_last>[\w|\-]+))?(\{(?<attributes>.+)\})?(?<text>.+)?/)
141
+ :tag => LineType.new(/^(\s{1,})?(?<!%)%(?<close>\/{0,2})?(?<name>[\w|\-]+)(?<tab_reset>\*{1,})?(\#(?<id_first>(\@\(([\w|-]+\.)?)?[\w|\-]+(\))?))?(?<class>(\.[\w|\-]+)?{1,})?(\#(?<id_last>[\w|\-]+))?(\{(?<attributes>.+)\})?(?<text>.+)?/)
101
142
  }
102
143
  if line[:type] == :string
103
144
  types.each do |type, line_type|
@@ -205,9 +246,9 @@ class Compile
205
246
  pstruct[:children]
206
247
  end
207
248
 
208
- def recursive_close(struct,index=0,definition)
249
+ def recursive_close(struct,index=0,definition,index_reset)
209
250
  next_index = struct.key?(:line) ? index+1 : index
210
- tab_index = "\t" * index
251
+ tab_index = "\t" * (index-index_reset)
211
252
  opening_tag_attributes = ""
212
253
  opening_tag = ""
213
254
  closing_tag = ""
@@ -237,10 +278,16 @@ class Compile
237
278
  end
238
279
  tag_text = struct[:line][:text]
239
280
  if struct.key?(:children)
240
- tag_text = "\r\n#{tab_index}\t#{tag_text}" if tag_text.to_s.length > 0
281
+ new_line = "\r\n"
282
+
283
+ #testing * aka tab_reset
284
+ index_reset = struct[:line][:index]+1 if struct[:line][:tab_reset].to_s.length > 0
285
+
286
+ tag_text = "#{new_line}#{tab_index}\t#{tag_text}" if tag_text.to_s.length > 0
287
+
241
288
  @@structure << "#{tab_index}#{opening_tag}#{tag_text}" if struct.key?(:line)
242
289
  struct[:children].each do |struct_children|
243
- recursive_close(struct_children,next_index,definition)
290
+ recursive_close(struct_children,next_index,definition,index_reset)
244
291
  end
245
292
  @@structure << "#{tab_index}#{closing_tag}" if struct.key?(:line)
246
293
  else
@@ -1,8 +1,6 @@
1
1
  class Core
2
-
3
- def self.loop(index=0, a={})
4
- return "loop"
5
- end
2
+
3
+ @words = %w[a ac accumsan adipiscing aenean aliquam aliquet amet ante arcu at auctor augue bibendum blandit commodo condimentum congue consectetur consequat convallis cras curabitur cursus dapibus diam dictum dictumst dignissim dis dolor donec dui duis egestas eget eleifend elementum elit enim erat eros est et etiam eu euismod facilisi facilisis fames faucibus felis fermentum feugiat fringilla fusce gravida habitasse hac hendrerit iaculis id imperdiet in integer interdum ipsum justo lacinia lacus laoreet lectus leo libero ligula lobortis lorem luctus maecenas magna magnis malesuada massa mattis mauris metus mi molestie mollis montes morbi mus nam nascetur natoque nec neque nibh nisi nisl non nulla nullam nunc odio orci ornare parturient pellentesque penatibus pharetra phasellus placerat platea porta porttitor posuere potenti praesent pretium primis proin pulvinar purus quam quis quisque rhoncus ridiculus risus rutrum sagittis sapien scelerisque sed sem semper sit sociis sodales sollicitudin suscipit suspendisse tellus tempor tempus tincidunt tortor tristique turpis ullamcorper ultrices ultricies urna ut varius vehicula vel velit venenatis vestibulum vitae vivamus viverra volutpat vulputate]
6
4
 
7
5
  def self.date(index=0, a={}, d={:format=>'%Y-%m-%d %H:%M:%S'})
8
6
  a = d.merge(a)
@@ -14,11 +12,61 @@ class Core
14
12
  return self.date(index,{:format=>'%Y'})
15
13
  end
16
14
 
17
- def self.ipsum(index=0, a={})
18
- return "%p lorem ipsum sit amet dolor"
15
+ def self.lorem(index=0, a={}, d={:number=>5,:type=>'paragraph',:capitalize=>true})
16
+ #(en-us)
17
+ a = d.merge(a)
18
+ a[:number] = a[:number].to_i
19
+ string = ""
20
+ if a[:type] == 'paragraph'
21
+ string = self._random_paragraph(a[:number])
22
+ elsif a[:type] == 'sentence'
23
+ string = self._random_sentence(a[:number])
24
+ elsif a[:type] == 'word'
25
+ string = self._random_word(a[:capitalize])
26
+ elsif a[:type] == 'name'
27
+ string = self._random_word(true) + ' ' + self._random_word(a[:capitalize])[0] + '. ' + self._random_word(true)
28
+ elsif a[:type] == 'address'
29
+ address = []
30
+ count = rand(2)+2
31
+ until address.count == count do
32
+ address << self._random_word(true)
33
+ end
34
+ city = []
35
+ count = rand(1)+1
36
+ until city.count == count do
37
+ city << self._random_word(true)
38
+ end
39
+ string = (rand(5000)+100).to_s + ' ' + address.join(' ') + ', ' + city.join(' ') + ', ' + self._random_word(a[:capitalize])[0] + self._random_word(a[:capitalize])[0] + ' ' + rand(10000...99999).to_s
40
+ elsif a[:type] == 'phone'
41
+ string = '('+ rand(100...999).to_s + ') ' + rand(100...999).to_s + '-' + rand(1000...9999).to_s
42
+ end
43
+ return string
19
44
  end
20
45
 
21
- def self.random(index=0, a={})
22
- return "random"
46
+ def self._random_word(capitalize=false)
47
+ string = @words[rand(@words.count)]
48
+ string = string.capitalize if capitalize
49
+ string
23
50
  end
51
+
52
+ def self._random_sentence(max_words=20)
53
+ count = rand(max_words)+3
54
+ count = max_words if count > max_words
55
+ string = []
56
+ until string.count == count do
57
+ string << self._random_word(string.count==0)
58
+ end
59
+ string.join(' ') + '.'
60
+ end
61
+
62
+ def self._random_paragraph(max_sentences=10)
63
+ count = rand(max_sentences)+3
64
+ count = max_sentences if count > max_sentences
65
+ string = []
66
+ until string.count == count do
67
+ string << self._random_sentence
68
+ end
69
+ string.join(' ')
70
+ end
71
+
24
72
  end
data/lib/aml/line_type.rb CHANGED
@@ -35,6 +35,9 @@ LineType = Struct.new(:regex) do
35
35
  type = %w(tag self none)
36
36
  type[match[:close].to_s.length]
37
37
  end
38
+ def tab_reset(match)
39
+ match[:tab_reset].to_s
40
+ end
38
41
  def stringHashToHash(string)
39
42
  hash = {}
40
43
  regex = /:(?<name>\w+)\s?=>\s?(?<hash>{(.+?)?}|(?<quote>'|")(?<value>.+?)??\k<quote>)/
data/lib/aml/parse.rb CHANGED
@@ -13,16 +13,16 @@ class Parse
13
13
  @regex = {
14
14
  :attribute => /@\(\:(?<name>[\w|\-]+)\)/,
15
15
  :comment => /%!--[^%]*--%$/,
16
- :variable => /\@\(((?<bundle>[\w|\-]+)\.)?(?<name>[\w|\-]+)\)/,
16
+ :variable => /\@\(((?<bundle>[\w|\-]+)\.)?(?<name>[\w|\-]+)\)/
17
17
  }
18
18
  @types = {
19
- :method => LineType.new(/^(\s{1,})?::((?<bundle>[\w|\-]+)\.)?(?<name>[\w|\-]+)(\{(?<attributes>.+)\})?/),
19
+ :method => LineType.new(/^(\s{1,})?::((?<bundle>[\w|\-]+)\.)?(?<name>[\w|\-]+)(\{(?<attributes>.+)\})?(?<value>.+)?/),
20
20
  :variable_def => LineType.new(/^(\s{1,})?\@((?<bundle>[\w|\-]+)\.)?(?<name>[\w|\-]+)\s?(\=)\s?(?<value>.+)?$/),
21
21
  :mixin => LineType.new(/^(\s{1,})?%\(((?<bundle>[\w|\-]+)\.)?(?<name>[^~][\w|\-]+)\)(\{(?<attributes>.+)\})?[^\{]?/),
22
22
  :mixin_def => LineType.new(/^%%(?<name>[\w|\-]+)(\((?<attributes>.+?)\))?{/),
23
23
  :mixin_end => LineType.new(/^\}$/),
24
24
  :partial => LineType.new(/^(\s{1,})?%\(\~((?<bundle>[\w|\-]+)\.)?(?<name>[\w|\-]+)\)(\{(?<attributes>.+)\}[^\{]?)?$/),
25
- :tag => LineType.new(/^(\s{1,})?(?<!%)%(?<close>\/{0,2})?(?<name>[\w|\-]+)(\#(?<id_first>(\@\(([\w|-]+\.)?)?[\w|\-]+(\))?))?(?<class>(\.[\w|\-]+)?{1,})?(\#(?<id_last>[\w|\-]+))?(\{(?<attributes>.+)\})?(?<text>.+)?/),
25
+ :tag => LineType.new(/^(\s{1,})?(?<!%)%(?<close>\/{0,2})?(?<name>[\w|\-]+)(?<tab_reset>\*{1,})?(\#(?<id_first>(\@\(([\w|-]+\.)?)?[\w|\-]+(\))?))?(?<class>(\.[\w|\-]+)?{1,})?(\#(?<id_last>[\w|\-]+))?(\{(?<attributes>.+)\})?(?<text>.+)?/),
26
26
  :empty => LineType.new(/^$/),
27
27
  :eval => LineType.new(/^(\s{1,})?==(\s{1,})(?<value>.+)?/),
28
28
  :string => LineType.new(/(\s{1,})?(?<value>.+)?/)
@@ -1,4 +1,4 @@
1
- #require "awesome_print"
1
+ require "awesome_print"
2
2
  require 'aml/error'
3
3
  require 'aml/argument'
4
4
  require 'aml/line_type'
data/lib/aml.rb CHANGED
@@ -3,13 +3,11 @@ module AbstractMarkupLanguage
3
3
  @basePath
4
4
  @watchFile
5
5
  @makeFile
6
-
7
6
  class Base
8
7
  def self.initialize(arguments, instance)
9
8
  error = Error.new()
10
9
  argument = Argument.new(arguments,error)
11
10
  argument.required('watch','The required --watch argument has not been defined.')
12
-
13
11
  if(argument.has_requirements? == false)
14
12
  argument.clear_required
15
13
  argument.required('build','The required --build argument has not been defined.')
@@ -21,7 +19,6 @@ module AbstractMarkupLanguage
21
19
  else
22
20
  argument.create('build','false')
23
21
  end
24
-
25
22
  if argument.has_requirements? and File.exist?(argument.read('watch'))
26
23
  basePath = File.dirname(argument.read('watch'))
27
24
  @basePath = basePath
@@ -35,10 +32,10 @@ module AbstractMarkupLanguage
35
32
  argument.create_if_empty('basePath',basePath)
36
33
  argument.create_if_empty('fileExtension','html')
37
34
  argument.create_if_empty('fileOutput',"#{File.basename(argument.read('watch'), ".*")}.#{argument.read('fileExtension')}")
38
- argument.create_if_empty('aml-watch-instance', "#{instance}")
39
-
40
35
  argument.create_if_empty('selfClosing',"area,base,basefont,bgsound,br,col,frame,hr,img,isindex,input,keygen,link,meta,param,source,track,wbr")
41
36
 
37
+ argument.create_if_empty('aml-watch-instance', "#{instance}")
38
+
42
39
  parse = Parse.new(argument.read('basePath'), argument.read('watch'))
43
40
  files = []
44
41
 
@@ -128,7 +125,11 @@ module AbstractMarkupLanguage
128
125
  end
129
126
  end
130
127
  else
131
- puts argument.read('watch').to_s.length == 0 ? "Please define the --watch or --build argument." : "File not found."
128
+ if argument.defined('version')
129
+ puts Gem.loaded_specs['aml'].version.to_s
130
+ else
131
+ puts argument.read('watch').to_s.length == 0 ? "Please define the --watch or --build argument." : "File not found."
132
+ end
132
133
  end
133
134
  end
134
135
 
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.1.0
4
+ version: 0.1.1
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-03-07 00:00:00.000000000 Z
11
+ date: 2014-04-15 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.
@@ -19,21 +19,21 @@ executables:
19
19
  extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
22
- - bin/aml-bundle
23
22
  - bin/aml
24
- - lib/aml.rb
25
- - lib/aml-bundle.rb
26
- - lib/aml/definition.rb
27
- - lib/aml/error.rb
23
+ - bin/aml-bundle
24
+ - lib/aml/argument.rb
25
+ - lib/aml/compile.rb
28
26
  - lib/aml/core/method.rb
29
27
  - lib/aml/core/mixin.aml
30
- - lib/aml/parse.rb
31
- - lib/aml/argument.rb
28
+ - lib/aml/definition.rb
29
+ - lib/aml/error.rb
32
30
  - lib/aml/line_type.rb
33
31
  - lib/aml/make.rb
34
- - lib/aml/watch.rb
35
- - lib/aml/compile.rb
32
+ - lib/aml/parse.rb
36
33
  - lib/aml/requirement.rb
34
+ - lib/aml/watch.rb
35
+ - lib/aml-bundle.rb
36
+ - lib/aml.rb
37
37
  homepage: https://abstractmarkup.com
38
38
  licenses:
39
39
  - MIT
@@ -54,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
54
  version: '0'
55
55
  requirements: []
56
56
  rubyforge_project:
57
- rubygems_version: 2.0.7
57
+ rubygems_version: 2.0.3
58
58
  signing_key:
59
59
  specification_version: 4
60
60
  summary: Abstract Markup Language