aml 0.1.2 → 0.1.3

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: 4554e8086f2ded34322b99b7d29197f0d106d547
4
- data.tar.gz: 6a46a20ef78e5888ffd391c960744d5f3382acce
3
+ metadata.gz: 96b4862d968beca0ef77a6a40a76ba5046a4374f
4
+ data.tar.gz: fc95c860a87e77d54407072679d06dedf1855fb0
5
5
  SHA512:
6
- metadata.gz: 984d81c03eecfc52d2bc73376837809fa7ddeb0abbc5dd0dd978df88160693b0cd367332b0ca3d096c367849fd75dcf1d3a69ef03defdf96e1426cb240ec3320
7
- data.tar.gz: 30632d24ea907aa6884944f770c5c32b8a1308c9ea8d1ef1967a590a8b4fe3f3c41d938f8d6ad3e6474b2787340c94fdd92ba9b39da73d559283bf07108f3ce3
6
+ metadata.gz: a6308cbf0bf762ebe2ba84cc3f17bf688cbf832b4d2398ab34d2bd2988e0acaace746b95727ddca18aa125b9b6a3b1b85f67dd622f4909a2a0ce4663bb2068d3
7
+ data.tar.gz: 6f19b512a26009fbe4c44d3db5155d49ccf42abbe7e45d4a23bd8bb9138757636a2da9b5aae41ee89a790b36cce421291f0e9ee7fc15c16a94b2a36ff5f561ea
data/lib/aml.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # Entry Point for Abstract Markup Language
2
+ require "awesome_print"
2
3
  class AbstractMarkupLanguage
3
4
  require "aml/Build"
4
5
  def initialize(argument)
data/lib/aml/Build.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  class Build
2
2
  require "aml/Argument"
3
3
  require "aml/Compile"
4
-
4
+
5
5
  @@structure = []
6
6
  @@selfClosing = []
7
7
 
@@ -126,24 +126,22 @@ class Build
126
126
  end
127
127
 
128
128
  def tag_line_attributes(line,base="")
129
- if line[:type] == :tag
130
- attributes = hash_to_attribute_build(line[:attribute],"",line)
131
- attributes = " #{attributes}" if(attributes.length > 0)
132
- end
129
+ attributes = hash_to_attribute_build(line[:attribute],"").strip
130
+ attributes = ' ' + attributes if(attributes.length > 0)
133
131
  end
134
132
 
135
- def hash_to_attribute_build(hash,base="",line)
133
+ def hash_to_attribute_build(hash,base="")
136
134
  hash = hash.sort_by{|key, value| key}
137
135
  string = ""
138
136
  hash.each do |key, value|
139
137
  if(value.is_a?(Hash))
140
138
  value.sort_by{|key, value| key}
141
- string << "#{hash_to_attribute_build(value,"#{base}#{key}-",line)} "
139
+ string << hash_to_attribute_build(value,"#{base}#{key}-")
142
140
  else
143
141
  string << "#{base}#{key}=\"#{value}\" " if value.to_s.length > 0
144
142
  end
145
143
  end
146
- string.strip
144
+ string
147
145
  end
148
146
 
149
147
  def prepare_structure(struct,index=0,pstruct={:line=>false,:children=>[]})
data/lib/aml/Cluster.rb CHANGED
@@ -68,6 +68,19 @@ class Cluster
68
68
  definition.self[:hash] = process_conditional_block(definition, _get_conditionals(definition.self[:hash]), definition.self[:hash], 'loop')
69
69
  definition.self[:hash] = process_conditional_block(definition, _get_conditionals(definition.self[:hash]), definition.self[:hash], 'if')
70
70
  end
71
+
72
+ def recursive_attribute_replace(attributes,find,replace)
73
+ attributes.each do |attribute, value|
74
+ if value.is_a? Hash
75
+ value = recursive_attribute_replace(value,find,replace)
76
+ else
77
+ value = value.to_s.gsub(find,replace)
78
+ end
79
+ attributes[attribute] = value
80
+ end
81
+ attributes
82
+ end
83
+
71
84
  # Process Conditional Block
72
85
  def process_conditional_block(definition, conditionals, lines, type)
73
86
  conditional = conditionals.select{|k|k[:name].downcase == type}.sort_by{|k|k[:index]}.reverse
