aml 0.0.0 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/aml +3 -0
- data/lib/aml.rb +67 -5
- data/lib/aml/argument.rb +65 -0
- data/lib/aml/log.rb +25 -0
- data/lib/aml/parse.rb +504 -0
- data/lib/aml/watch.rb +37 -0
- metadata +15 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62586a90cf259bfb9db8e6144d6b617eac6f62f7
|
4
|
+
data.tar.gz: 83cd34500258139d04cfd6d91a484ff53aa62fcc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6a5e3848de3b9e91245fcfeb9d74546f38816e285d794601d59461f9dda536ae8ff427c6b0bea8bfa4001657ba8982890808f50786d5a2cfa34942b699dd544
|
7
|
+
data.tar.gz: 4ec08e0e48c78777aeda9ffe8563d448e9ee42988e41be19149f87fa5a917a107c399108a7eea97c89665de1562b1e4513210eceafd06b20f9264465496b3516
|
data/bin/aml
ADDED
data/lib/aml.rb
CHANGED
@@ -1,5 +1,67 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module AbstractMarkupLanguage
|
2
|
+
class Base
|
3
|
+
@@args = {}
|
4
|
+
@@args_original = ''
|
5
|
+
@@watch = false
|
6
|
+
@@p = false
|
7
|
+
|
8
|
+
def self.initialize(arguments)
|
9
|
+
log = Log.new('The following errors have occured:')
|
10
|
+
argument = Argument.new(arguments)
|
11
|
+
@@args_original = arguments
|
12
|
+
argument.required('watch','The required --watch attribute has not been defined.')
|
13
|
+
if(argument.has_requirements?)
|
14
|
+
if File.exist?(argument.read('watch'))
|
15
|
+
basePath = File.dirname(argument.read('watch'))
|
16
|
+
argument.create('watch',"#{File.basename(argument.read('watch'))}")
|
17
|
+
argument.create_if_empty('basePath',basePath)
|
18
|
+
argument.create_if_empty('fileExtension','html')
|
19
|
+
argument.create_if_empty('fileOutput',"#{File.basename(argument.read('watch'), ".*")}.#{argument.read('fileExtension')}")
|
20
|
+
argument.create_if_empty('selfClosing',"area,base,basefont,bgsound,br,col,frame,hr,img,isindex,input,keygen,link,meta,param,source,track,wbr")
|
21
|
+
argument.create_if_empty('sortAttribute','true')
|
22
|
+
argument.create_if_empty('singleQuote','false')
|
23
|
+
@@args = argument.hash
|
24
|
+
@@p = Parse.new(@@args)
|
25
|
+
process
|
26
|
+
else
|
27
|
+
log.add('The file to watch does not exist.')
|
28
|
+
argument.missing_required.each do |message|
|
29
|
+
log.add(message)
|
30
|
+
end
|
31
|
+
log.display
|
32
|
+
end
|
33
|
+
else
|
34
|
+
argument.missing_required.each do |message|
|
35
|
+
log.add(message)
|
36
|
+
end
|
37
|
+
log.display
|
38
|
+
end
|
39
|
+
end
|
40
|
+
def self.process
|
41
|
+
file = []
|
42
|
+
@@watch = Watch.new()
|
43
|
+
parse = Parse.new(@@args)
|
44
|
+
file << File.join(@@args[:basePath],@@args[:watch])
|
45
|
+
parse.process_partials(File.join(@@args[:basePath],@@args[:watch])).each do |partial|
|
46
|
+
partial_file = File.join(@@args[:basePath],"~","#{partial[:name]}.aml")
|
47
|
+
file << partial_file if File.exist?(partial_file)
|
48
|
+
end
|
49
|
+
@@watch.process(file)
|
50
|
+
message = "Watching #{file[0]}"
|
51
|
+
message += " and #{file.count-1} partial" if file.count >= 2
|
52
|
+
message += "s" if file.count >= 3
|
53
|
+
message += "...\r\n"
|
54
|
+
puts message
|
55
|
+
@@watch.watch
|
56
|
+
end
|
57
|
+
|
58
|
+
def file_update(name)
|
59
|
+
puts "updating #{@@args[:watch]} - #{name} has been updated..."
|
60
|
+
@@p.init(File.join(@@args[:basePath],@@args[:watch]),@@args)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
require 'aml/argument'
|
65
|
+
require 'aml/log'
|
66
|
+
require 'aml/watch'
|
67
|
+
require 'aml/parse'
|
data/lib/aml/argument.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
class Argument
|
2
|
+
|
3
|
+
@@argumental = {}
|
4
|
+
@@required = {}
|
5
|
+
|
6
|
+
def initialize(arguments)
|
7
|
+
arguments = arguments.split('--')
|
8
|
+
arguments.each do |argument|
|
9
|
+
string = argument.split(' ')
|
10
|
+
create(string[0],string[1..string.count].join(' ')) if argument.strip.length > 0
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def hash
|
15
|
+
return @@argumental
|
16
|
+
end
|
17
|
+
|
18
|
+
def required(name,message)
|
19
|
+
@@required[name.to_sym] = {:message=>message.strip, :defined=>false}
|
20
|
+
end
|
21
|
+
|
22
|
+
def has_requirements?
|
23
|
+
@@required.each do|key,hash|
|
24
|
+
hash[:defined] = true if(@@argumental.select{|k,v| k.to_s == key.to_s}.count == 1)
|
25
|
+
end
|
26
|
+
@@required.select{|k,v| v[:defined] == false}.count == 0 ? true : false
|
27
|
+
end
|
28
|
+
|
29
|
+
def missing_required
|
30
|
+
message = []
|
31
|
+
@@required.select{|k,v| v[:defined] == false}.each do |attribute,hash|
|
32
|
+
message << hash[:message]
|
33
|
+
end
|
34
|
+
message
|
35
|
+
end
|
36
|
+
|
37
|
+
def create(name,value)
|
38
|
+
@@argumental[name.to_sym] = value.strip if(value.length > 0)
|
39
|
+
end
|
40
|
+
|
41
|
+
def create_if_empty(name,value)
|
42
|
+
create(name,value) if @@argumental.select{|k,v| k.to_s == name}.count == 0
|
43
|
+
end
|
44
|
+
|
45
|
+
def read(name)
|
46
|
+
@@argumental[name.to_sym]
|
47
|
+
end
|
48
|
+
|
49
|
+
def update(name,value)
|
50
|
+
create(name,value)
|
51
|
+
end
|
52
|
+
|
53
|
+
def update_append(name,value)
|
54
|
+
create(name,"#{value}#{read(name)}")
|
55
|
+
end
|
56
|
+
|
57
|
+
def update_prepend(name,value)
|
58
|
+
create(name,"#{read(name)}#{value}")
|
59
|
+
end
|
60
|
+
|
61
|
+
def delete(name)
|
62
|
+
@@argumental = @@argumental.select{|k,v| k.to_s != name}
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
data/lib/aml/log.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
class Log
|
2
|
+
|
3
|
+
@@introduction = false
|
4
|
+
@@message = []
|
5
|
+
|
6
|
+
def initialize(introduction=false)
|
7
|
+
@@introduction = introduction
|
8
|
+
end
|
9
|
+
|
10
|
+
def introduction(message)
|
11
|
+
@@introduction = message
|
12
|
+
end
|
13
|
+
|
14
|
+
def add(message)
|
15
|
+
@@message << message
|
16
|
+
end
|
17
|
+
|
18
|
+
def display(introduction=true)
|
19
|
+
puts @@introduction if(@@introduction != false) and introduction
|
20
|
+
@@message.each do |message|
|
21
|
+
puts "- #{message}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/lib/aml/parse.rb
ADDED
@@ -0,0 +1,504 @@
|
|
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']
|
45
|
+
}
|
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']
|
81
|
+
}
|
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
|
125
|
+
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])
|
248
|
+
end
|
249
|
+
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
|
+
end
|
312
|
+
else
|
313
|
+
close << open_tag[0] if(open_tag.count == 1)
|
314
|
+
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
|
484
|
+
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
|
500
|
+
end
|
501
|
+
partial
|
502
|
+
end
|
503
|
+
|
504
|
+
end
|
data/lib/aml/watch.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
class Watch
|
2
|
+
def initialize
|
3
|
+
end
|
4
|
+
|
5
|
+
def process(filenames)
|
6
|
+
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
|
+
|
14
|
+
def watch(sleep=1)
|
15
|
+
loop do
|
16
|
+
begin
|
17
|
+
Kernel.sleep sleep until file_updated?
|
18
|
+
rescue SystemExit,Interrupt
|
19
|
+
puts "\r\n"
|
20
|
+
Kernel.exit
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def file_updated?
|
26
|
+
@filenames.each do |filename|
|
27
|
+
mtime = File.stat(filename).mtime
|
28
|
+
updated = @last_mtimes[filename] < mtime
|
29
|
+
@last_mtimes[filename] = mtime
|
30
|
+
if(updated)
|
31
|
+
AbstractMarkupLanguage::Base.new.file_update(filename)
|
32
|
+
return true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
return false
|
36
|
+
end
|
37
|
+
end
|
metadata
CHANGED
@@ -1,24 +1,30 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Esquivias
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
14
|
-
|
15
|
-
email: daniel
|
16
|
-
executables:
|
13
|
+
description: Abstract Markup Language is a robust and feature rich markup language
|
14
|
+
designed to avoid repetition and promote clear, well-indented markup.
|
15
|
+
email: daniel@aml-info.org
|
16
|
+
executables:
|
17
|
+
- aml
|
17
18
|
extensions: []
|
18
19
|
extra_rdoc_files: []
|
19
20
|
files:
|
20
21
|
- lib/aml.rb
|
21
|
-
|
22
|
+
- lib/aml/argument.rb
|
23
|
+
- lib/aml/log.rb
|
24
|
+
- lib/aml/watch.rb
|
25
|
+
- lib/aml/parse.rb
|
26
|
+
- bin/aml
|
27
|
+
homepage: https://aml-info.org/
|
22
28
|
licenses:
|
23
29
|
- MIT
|
24
30
|
metadata: {}
|
@@ -30,7 +36,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
30
36
|
requirements:
|
31
37
|
- - '>='
|
32
38
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
39
|
+
version: 2.0.0
|
34
40
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
41
|
requirements:
|
36
42
|
- - '>='
|
@@ -38,7 +44,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
38
44
|
version: '0'
|
39
45
|
requirements: []
|
40
46
|
rubyforge_project:
|
41
|
-
rubygems_version: 2.0.
|
47
|
+
rubygems_version: 2.0.0
|
42
48
|
signing_key:
|
43
49
|
specification_version: 4
|
44
50
|
summary: Abstract Markup Language
|