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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62586a90cf259bfb9db8e6144d6b617eac6f62f7
4
- data.tar.gz: 83cd34500258139d04cfd6d91a484ff53aa62fcc
3
+ metadata.gz: b0cdc40b541bc19e5680c9216bc712639b954f98
4
+ data.tar.gz: dc1ae55d6d5c42dd4811a63689da7033436f2568
5
5
  SHA512:
6
- metadata.gz: f6a5e3848de3b9e91245fcfeb9d74546f38816e285d794601d59461f9dda536ae8ff427c6b0bea8bfa4001657ba8982890808f50786d5a2cfa34942b699dd544
7
- data.tar.gz: 4ec08e0e48c78777aeda9ffe8563d448e9ee42988e41be19149f87fa5a917a107c399108a7eea97c89665de1562b1e4513210eceafd06b20f9264465496b3516
6
+ metadata.gz: 472033267cf83259a6f37ae2041e06dfab735961148a48be84b2da66b876e2e193514d1f69887e25a0d8bc58a3f5c51cbd5206addf0ca7314f014a3a8e9e4929
7
+ data.tar.gz: 3c62a5f13935b8fc6c9e52a40374671693b4c272bd31d4a8ade79b49a8176a1648b0a9b2201b497b41fd6885ecc0fc7d27695cf5451d91a3e6b69fde8762ad32
data/bin/aml CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'aml'
3
- AbstractMarkupLanguage::Base.initialize(ARGV.join(' '))
3
+ AbstractMarkupLanguage::Base.initialize(ARGV.join(' '),0)
data/bin/aml-bundle ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'aml-bundle'
3
+ AbstractMarkupLanguage::Bundle.initialize(ARGV.join(' '))
data/lib/aml/argument.rb CHANGED
@@ -2,15 +2,22 @@ class Argument
2
2
 
3
3
  @@argumental = {}
4
4
  @@required = {}
5
+
6
+ @@error
7
+
8
+ def initialize(arguments,error)
9
+ @@error = error
10
+ parse(arguments)
11
+ end
5
12
 
6
- def initialize(arguments)
13
+ def parse(arguments)
7
14
  arguments = arguments.split('--')
8
15
  arguments.each do |argument|
9
16
  string = argument.split(' ')
10
17
  create(string[0],string[1..string.count].join(' ')) if argument.strip.length > 0
11
18
  end
12
19
  end
13
-
20
+
14
21
  def hash
15
22
  return @@argumental
16
23
  end
@@ -33,6 +40,10 @@ class Argument
33
40
  end
34
41
  message
35
42
  end
43
+
44
+ def clear_required
45
+ @@required = {}
46
+ end
36
47
 
37
48
  def create(name,value)
38
49
  @@argumental[name.to_sym] = value.strip if(value.length > 0)