@@ -83,28 +96,33 @@ class Cluster
83
96
  loop_line = Marshal.load(Marshal.dump(lines.select{|k|k[:c_index] > conditional[:c_index] and k[:c_index] < conditional[:end][:c_index]}))
84
97
  loop_line.each do |line|
85
98
  line[:index] = line[:index]-1
86
- line[:text] = line[:text].gsub(/@@/,value) if line[:text] != nil
87
- line[:value] = line[:value].gsub(/@@/,value) if line[:value] != nil
99
+ [:text,:value].each do |name|
100
+ line[name] = line[name].gsub(/@\(\:index\)/, value) if line[name] != nil
101
+ line[name] = line[name].gsub(/@\(\:zero\-index\)/, ((value.to_i)-1).to_s) if line[name] != nil
102
+ end
88
103
  if line[:attribute] != nil
89
- line[:attribute].each do |attribute|
90
- line[:attribute][attribute[0]] = attribute[1].gsub(/@@/,value) if attribute[1] != nil
91
- end
104
+ line[:attribute] = recursive_attribute_replace(line[:attribute],/@\(\:index\)/, value)
105
+ line[:attribute] = recursive_attribute_replace(line[:attribute],/@\(\:zero\-index\)/, ((value.to_i)-1).to_s)
92
106
  end
93
107
  conditional_lines << line
94
108
  end
95
109
  end
96
110
  else
97
- conditional[:value].split(',').each do |value|
111
+ conditional[:value].split(',').each_with_index do |value, index|
98
112
  value = value.strip
113
+ index = index
99
114
  loop_line = Marshal.load(Marshal.dump(lines.select{|k|k[:c_index] > conditional[:c_index] and k[:c_index] < conditional[:end][:c_index]}))
100
115
  loop_line.each do |line|
101
116
  line[:index] = line[:index]-1
102
- line[:text] = line[:text].gsub(/@@/,value) if line[:text] != nil
103
- line[:value] = line[:value].gsub(/@@/,value) if line[:value] != nil
117
+ [:text,:value].each do |name|
118
+ line[name] = line[name].gsub(/@\(\:value\-index\)/, value) if line[name] != nil
119
+ line[name] = line[name].gsub(/@\(\:index\)/, (index+1).to_s) if line[name] != nil
120
+ line[name] = line[name].gsub(/@\(\:zero\-index\)/, index.to_s) if line[name] != nil
121
+ end
104
122
  if line[:attribute] != nil
105
- line[:attribute].each do |attribute|
106
- line[:attribute][attribute[0]] = attribute[1].gsub(/@@/,value) if attribute[1] != nil
107
- end
123
+ line[:attribute] = recursive_attribute_replace(line[:attribute],/@\(\:value\-index\)/, value)
124
+ line[:attribute] = recursive_attribute_replace(line[:attribute],/@\(\:index\)/, (index+1).to_s)
125
+ line[:attribute] = recursive_attribute_replace(line[:attribute],/@\(\:zero\-index\)/, index.to_s)
108
126
  end
109
127
  conditional_lines << line
110
128
  end
data/lib/aml/Compile.rb CHANGED
@@ -66,6 +66,19 @@ class Compile
66
66
  definition.self[:hash][index] = process_variable_line(line, definition)
67
67
  definition.self[:hash][index] = process_method_line(line, definition) if methods
68
68
  end
69
+
70
+ def recursive_attribute_replace_variable(attributes, line, definition)
71
+ attributes.each do |attribute, value|
72
+ if value.is_a? Hash
73
+ value = recursive_attribute_replace_variable(value, line, definition)
74
+ else
75
+ value = process_variable_find(value.to_s, line, definition)
76
+ end
77
+ attributes[attribute] = value
78
+ end
79
+ attributes
80
+ end
81
+
69
82
  def process_variable_line(line, definition)
70
83
  if line[:type] == :string
71
84
  line[:value] = process_variable_find(line[:value], line, definition)
@@ -74,14 +87,25 @@ class Compile
74
87
  else
75
88
  line[:text] = process_variable_find(line[:text], line, definition)
76
89
  line[:value] = process_variable_find(line[:value], line, definition)