@@ -0,0 +1,163 @@
1
+ class Compile
2
+
3
+ @@structure = []
4
+
5
+ def initialize(parse,argument,definition,error)
6
+ error.compile(parse,definition,error)
7
+ if(error.count == 0)
8
+ prepare_line_variable(parse.file[:line],definition)
9
+ prepare_mixin_structure(parse.file[:line],definition)
10
+ structure = prepare_structure(parse.file[:line])
11
+ structure.each do |group|
12
+ recursive_close(group)
13
+ end
14
+ make = Make.new(@@structure)
15
+ end
16
+ end
17
+
18
+ def prepare_line_variable(lines,definition)
19
+ regex = /\@\(((?<bundle>[\w|\-]+)\.)?(?<name>[\w|\-]+)\)/
20
+ if lines.kind_of?(Array)
21
+ lines.each do |line|
22
+ line = line_variable_replace(line,definition)
23
+ end
24
+ else
25
+ lines = line_variable_replace(lines,definition)
26
+ end
27
+ check = 0
28
+ if lines.kind_of?(Array)
29
+ check_text = lines.select{|k| k[:text].to_s.match(regex)}
30
+ check_value = lines.select{|k| k[:value].to_s.match(regex)}
31
+ check = check_text.count+check_value.count
32
+ end
33
+ prepare_line_variable(lines,definition) if check > 0
34
+ lines
35
+ end
36
+
37
+ def line_variable_replace(line,definition)
38
+ regex = /\@\(((?<bundle>[\w|\-]+)\.)?(?<name>[\w|\-]+)\)/
39
+ %w"text value".each do |key|
40
+ key = key.to_sym
41
+ if line.has_key?(key)
42
+ line[key] = line[key].to_s.gsub(regex){definition.variable($2,line[:number],$1.to_s.length > 0 ? $1 : false).to_s} if line[key].to_s.length > 0
43
+ end
44
+ end
45
+ if line.has_key?(:attributes) and line[:attributes].count > 0
46
+ line[:attributes].each do |k,v|
47
+ line[:attributes][k] = line[:attributes][k].to_s.gsub(regex){definition.variable($2,line[:number],$1.to_s.length > 0 ? $1 : false).to_s} if v.to_s.length > 0
48
+ end
49
+ end
50
+ line
51
+ end
52
+
53
+ def line_attribute_replace(line,default_attributes,mixin_attributes)
54
+ regex = /@\(\:(?<name>[\w|\-]+)\)/
55
+ mixin_attributes.merge!(default_attributes){|key, mixin, default| mixin}
56
+ if mixin_attributes.length > 0
57
+ %w"text value".each do |key|
58
+ line[key.to_sym] = line[key.to_sym].to_s.gsub(regex){mixin_attributes[$1.to_sym]} if line.has_key?(key.to_sym)
59
+ end
60
+ attributes = line[:attributes].clone
61
+ attributes.each do |k,v|
62
+ attributes[k] = v.to_s.gsub(regex){mixin_attributes[$1.to_sym]}
63
+ end
64
+ line[:attributes] = attributes
65
+ end
66
+ line
67
+ end
68
+
69
+ def prepare_mixin_structure(lines,definition)
70
+ lines.each_with_index do |line,index|
71
+ if line[:type] == :mixin
72
+ lines.delete_at index
73
+ mixin = definition.mixin(line[:name],line[:bundle])
74
+ if(mixin.is_a?(Hash))
75
+ mixin = mixin.clone
76
+ mixin[:structure].each_with_index do |mline,mindex|
77
+ mixin_line = mline.clone
78
+ mixin_line[:index] += line[:index]
79
+ mixin_line[:number] = line[:number]
80
+ line_attribute_replace(mixin_line,mixin[:attribute],line[:attributes])
81
+ lines.insert(index+mindex,mixin_line)
82
+ end
83
+ end
84
+ break
85
+ end
86
+ end
87
+ prepare_mixin_structure(lines,definition) if(lines.select{|k|k[:type]==:mixin}).count > 0
88
+ prepare_line_variable(lines,definition)
89
+ lines
90
+ end
91
+
92
+ def prepare_structure(struct,index=0,pstruct={:line=>false,:children=>[]})
93
+ parent_tags = struct.each_index.select{|i| struct[i][:index] == index}.compact
94
+ parent_struct = []
95
+ parent_tags.each_with_index do |struct_index,index|
96
+ last_struct_index = parent_tags.count > index+1 ? parent_tags[index+1]-1 : parent_tags[index]
97
+ last_struct_index = struct.count if(parent_tags.count == index+1)
98
+ parent_struct << struct[struct_index..last_struct_index]
99
+ end
100
+ parent_struct.each do |parent_structure|
101
+ index_struct = {}
102
+ index_struct[:line] = parent_structure[0]
103
+ c = prepare_structure(parent_structure,index+1)
104
+ index_struct[:children] = c if c.count > 0
105
+ pstruct[:children] << index_struct
106
+ end
107
+ pstruct[:children]
108
+ end
109
+
110
+ def recursive_close(struct,index=0)
111
+ next_index = struct.key?(:line) ? index+1 : index
112
+ tab_index = "\t" * index
113
+ opening_tag_attributes = ""
114
+ opening_tag = ""
115
+ closing_tag = ""
116
+
117
+ #STRING
118
+ if(struct[:line][:type]==:string)
119
+ opening_tag = struct[:line][:value]
120
+ end
121
+
122
+ #TAG
123
+ if(struct[:line][:type]==:tag)
124
+ opening_tag_attributes = tag_line_attributes(struct[:line])
125
+ opening_tag = "<#{struct[:line][:name]}#{opening_tag_attributes}>"
126
+ closing_tag = "</#{struct[:line][:name]}>"
127
+ if struct.key?(:line)
128
+ if struct[:line][:close] == 'self'
129
+ opening_tag = "<#{struct[:line][:name]}#{opening_tag_attributes} />"
130
+ closing_tag = ""
131
+ end
132
+ if struct[:line][:close] == 'none'
133
+ closing_tag = ""
134
+ end
135
+ end
136
+ end
137
+ tag_text = struct[:line][:text]
138
+ if struct.key?(:children)
139
+ tag_text = "\r\n#{tab_index}\t#{tag_text}" if tag_text.to_s.length > 0
140
+ @@structure << "#{tab_index}#{opening_tag}#{tag_text}" if struct.key?(:line)
141
+ struct[:children].each do |struct_children|
142
+ recursive_close(struct_children,next_index)
143
+ end
144
+ @@structure << "#{tab_index}#{closing_tag}" if struct.key?(:line)
145
+ else
146
+ @@structure << "#{tab_index}#{opening_tag}#{tag_text}#{closing_tag}"
147
+ end
148
+
149
+ end
150
+
151
+ def tag_line_attributes(line)
152
+ if line[:type] == :tag
153
+ line[:attributes][:id] = line[:id] if line[:id].to_s.length > 0 and line[:attributes][:id].to_s.length == 0
154
+ line[:attributes][:class] = line[:class] if line[:class].to_s.length > 0 and line[:attributes][:class].to_s.length == 0
155
+ attributes = ""
156
+ line[:attributes].each do |attribute,value|
157
+ attributes += " #{attribute.to_s}=\"#{value.to_s}\"" if(value.to_s.length) > 0 and value.to_s != 'nil'
158
+ attributes += " #{attribute.to_s}" if(value.to_s) == "nil"
159
+ end
160
+ attributes
161
+ end
162
+ end
163
+ end
@@ -0,0 +1,19 @@
1
+ class Core
2
+ def self.loop(index=0, a={})
3
+ return "loop"
4
+ end
5
+ def self.date(index=0, a={:format=>'%Y-%m-%d %H:%M:%S'})
6
+ time = Time.new
7
+ return time.strftime(a[:format])
8
+ end
9
+ def self.ipsum(index=0, a={})
10
+ return "%p lorem ipsum sit amet dolor"
11
+ end
12
+ def self.random(index=0, a={})
13
+ return "random"
14
+ end
15
+ def self.copyright(index=0, a={})
16
+ time = Time.new
17
+ return "%p &copy; #{time.year}"
18
+ end
19
+ end
@@ -0,0 +1,52 @@
1
+ %!-- VARIABLES --%
2
+
3
+ @aml = Abstract Markup Language
4
+
5
+ %!-- DOCTYPES ---%
6
+
7
+ %%html5{
8
+ <!DOCTYPE html>
9
+ %html
10
+ }
11
+ %%html401s{
12
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
13
+ %html
14
+ }
15
+ %%html401t{
16
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
17
+ %html
18
+ }
19
+ %%html401f{
20
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
21
+ %html
22
+ }
23
+ %%xhtml1s{
24
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
25
+ %html
26
+ }
27
+ %%xhtml1t{
28
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
29
+ }
30
+ %%xhtml1f{
31
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
32
+ %html
33
+ }
34
+ %%xhtml11{
35
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
36
+ %html
37
+ }
38
+
39
+
40
+ %!-- HELPERS ---%
41
+
42
+ %%stylesheet(:href=>''){
43
+ %/link{:href=>'@(:href).css',:rel=>'stylesheet'}
44
+ }
45
+
46
+ %%javascript(:href=>''){
47
+ %/script{:href=>'@(:href).js',:type=>'text/javascript'}
48
+ }
49
+
50
+ %%favicon(:href=>''){
51
+ %/link{:rel=>'icon',:type=>'image/png',:href=>'@(:href)'}
52
+ }
@@ -0,0 +1,61 @@
1
+ class Definition
2
+ def initialize(parse,scope=false,add_bundle=true,add_mixin=true,add_variable=true)
3
+ @bundle = {}
4
+ @mixin = {}
5
+ @variable = {}
6
+ add(parse,scope,add_bundle,add_mixin,add_variable)
7
+ end
8
+ def add(parse,scope=false,add_bundle=true,add_mixin=true,add_variable=true)
9
+ #define bundles
10
+ parse[:line].select{|k,v| k[:type] == :method or k[:type] == :partial}.each do |bundle|
11
+ @bundle[bundle[:bundle]] = camelCase(bundle[:bundle]) if @bundle.has_key?(bundle[:bundle]) == false and bundle[:bundle] != false
12
+ end if add_bundle
13
+ #define mixins
14
+ mixin_def = parse[:line].reject{|k,v| k[:type] != :mixin_def}
15
+ mixin_end = parse[:line].reject{|k,v| k[:type] != :mixin_end}
16
+ if(mixin_def.count == mixin_end.count)
17
+ mixin_def.each_with_index do |mixin,index|
18
+ mixin[:bundle] = scope if scope
19
+ @mixin[mixin[:bundle]] = {} if @mixin.has_key?(mixin[:bundle]) == false
20
+ @mixin[mixin[:bundle]][mixin[:name]] = {} if @mixin[mixin[:bundle]].has_key?(mixin[:name]) == false
21
+ @mixin[mixin[:bundle]][mixin[:name]] = {
22
+ :attribute => mixin[:attributes],
23
+ :structure => parse[:line].reject{|k,v| k[:number].between?(mixin[:number]+1,mixin_end[index][:number]-1) == false}
24
+ }
25
+ @mixin[mixin[:bundle]][mixin[:name]][:structure].each do |line|
26
+ line[:index]-=1
27
+ end
28
+ parse[:line] = parse[:line].reject{|k,v| k[:number].between?(mixin[:number],mixin_end[index][:number])}
29
+ end
30
+ end if add_mixin
31
+ #define variables
32
+ variable = parse[:line].reject{|k,v| k[:type] != :variable_def}
33
+ variable.each do |var|
34
+ var[:bundle] = scope if scope
35
+ @variable[var[:bundle]] = {} if @variable.has_key?(var[:bundle]) == false
36
+ @variable[var[:bundle]][var[:name]] = {} if @variable[var[:bundle]].has_key?(var[:name]) == false
37
+ @variable[var[:bundle]][var[:name]][var[:number]] = var[:value]
38
+ end if add_variable
39
+ end
40
+ def camelCase(value)
41
+ value.split('-').each{|i|i.capitalize!}.join if value != false
42
+ end
43
+ def bundles
44
+ @bundle
45
+ end
46
+ def variables
47
+ @variable
48
+ end
49
+ def variable(name,line,bundle=false)
50
+ @variable[bundle].select{|variable| variable == name}.first[1].select{|line_number,value| line_number <= line}.values.last if (@variable.has_key?(bundle) and @variable[bundle].has_key?(name))
51
+ end
52
+ def mixins
53
+ @mixin
54
+ end
55
+ def mixins_of(bundle=false)
56
+ @mixin[bundle]
57
+ end
58
+ def mixin(name,bundle=false)
59
+ @mixin[bundle].select{|mixin|mixin==name}.first[1] if(@mixin.has_key?(bundle) and @mixin[bundle].has_key?(name))
60
+ end
61
+ end
data/lib/aml/error.rb ADDED
@@ -0,0 +1,84 @@
1
+ class Error
2
+ @errors
3
+ def initialize
4
+ @errors = []
5
+ end
6
+ def log(bundle,partial,file,line,message)
7
+ file = "partial/#{file}" if partial != false
8
+ file = "#{bundle}/#{file}" if bundle != false
9
+ line = line ? "::#{line}" : nil
10
+ @errors << "#{file}#{line} #{message}"
11
+ end
12
+ def count
13
+ @errors.count
14
+ end
15
+ def log_delete
16
+ begin
17
+ File.delete(File.join(AbstractMarkupLanguage::Base.basePath,'error.log'))
18
+ rescue Exception => e
19
+ end
20
+ end
21
+ def log_create
22
+ error_output = ""
23
+ @errors.each do |error|
24
+ error_output += "#{error}\r\n"
25
+ end
26
+ File.write(File.join(AbstractMarkupLanguage::Base.basePath,'error.log'),error_output)
27
+ end
28
+ def output
29
+ @errors.each do |error|
30
+ error
31
+ end
32
+ end
33
+ def match
34
+ /\((\w+)\)\:(?<line>\d+)\:(\s{1,})?(?<message>.+)/
35
+ end
36
+ def compile(parse,definition,error)
37
+ error.syntax(parse,false,false,error)
38
+ #Check Tag, Partial, Mixin Call, and Method Call Attributes for Errors
39
+ parse.watch.each do |file|
40
+ if file[:partial]
41
+ file_path = File.join(AbstractMarkupLanguage::Base.basePath,'partial')
42
+ file_path = File.join(AbstractMarkupLanguage::Base.basePath,file[:bundle],'partial') if file[:bundle]
43
+ partial_parse = Parse.new(file_path,file[:file])
44
+ error.syntax(partial_parse,file[:bundle],file[:partial],error)
45
+ end
46
+ end
47
+ #Check Mixin Definitions for Errors
48
+ definition.mixins.each do |bundle,mixins|
49
+ if(bundle != false and bundle != 'core')
50
+ file_path = File.join(AbstractMarkupLanguage::Base.basePath,bundle)
51
+ mixin_parse = Parse.new(file_path,'mixin.aml')
52
+ error.syntax(mixin_parse,bundle,false,error)
53
+ end
54
+ end
55
+ end
56
+ def syntax(parse,bundle=false,partial=false,error)
57
+ parse.file[:line].each do |line|
58
+ if(line[:attributes] && line[:attributes][:abstract_markup_language_exception] or partial && line[:type] == :mixin_def)
59
+ #Mixin definition in partials is not possible...
60
+ if line[:type] == :mixin_def and partial
61
+ file_to_define = bundle ? "#{bundle}/minxin.aml" : AbstractMarkupLanguage::Base.watchFile
62
+ error.log(bundle,partial,parse.file[:name],line[:number],"mixin must be defined in #{file_to_define}; #{line[:name]} cannot be defined in a partial")
63
+ else
64
+ line[:type] = "mixin definition" if line[:type] == :mixin_def
65
+ error.log(bundle,partial,parse.file[:name],line[:number],"attribute syntax error on #{line[:name]} #{line[:type]}")
66
+ end
67
+ end
68
+ if line[:type] == :method
69
+ begin
70
+ #ap AbstractMarkupLanguage::Base.const_get(definition.camelCase(line[:bundle])).method(line[:name]).call()
71
+ rescue Exception => e
72
+ message = "#{line[:name]} method undefined in #{line[:bundle]} bundle"
73
+ if !AbstractMarkupLanguage::Base.constants.include? definition.camelCase(line[:bundle]).to_sym
74
+ message = "#{line[:bundle]} bundle undefined"
75
+ end
76
+ error.log(bundle,partial,parse.file[:name],line[:number],message)
77
+ false
78
+ end
79
+ #.method(line[:name]).call()
80
+ #ap Base.const_get(line[:bundle]).method(line[:name]).call()
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,38 @@
1
+ LineType = Struct.new(:regex) do
2
+ def match?(string)
3
+ string.match(regex)
4
+ end
5
+ def attributes(match)
6
+ begin
7
+ eval("{#{match[:attributes].to_s}}")
8
+ rescue Exception => e
9
+ {:abstract_markup_language_exception=>true}
10
+ end
11
+ end
12
+ def bundle(match)
13
+ match[:bundle].to_s
14
+ end
15
+ def class(match)
16
+ match[:class].to_s.split('.').join(' ').strip!
17
+ end
18
+ def name(match)
19
+ match[:name].to_s
20
+ end
21
+ def text(match)
22
+ match[:text].to_s.strip!
23
+ end
24
+ def value(match)
25
+ match[:value].to_s
26
+ end
27
+ def id_first(match)
28
+ match[:id_first].to_s
29
+ end
30
+ def id_last(match)
31
+ match[:id_last].to_s
32
+ end
33
+ def close(match)
34
+ # => </tag> /self> >
35
+ type = %w(tag self none)
36
+ type[match[:close].to_s.length]
37
+ end
38
+ end
data/lib/aml/make.rb ADDED
@@ -0,0 +1,12 @@
1
+ class Make
2
+ def initialize(structure)
3
+ makeFile = File.join(AbstractMarkupLanguage::Base.basePath,AbstractMarkupLanguage::Base.makeFile)
4
+ File.open(makeFile, 'w'){|file|
5
+ struct_count = structure.count-1
6
+ structure.each_with_index do |line,index|
7
+ new_line = (index < struct_count) ? "\r\n" : ""
8
+ file.write(line+new_line) if line.strip.length > 0
9
+ end
10
+ }
11
+ end
12
+ end