77
- if line.key? :attribute != nil
78
- line[:attribute].each do|k,v|
79
- line[:attribute][k] = process_variable_find(v, line, definition)
80
- end
90
+ if line.key? :attribute and line[:attribute].count > 0
91
+ line[:attribute] = recursive_attribute_replace_variable(line[:attribute], line, definition)
81
92
  end
82
93
  end
83
94
  line
84
95
  end
96
+
97
+ def recursive_attribute_replace_method(attributes, line)
98
+ attributes.each do |attribute, value|
99
+ if value.is_a? Hash
100
+ value = recursive_attribute_replace_method(value, line)
101
+ else
102
+ value = process_method_find(value.to_s, line)
103
+ end
104
+ attributes[attribute] = value
105
+ end
106
+ attributes
107
+ end
108
+
85
109
  def process_method_line(line, definition)
86
110
  if line[:type] == :string
87
111
  line[:value] = process_method_find(line[:value], line)
@@ -89,10 +113,8 @@ class Compile
89
113
  line = parse.line("#{"\t" * line[:index]}#{line[:value]}",line[:number])
90
114
  else
91
115
  line[:text] = process_method_find(line[:text], line)
92
- if line.key? :attribute != nil
93
- line[:attribute].each do|k,v|
94
- line[:attribute][k] = process_method_find(v, line)
95
- end
116
+ if line.key? :attribute and line[:attribute].count > 0
117
+ line[:attribute] = recursive_attribute_replace_method(line[:attribute],line)
96
118
  end
97
119
  end
98
120
  line
@@ -167,19 +189,31 @@ class Compile
167
189
  return false
168
190
  end
169
191
  end
192
+
193
+ def recursive_attribute_replace_attribute(attributes, mixin)
194
+ attributes.each do |attribute, value|
195
+ if value.is_a? Hash
196
+ value = recursive_attribute_replace_attribute(value, mixin)
197
+ else
198
+ value = process_attribute_find(value.to_s, mixin)
199
+ end
200
+ attributes[attribute] = value
201
+ end
202
+ attributes
203
+ end
204
+
170
205
  def process_attribute(line, mixin)
171
206
  if line[:type] == :string
172
207
  line[:value] = process_attribute_find(line[:value], mixin[:attribute])
173
208
  else
174
209
  line[:text] = process_attribute_find(line[:text], mixin[:attribute])
175
210
  if line[:attribute] != nil
176
- line[:attribute].each do|k,v|
177
- line[:attribute][k] = process_attribute_find(v, mixin[:attribute])
178
- end
211
+ line[:attribute] = recursive_attribute_replace_attribute(line[:attribute],mixin[:attribute])
179
212
  end
180
213
  end
181
214
  line
182
215
  end
216
+
183
217
  def process_attribute_find(string, attribute)
184
218
  regex = @inline.select{|k|k[:type] == :attribute}[0][:regex]
185
219
  string = string.to_s.gsub(regex).each do
@@ -206,7 +240,7 @@ class Compile
206
240
  partial = Definition.new(File.join(@argument.get('path'),path,line[:name]+'.aml'), line[:type].to_s, line[:bundle])
207
241
  partial.self[:hash].each_with_index do |line, index|
208
242
  line[:number] = partial_number
209
- line = process_attribute(line, {:attribute=>patrial_attribute})
243
+ line = process_attribute(line, {:attribute=>patrial_attribute}) if patrial_attribute.count > 0
210
244
  line = process_variable_line(line, definition)
211
245
  end
212
246
  partial.self[:hash].each do|line|
@@ -13,7 +13,7 @@ class Definition
13
13
  begin
14
14
  parse = Parse.new(bundle)
15
15
  # Remove Comment Line(s)
16
- File.open(file).read.gsub(/%!--[^%]*--%$/,'').each_line do |line|
16
+ File.open(file).read.gsub(/%!--[^%]*--%$|[^%]\/\/.*$/,'').each_line do |line|
17
17
  number+=1
18
18
  # Remove Empty Lines
19
19
  add_line(parse.line(line,number))
data/lib/aml/Line.rb CHANGED
@@ -39,11 +39,12 @@ class Line
39
39
  line[:bundle] = 'core' if line[:bundle] == false
40
40
  end
41
41
  # class
42
- if line.key? :class
42
+ if line.key? :class and line[:class].length > 0
43
43
  line[:class] = '.' + line[:class]
44
44
  line[:attribute][:class] = line[:class].split('.').join(' ').strip!
45
45
  line.delete(:class)
46
46
  end
47
+
47
48
  # close
48
49
  line[:close] = %w(tag self none)[line[:close].to_s.length].to_sym if line.key? :close
49
50
  # id
@@ -67,7 +68,7 @@ class Line
67
68
  if string != nil
68
69
  string.scan(regex){|match|
69
70
  thisHash = Hash[names.zip(match)]
70
- if thisHash["hash"].to_s[0] == "{"
71
+ if thisHash["hash"].to_s.strip[0] == '{'
71
72
  hash[thisHash["name"].to_sym] = recursive_string_to_hash(thisHash["hash"])
72
73
  else
73
74
  hash[thisHash["name"].to_sym] = thisHash["value"].to_s.strip
data/lib/aml/Parse.rb CHANGED
@@ -8,7 +8,7 @@ class Parse
8
8
  @line << Line.new(bundle, :mixin_end, /^\}$/)
9
9
  @line << Line.new(bundle, :partial, /^(\s{1,})?%\(\~((?<bundle>[\w|\-]+)\.)?(?<name>[\w|\-]+)\)(\{(?<attribute>.+)\}[^\{]?)?$/)
10
10
  @line << Line.new(bundle, :tag, /^(\s{1,})?(?<!%)%(?<close>\/{0,2})?(?<name>[\w|\-]+)(\#(?<id_first>[\w|\-]+))?(\.(?<class>[\w|\-|\.]+))?(\#(?<id_last>[\w|\-]+))?(?<reset>\*{1,})?(\{(?<attribute>.+)\})?(?<text>.+)?$/)
11
- @line << Line.new(bundle, :tag_shorthand, /^(\s{1,})?(?=[#|\.|\/])(?<close>\/{0,2})?(\#(?<id_first>[\w|\-]+))?(\.(?<class>[\w|\-|\.]+))?(\#(?<id_last>[\w|\-]+))?(?<reset>\*{1,})?(\{(?<attribute>.+)\})?(?<text>.+)?$/)
11
+ @line << Line.new(bundle, :tag_shorthand, /^(\s{1,})?(?=[#|\.|\/])(\#(?<id_first>[\w|\-]+))?(\.(?<class>[\w|\-|\.]+))?(\#(?<id_last>[\w|\-]+))?(?<reset>\*{1,})?(?<close>\/{0,2})?(\{(?<attribute>.+)\})?(?<text>.+)?$/)
12
12
  @line << Line.new(bundle, :conditional, /^(\s{1,})?-\s?(?<name>if|loop|end)(\s(?<value>.+))?$/)
13
13
  @line << Line.new(bundle, :empty, /^$/)
14
14
  @line << Line.new(bundle, :eval, /^(\s{1,})?==(\s{1,})(?<value>.+)?/)
@@ -1,6 +1,11 @@
1
1
  class Core
2
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]
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 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 werumensium xiphias]
4
+
5
+ def self.rand(index=0, a={}, d={:min=>'1', :max=>'10'})
6
+ offset = 1 if a[:min] == 0
7
+ return rand(a[:max]+offset)+a[:min]
8
+ end
4
9
 
5
10
  def self.date(index=0, a={}, d={:format=>'%Y-%m-%d %H:%M:%S'})
6
11
  a = d.merge(a)
@@ -22,38 +27,28 @@ class Core
22
27
  return self.date(index,{:format=>'%Y'})
23
28
  end
24
29
 
25
- def self.lorem(index=0, a={}, d={:number=>5,:type=>'paragraph',:capitalize=>true})
26
- #(en-us)
30
+ def self.lorem(index=0, a={}, d={:paragraphs=>6, :words=>8, :type=>'paragraph',:capitalize=>true})
31
+ #Generate random copy based on en-us formats.
27
32
  a = d.merge(a)
28
- a[:number] = a[:number].to_i
33
+ a[:paragraphs] = a[:paragraphs].to_i
34
+ a[:words] = a[:words].to_i
29
35
  string = ""
30
- if a[:type] == 'paragraph'
31
- string = self._random_paragraph(a[:number])
36
+ if a[:type] == 'word'
37
+ string = self._random_word(a[:capitalize])
32
38
  elsif a[:type] == 'sentence'
33
- string = self._random_sentence(a[:number])
39
+ string = self._random_sentence(a[:words])
40
+ elsif a[:type] == 'paragraph'
41
+ string = self._random_paragraph(a[:paragraphs], a[:words])
34
42
  elsif a[:type] == 'title'
35
- for i in 1..rand(a[:number]-1)+1
36
- string += self._random_word(a[:capitalize]) + " "
37
- end
38
- string.strip!
39
- elsif a[:type] == 'word'
40
- string = self._random_word(a[:capitalize])
43
+ string = self._random_title(a[:words])
41
44
  elsif a[:type] == 'name'
42
- string = self._random_word(true) + ' ' + self._random_word(a[:capitalize])[0] + '. ' + self._random_word(true)
45
+ string = self._random_name
43
46
  elsif a[:type] == 'address'
44
- address = []
45
- count = rand(2)+2
46
- until address.count == count do
47
- address << self._random_word(true)
48
- end
49
- city = []
50
- count = rand(1)+1
51
- until city.count == count do
52
- city << self._random_word(true)
53
- end
54
- 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
47
+ string = self._random_address
55
48
  elsif a[:type] == 'phone'
56
- string = '('+ rand(100...999).to_s + ') ' + rand(100...999).to_s + '-' + rand(1000...9999).to_s
49
+ string = self._random_phone
50
+ elsif a[:type] == 'email'
51
+ string = self._random_email
57
52
  end
58
53
  return string
59
54
  end
@@ -64,24 +59,63 @@ class Core
64
59
  string
65
60
  end
66
61
 
67
- def self._random_sentence(max_words=20)
68
- count = rand(max_words)+3
69
- count = max_words if count > max_words
62
+ def self._random_sentence(number)
63
+ words = rand(number)
64
+ words = number if words == 0
65
+ words = words <= (number/2) ? number/2+rand(0..1) : words
70
66
  string = []
71
- until string.count == count do
67
+ until string.count == words do
72
68
  string << self._random_word(string.count==0)
73
69
  end
74
70
  string.join(' ') + '.'
75
71
  end
76
72
 
77
- def self._random_paragraph(max_sentences=10)
78
- count = rand(max_sentences)+3
79
- count = max_sentences if count > max_sentences
73
+ def self._random_paragraph(number, words)
74
+ paragraphs = rand(number)
75
+ paragraphs = number if paragraphs == 0
76
+ paragraphs = paragraphs <= (number/2) ? number/2+rand(0..1) : paragraphs
77
+ string = []
78
+ until string.count == paragraphs do
79
+ string << self._random_sentence(words)
80
+ end
81
+ string.join(' ')
82
+ end
83
+
84
+ def self._random_title(number)
85
+ words = rand(number)
86
+ words = number if words == 0
87
+ words = words <= (number/2) ? number/2+rand(0..1) : words
80
88
  string = []
81
- until string.count == count do
82
- string << self._random_sentence
89
+ until string.count == words do
90
+ string << self._random_word(true)
83
91
  end
84
92
  string.join(' ')
85
93
  end
86
94
 
95
+ def self._random_name
96
+ self._random_word(true) + ' ' + self._random_word(true)[0] + '. ' + self._random_word(true)
97
+ end
98
+
99
+ def self._random_phone
100
+ '('+ rand(100...999).to_s + ') ' + rand(100...999).to_s + '-' + rand(1000...9999).to_s
101
+ end
102
+
103
+ def self._random_address
104
+ address = []
105
+ count = rand(2..4)
106
+ until address.count == count do
107
+ address << self._random_word(true)
108
+ end
109
+ city = []
110
+ count = rand(1..2)
111
+ until city.count == count do
112
+ city << self._random_word(true)
113
+ end
114
+ rand(100..5000).to_s + ' ' + address.join(' ') + ', ' + city.join(' ') + ', ' + self._random_word(true)[0].upcase + self._random_word(true)[0].upcase + ' ' + rand(10000...99999).to_s
115
+ end
116
+
117
+ def self._random_email
118
+ self._random_word + '@' + self._random_word + '.' + self._random_word[0..3]
119
+ end
120
+
87
121
  end
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.2
4
+ version: 0.1.3
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-06-08 00:00:00.000000000 Z
11
+ date: 2014-06-21 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.