aml 0.1.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,80 @@
1
+ # Convert a string input to a Hash output.
2
+ class Line
3
+ # Create a new Line with a symbol type and regular expression.
4
+ def initialize(bundle, type, regex)
5
+ @line = {}
6
+ @line[:type] = type
7
+ @line[:regex] = regex
8
+ @line[:bundle] = bundle
9
+ end
10
+ # Return a Hash if the line match is successful, otherwise false.
11
+ def match?(string,number)
12
+ match = string.match(@line[:regex])
13
+ match ? process_match(match,number) : false
14
+ end
15
+ private
16
+ # Return a processed Hash based on the matches and convert keys to symbols.
17
+ def process_match(match,number)
18
+ line = Hash[match.names.zip(match.captures)]
19
+ line = Hash[line.map{|(k,v)| [k.to_sym,v]}]
20
+ line[:type] = @line[:type]
21
+ line[:index] = match[0].match(/^\t{0,}/).to_s.length
22
+ line[:number] = number
23
+ line[:name] = 'div' and line[:type] = :tag if line[:type] == :tag_shorthand
24
+ # attribute value to Hash
25
+ line[:attribute] = recursive_string_to_hash(line[:attribute]) if line.key? :attribute
26
+ # key values to String
27
+ %w[bundle class name text value id_first id_last reset].each do |key|
28
+ line[key.to_sym] = line[key.to_sym].to_s if line.key? key.to_sym
29
+ end
30
+ # key values to String.Strip!
31
+ %w[text].each do |key|
32
+ line[key.to_sym] = line[key.to_sym].strip! if line.key? key.to_sym
33
+ end
34
+ # bundle
35
+ line[:bundle] = @line[:bundle] if line.key? :bundle and line[:bundle].to_s.length == 0
36
+ if line[:type] == :mixin
37
+ line[:bundle] = 'core' and line[:name] = line[:name][1..-1] if line[:name][0] == '.'
38
+ elsif line[:type] == :method
39
+ line[:bundle] = 'core' if line[:bundle] == false
40
+ end
41
+ # class
42
+ if line.key? :class
43
+ line[:class] = '.' + line[:class]
44
+ line[:attribute][:class] = line[:class].split('.').join(' ').strip!
45
+ line.delete(:class)
46
+ end
47
+ # close
48
+ line[:close] = %w(tag self none)[line[:close].to_s.length].to_sym if line.key? :close
49
+ # id
50
+ if line.key? :id_first and line[:id_first].length > 0
51
+ line[:attribute][:id] = line[:id_first]
52
+ elsif line.key? :id_last and line[:id_last].length > 0
53
+ line[:attribute][:id] = line[:id_last]
54
+ end
55
+ line.delete(:id_first) if line.key? :id_first
56
+ line.delete(:id_last) if line.key? :id_last
57
+ # reset
58
+ line[:reset] = line[:reset].to_s.length == 0 ? false : true if line.key? :reset
59
+ # return sorted Hash
60
+ Hash[line.sort]
61
+ end
62
+ # Return the Hash equivalent of a given String (no evaluation).
63
+ def recursive_string_to_hash(string)
64
+ hash = {}
65
+ regex = /:(?<name>\w+)\s?=>\s?(?<hash>{(.+?)?}|(?<quote>'|")(?<value>.+?)??\k<quote>)/
66
+ names = regex.names
67
+ if string != nil
68
+ string.scan(regex){|match|
69
+ thisHash = Hash[names.zip(match)]
70
+ if thisHash["hash"].to_s[0] == "{"
71
+ hash[thisHash["name"].to_sym] = recursive_string_to_hash(thisHash["hash"])
72
+ else
73
+ hash[thisHash["name"].to_sym] = thisHash["value"].to_s.strip
74
+ end
75
+ }
76
+ end
77
+ # return sorted Hash
78
+ Hash[hash.sort]
79
+ end
80
+ end
@@ -0,0 +1,24 @@
1
+ class Parse
2
+ require "aml/Line"
3
+ def initialize(bundle=false)
4
+ @line = []
5
+ @line << Line.new(bundle, :variable_definition, /^(\s{1,})?\@((?<bundle>[\w|\-]+)\.)?(?<name>[\w|\-]+)\s?(\=)\s?(?<value>.+)?$/)
6
+ @line << Line.new(bundle, :mixin, /^(\s{1,})?%\(((?<bundle>[\w|\-]+)\.)?(?<name>[^~][\w|\-]+)\)(\{(?<attribute>.+)\})?[^\{]?/)
7
+ @line << Line.new(bundle, :mixin_definition, /^%%(?<name>[\w|\-]+)(\((?<attribute>.+?)\))?{/)
8
+ @line << Line.new(bundle, :mixin_end, /^\}$/)
9
+ @line << Line.new(bundle, :partial, /^(\s{1,})?%\(\~((?<bundle>[\w|\-]+)\.)?(?<name>[\w|\-]+)\)(\{(?<attribute>.+)\}[^\{]?)?$/)
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>.+)?$/)
12
+ @line << Line.new(bundle, :conditional, /^(\s{1,})?-\s?(?<name>if|loop|end)(\s(?<value>.+))?$/)
13
+ @line << Line.new(bundle, :empty, /^$/)
14
+ @line << Line.new(bundle, :eval, /^(\s{1,})?==(\s{1,})(?<value>.+)?/)
15
+ @line << Line.new(bundle, :string, /(\s{1,})?(?<value>.+)?/)
16
+ end
17
+ # Return the line as a Hash.
18
+ def line(string,number)
19
+ @line.each do |type|
20
+ line = type.match?(string,number)
21
+ return line if line
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,59 @@
1
+ class Prepare
2
+ require "aml/Cluster"
3
+ def initialize(file)
4
+ @log = []
5
+ @cluster = false
6
+ @file = []
7
+ @watch = []
8
+ # Load Core Bundle
9
+ path = File.join(File.dirname(File.expand_path(__FILE__)),'core')
10
+ add_file(File.join(path,'mixin.aml'),'mixin', 'core')
11
+ add_watch(File.join(path,'method.rb'), 'method', 'core')
12
+ # Load Local Bundles
13
+ bundles = Definition.new(file, false)
14
+ bundles.self[:hash].reject{|k|k[:bundle] == false or k[:bundle] == nil}.each do |bundle|
15
+ if @file.select{|k|k[:bundle] == bundle[:bundle]}.count == 0
16
+ path = File.join(File.dirname(file), bundle[:bundle])
17
+ add_file(File.join(path,'mixin.aml'), 'mixin', bundle[:bundle])
18
+ add_watch(File.join(path,'method.rb'), 'method', bundle[:bundle])
19
+ # Load Only Required Partials
20
+ bundles.self[:hash].reject{|k|k[:bundle] != bundle[:bundle]}.reject{|k|k[:type] != :partial}.each do |partial|
21
+ add_file(File.join(path,'partial',partial[:name]+'.aml'), 'partial', bundle[:bundle], bundle[:name])
22
+ end
23
+ end
24
+ end
25
+ # Load Local File Mixin & Method
26
+ path = File.join(File.dirname(file))
27
+ add_file(File.join(path,'mixin.aml'), 'mixin')
28
+ add_watch(File.join(path,'method.rb'), 'method')
29
+ # Load Only Requird Local Partials
30
+ bundles.self[:hash].select{|k|k[:type] == :partial and k[:bundle] == false}.each do |bundle|
31
+ add_file(File.join(path,'partial',bundle[:name]+'.aml'), 'partial', bundle[:bundle], bundle[:name])
32
+ end
33
+ # Load Local File
34
+ add_file(file,'base')
35
+
36
+ @watch.concat(@file)
37
+ process
38
+ end
39
+ def add_file(file, type, bundle=false, partial=false)
40
+ @file << {:file=>file, :type=> type, :bundle=>bundle, :partial=>partial}
41
+ end
42
+ def add_watch(file, type, bundle=false)
43
+ @watch << {:file=>file, :bundle=>bundle}
44
+ end
45
+ def process
46
+ @cluster = Cluster.new(@file)
47
+ @cluster.process
48
+ @log = cluster.log
49
+ end
50
+ def log
51
+ @log
52
+ end
53
+ def cluster
54
+ @cluster
55
+ end
56
+ def watch
57
+ @watch
58
+ end
59
+ end
@@ -1,13 +1,23 @@
1
1
  class Core
2
2
 
3
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]
4
-
4
+
5
5
  def self.date(index=0, a={}, d={:format=>'%Y-%m-%d %H:%M:%S'})
6
6
  a = d.merge(a)
7
7
  time = Time.new
8
8
  return time.strftime(a[:format])
9
9
  end
10
-
10
+
11
+ def self.copyright(index=0, a={}, d={:name=>false})
12
+ a = d.merge(a)
13
+ return '&copy; ' + self.year + ' ' + a[:name]
14
+ end
15
+
16
+ def self.alphanumeric(index=0, a={}, d={:string=>nil})
17
+ a = d.merge(a)
18
+ return a[:string].downcase.gsub(/[^a-zA-Z0-9]/,'-')
19
+ end
20
+
11
21
  def self.year(index=0, a={})
12
22
  return self.date(index,{:format=>'%Y'})
13
23
  end
@@ -21,6 +31,11 @@ class Core
21
31
  string = self._random_paragraph(a[:number])
22
32
  elsif a[:type] == 'sentence'
23
33
  string = self._random_sentence(a[:number])
34
+ 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!
24
39
  elsif a[:type] == 'word'
25
40
  string = self._random_word(a[:capitalize])
26
41
  elsif a[:type] == 'name'
@@ -7,7 +7,7 @@
7
7
  %%html5-{
8
8
  <!DOCTYPE html>
9
9
  }
10
- %%html5{
10
+ %%html5(:this=>'this',:that=>'that'){
11
11
  %(.html5-)
12
12
  %html
13
13
  }
metadata CHANGED
@@ -1,38 +1,34 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1.1
4
+ version: 0.1.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: 2014-04-23 00:00:00.000000000 Z
11
+ date: 2014-06-08 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.
15
15
  email: daniel@abstractmarkup.com
16
16
  executables:
17
17
  - aml
18
- - aml-bundle
19
18
  extensions: []
20
19
  extra_rdoc_files: []
21
20
  files:
22
21
  - bin/aml
23
- - bin/aml-bundle
24
- - lib/aml/argument.rb
25
- - lib/aml/compile.rb
22
+ - lib/aml/Argument.rb
23
+ - lib/aml/Build.rb
24
+ - lib/aml/Cluster.rb
25
+ - lib/aml/Compile.rb
26
26
  - lib/aml/core/method.rb
27
27
  - lib/aml/core/mixin.aml
28
- - lib/aml/definition.rb
29
- - lib/aml/error.rb
30
- - lib/aml/line_type.rb
31
- - lib/aml/make.rb
32
- - lib/aml/parse.rb
33
- - lib/aml/requirement.rb
34
- - lib/aml/watch.rb
35
- - lib/aml-bundle.rb
28
+ - lib/aml/Definition.rb
29
+ - lib/aml/Line.rb
30
+ - lib/aml/Parse.rb
31
+ - lib/aml/Prepare.rb
36
32
  - lib/aml.rb
37
33
  homepage: https://abstractmarkup.com
38
34
  licenses:
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'aml-bundle'
3
- AbstractMarkupLanguage::Bundle.initialize(ARGV.join(' '))
@@ -1,52 +0,0 @@
1
- require 'fileutils'
2
- require 'aml/argument'
3
- module AbstractMarkupLanguage
4
- class Bundle
5
- def self.initialize(arguments)
6
- argument = Argument.new(arguments)
7
- #argument.create_action('create')
8
- #argument.create_action('install')
9
- #argument.create_action('update')
10
- #argument.create_action('delete')
11
-
12
- argument.required('action','The required --generate argument has not been defined.')
13
- argument.required('name','The required --name argument has not been defined.')
14
- if argument.has_requirements?#and directory exists false?)
15
- basePath = File.dirname('~')
16
-
17
- argument.create_if_empty('--','bundle')
18
-
19
- argument.create_if_empty('method','')
20
- argument.create_if_empty('mixin','')
21
- argument.create_if_empty('partial','')
22
- #ap argument.hash
23
- name = {:directory => argument.read('name').downcase.gsub(' ','-'), :class => argument.read('name').gsub(' ','')}
24
- FileUtils.mkdir_p(File.join(name[:directory],'partial'))
25
- %w"method.rb mixin.aml".each do |file|
26
- File.new(File.join(name[:directory],"#{file}"), 'w')
27
- end
28
- mixins = "%!-- #{argument.read('name')} Mixin Definitions --%"
29
- argument.read('mixin').split(' ').each do |mixin|
30
- mixin = mixin.split(':')
31
- mixin_name = mixin[0]
32
- attributes = ""
33
- if mixin.count > 1
34
- mixin.shift
35
- mixin.each do |attribute|
36
- a = attribute.split('=')
37
- attributes +="#{a[0]}='#{a[1]}',"
38
- end
39
- attributes = "(#{attributes[0..-2]})"
40
- end
41
- mixins += "\r\n%%#{mixin_name}#{attributes}{\r\n\t\r\n}"
42
- end
43
- File.open(File.join(name[:directory],'mixin.aml'), 'w'){|file|file.write(mixins)}
44
- File.open(File.join(name[:directory],'method.rb'), 'w'){|file|file.write("class #{name[:class]}\r\n\tdef self.aml\r\n\t\t\r\n\tend\r\nend")}
45
- argument.read('partial').split(' ').each do |partial|
46
- File.new(File.join(name[:directory],'partial',"#{partial}.aml"),'w')
47
- end
48
- end
49
- end
50
-
51
- end
52
- end
@@ -1,80 +0,0 @@
1
- class Argument
2
-
3
- @@argumental = {}
4
- @@required = {}
5
-
6
- @@error
7
-
8
- def initialize(arguments,error)
9
- @@error = error
10
- parse(arguments)
11
- end
12
-
13
- def parse(arguments)
14
- arguments = arguments.split('--')
15
- arguments.each do |argument|
16
- string = argument.split(' ')
17
- create(string[0],string[1..string.count].join(' ')) if argument.strip.length > 0
18
- end
19
- end
20
-
21
- def hash
22
- return @@argumental
23
- end
24
-
25
- def required(name,message)
26
- @@required[name.to_sym] = {:message=>message.strip, :defined=>false}
27
- end
28
-
29
- def has_requirements?
30
- @@required.each do|key,hash|
31
- hash[:defined] = true if(@@argumental.select{|k,v| k.to_s == key.to_s}.count == 1)
32
- end
33
- @@required.select{|k,v| v[:defined] == false}.count == 0 ? true : false
34
- end
35
-
36
- def missing_required
37
- message = []
38
- @@required.select{|k,v| v[:defined] == false}.each do |attribute,hash|
39
- message << hash[:message]
40
- end
41
- message
42
- end
43
-
44
- def clear_required
45
- @@required = {}
46
- end
47
-
48
- def create(name,value)
49
- @@argumental[name.to_sym] = value.strip #if(value.length > 0)
50
- end
51
-
52
- def create_if_empty(name,value)
53
- create(name,value) if @@argumental.select{|k,v| k.to_s == name}.count == 0
54
- end
55
-
56
- def read(name)
57
- @@argumental[name.to_sym]
58
- end
59
-
60
- def defined(name)
61
- @@argumental.select{|k,v| k.to_s == name}.count > 0
62
- end
63
-
64
- def update(name,value)
65
- create(name,value)
66
- end
67
-
68
- def update_append(name,value)
69
- create(name,"#{value}#{read(name)}")
70
- end
71
-
72
- def update_prepend(name,value)
73
- create(name,"#{read(name)}#{value}")
74
- end
75
-
76
- def delete(name)
77
- @@argumental = @@argumental.select{|k,v| k.to_s != name}
78
- end
79
-
80
- end
@@ -1,325 +0,0 @@
1
- class Compile
2
-
3
- @@structure = []
4
- @@selfClosing = []
5
-
6
- def initialize(parse,argument,definition,error)
7
- @@selfClosing = argument.read('selfClosing').split(',')
8
- error.compile(parse,definition,error)
9
- if(error.count == 0)
10
- prepare_line_variable(parse.file[:line],definition)
11
- lines = []
12
- parse.file[:line].each do |line|
13
- lines << post_prepare_line_variable(line)
14
- end
15
-
16
- parse.file[:line] = lines
17
-
18
- prepare_mixin_structure(parse.file[:line],definition)
19
- prepare_partial_structure(parse.file[:line],definition)
20
- prepare_method_structure(parse.file[:line],definition)
21
-
22
- prepare_string_line_merge(parse.file[:line])
23
-
24
- structure = prepare_structure(parse.file[:line])
25
-
26
- recursive_merge_lines(structure)
27
-
28
- structure.each do |group|
29
- recursive_close(group,0,definition,0)
30
- end
31
-
32
- make = Make.new(@@structure)
33
- end
34
- end
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
-
71
- def prepare_method_structure(lines,definition)
72
- lines.each_with_index do |line,index|
73
- if line[:type] == :method
74
- line[:type] = :string
75
- bundle = line[:bundle]
76
- bundle = "Core" if bundle == 'core'
77
- line[:value] = AbstractMarkupLanguage::Base.const_get(bundle).method(line[:name]).call(line[:index],line[:attributes]) + line[:value]
78
- end
79
- end
80
- lines
81
- end
82
-
83
- def prepare_partial_structure(lines,definition)
84
- definition_partial = definition.variables.clone
85
- bundle = nil
86
- lines.each_with_index do |line,index|
87
- if line[:type] == :partial
88
- lines.delete_at index
89
- bundle = line[:bundle]
90
- directory = 'partial'
91
- directory = File.join(line[:bundle],directory) if line[:bundle]
92
- directory = File.join(AbstractMarkupLanguage::Base.basePath, directory)
93
- variable = {}
94
- definition.variables[line[:bundle]].each do |var,val|
95
- value = val.count > 1 ? val.to_a.last[1] : val[1]
96
- value = line[:attributes][var.to_sym] if line[:attributes].has_key?(var.to_sym)
97
- variable[var] = {1 => value} if value != nil
98
- end if definition.variables[line[:bundle]] != nil
99
- partial = Parse.new(File.join(directory),"#{line[:name]}.aml",true, line[:bundle])
100
- partial.file[:line].each_with_index do |pline,pindex|
101
- pline[:index] += line[:index]
102
- pline[:number] = line[:number]
103
- lines.insert(index+pindex,pline)
104
- end
105
- definition_partial[line[:bundle]] = definition_partial[line[:bundle]].merge(variable) if definition_partial[line[:bundle]] != nil
106
- vars = DefinitionVariable.new(definition_partial)
107
- prepare_line_variable(lines,vars)
108
- break
109
- end
110
- end
111
- prepare_partial_structure(lines,definition) if(lines.select{|k|k[:type]==:partial}).count > 0
112
- prepare_line_variable(lines,definition)
113
- prepare_mixin_structure(lines,definition)
114
- lines
115
- end
116
-
117
- def prepare_line_variable(lines,definition)
118
- regex = /\@\(((?<bundle>[\w|\-]+)\.)?(?<name>[\w|\-]+)\)/
119
- if lines.kind_of?(Array)
120
- lines.each do |line|
121
- line = line_variable_replace(line,definition)
122
- end
123
- else
124
- lines = line_variable_replace(lines,definition)
125
- end
126
- check = 0
127
- if lines.kind_of?(Array)
128
- check_text = lines.select{|k| k[:text].to_s.match(regex)}
129
- check_value = lines.select{|k| k[:value].to_s.match(regex)}
130
- check = check_text.count+check_value.count
131
- end
132
- prepare_line_variable(lines,definition) if check > 0
133
- lines
134
- end
135
-
136
- def post_prepare_line_variable(line)
137
- types = {
138
- :method => LineType.new(/^(\s{1,})?::((?<bundle>[\w|\-]+)\.)?(?<name>[\w|\-]+)(\{(?<attributes>.+)\})?(?<value>.+)?/),
139
- :mixin => LineType.new(/^(\s{1,})?%\(((?<bundle>[\w|\-]+)\.)?(?<name>[^~][\w|\-]+)\)(\{(?<attributes>.+)\})?[^\{]?/),
140
- :partial => LineType.new(/^(\s{1,})?%\(\~((?<bundle>[\w|\-]+)\.)?(?<name>[\w|\-]+)\)(\{(?<attributes>.+)\}[^\{]?)?$/),
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>.+)?/)
142
- }
143
- if line[:type] == :string
144
- types.each do |type, line_type|
145
- if match = line_type.match?(line[:value])
146
- struct = Hash[match.names.zip(match.captures)]
147
- struct = Hash[struct.map{|(k,v)| [k.to_sym,v]}]
148
- struct[:index] = line[:index]
149
- struct[:number] = line[:number]
150
- struct[:type] = type
151
- match.names.each do |name|
152
- struct[name.to_sym] = line_type.send(name.to_s, match)
153
- end
154
- if struct[:name].to_s[0,1] == '.'
155
- #set undefined bundle
156
- struct[:bundle] = 'core'
157
- struct[:name] = struct[:name][1,struct[:name].length]
158
- end
159
- struct[:bundle] = false if struct[:bundle].to_s.length == 0
160
- #set undefined method bundle
161
- struct[:bundle] = 'core' if struct[:type] == :method and !struct[:bundle]
162
- struct[:id] = struct[:id_first].to_s.length > 0 ? struct[:id_first] : struct[:id_last]
163
- struct.delete(:id_first)
164
- struct.delete(:id_last)
165
- line = struct
166
- break
167
- end
168
- end
169
- end
170
- line
171
- end
172
-
173
- def line_variable_replace(line,definition)
174
- regex = /\@\(((?<bundle>[\w|\-]+)\.)?(?<name>[\w|\-]+)\)/
175
- %w"text value".each do |key|
176
- key = key.to_sym
177
- if line.has_key?(key)
178
- 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
179
- end
180
- end
181
- if line.has_key?(:attributes) and line[:attributes].count > 0
182
- line[:attributes].each do |k,v|
183
- if v.is_a?(Hash) == false
184
- 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
185
- end
186
- end
187
- end
188
- end
189
-
190
- def line_attribute_replace(line,default_attributes,mixin_attributes)
191
- regex = /@\(\:(?<name>[\w|\-]+)\)/
192
- mixin_attributes.merge!(default_attributes){|key, mixin, default| mixin}
193
- if mixin_attributes.length > 0
194
- %w"text value".each do |key|
195
- line[key.to_sym] = line[key.to_sym].to_s.gsub(regex){mixin_attributes[$1.to_sym]} if line.has_key?(key.to_sym)
196
- end
197
- if(line.has_key?(:attributes))
198
- attributes = line[:attributes].clone
199
- attributes.each do |k,v|
200
- attributes[k] = v.to_s.gsub(regex){mixin_attributes[$1.to_sym]}
201
- end
202
- line[:attributes] = attributes
203
- end
204
- end
205
- line
206
- end
207
-
208
- def prepare_mixin_structure(lines,definition)
209
- lines.each_with_index do |line,index|
210
- if line[:type] == :mixin
211
- lines.delete_at index
212
- mixin = definition.mixin(line[:name],line[:bundle])
213
- if(mixin.is_a?(Hash))
214
- mixin = mixin.clone
215
- mixin[:structure].each_with_index do |mline,mindex|
216
- mixin_line = mline.clone
217
- mixin_line[:index] += line[:index]
218
- mixin_line[:number] = line[:number]
219
- line_attribute_replace(mixin_line,mixin[:attribute],line[:attributes])
220
- lines.insert(index+mindex,mixin_line)
221
- end
222
- end
223
- break
224
- end
225
- end
226
- prepare_mixin_structure(lines,definition) if(lines.select{|k|k[:type]==:mixin}).count > 0
227
- prepare_line_variable(lines,definition)
228
- lines
229
- end
230
-
231
- def prepare_structure(struct,index=0,pstruct={:line=>false,:children=>[]})
232
- parent_tags = struct.each_index.select{|i| struct[i][:index] == index}.compact
233
- parent_struct = []
234
- parent_tags.each_with_index do |struct_index,index|
235
- last_struct_index = parent_tags.count > index+1 ? parent_tags[index+1]-1 : parent_tags[index]
236
- last_struct_index = struct.count if(parent_tags.count == index+1)
237
- parent_struct << struct[struct_index..last_struct_index]
238
- end
239
- parent_struct.each do |parent_structure|
240
- index_struct = {}
241
- index_struct[:line] = parent_structure[0]
242
- c = prepare_structure(parent_structure,index+1)
243
- index_struct[:children] = c if c.count > 0
244
- pstruct[:children] << index_struct
245
- end
246
- pstruct[:children]
247
- end
248
-
249
- def recursive_close(struct,index=0,definition,index_reset)
250
- next_index = struct.key?(:line) ? index+1 : index
251
- tab_index = "\t" * (index-index_reset)
252
- opening_tag_attributes = ""
253
- opening_tag = ""
254
- closing_tag = ""
255
-
256
- #STRING
257
- if(struct[:line][:type]==:string)
258
- opening_tag = struct[:line][:value]
259
- end
260
-
261
- #TAG
262
- if(struct[:line][:type]==:tag)
263
-
264
- struct[:line][:close] = 'self' if @@selfClosing.include? struct[:line][:name]
265
-
266
- opening_tag_attributes = tag_line_attributes(struct[:line],"",definition)
267
- opening_tag = "<#{struct[:line][:name]}#{opening_tag_attributes}>"
268
- closing_tag = "</#{struct[:line][:name]}>"
269
- if struct.key?(:line)
270
- if struct[:line][:close] == 'self'
271
- opening_tag = "<#{struct[:line][:name]}#{opening_tag_attributes} />"
272
- closing_tag = ""
273
- end
274
- if struct[:line][:close] == 'none'
275
- closing_tag = ""
276
- end
277
- end
278
- end
279
- tag_text = struct[:line][:text]
280
- if struct.key?(:children)
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
-
288
- @@structure << "#{tab_index}#{opening_tag}#{tag_text}" if struct.key?(:line)
289
- struct[:children].each do |struct_children|
290
- recursive_close(struct_children,next_index,definition,index_reset)
291
- end
292
- @@structure << "#{tab_index}#{closing_tag}" if struct.key?(:line)
293
- else
294
- @@structure << "#{tab_index}#{opening_tag}#{tag_text}#{closing_tag}"
295
- end
296
-
297
- end
298
-
299
- def tag_line_attributes(line,base="",definition)
300
- if line[:type] == :tag
301
- line[:attributes][:id] = line[:id] if line[:id].to_s.length > 0 and line[:attributes][:id].to_s.length == 0
302
- line[:attributes][:class] = line[:class] if line[:class].to_s.length > 0 and line[:attributes][:class].to_s.length == 0
303
- attributes = hash_to_attribute_build(line[:attributes],"",definition,line)
304
- attributes = " #{attributes}" if(attributes.length > 0)
305
- end
306
- end
307
-
308
- def hash_to_attribute_build(hash,base="",definition,line)
309
- hash = hash.sort_by{|key, value| key}
310
- string = ""
311
- hash.each do |key, value|
312
- if(value.is_a?(Hash))
313
- value.sort_by{|key, value| key}
314
- string << "#{hash_to_attribute_build(value,"#{base}#{key}-",definition,line)} "
315
- else
316
- #if key == :id
317
- # regex = /\@\(((?<bundle>[\w|\-]+)\.)?(?<name>[\w|\-]+)\)/
318
- # 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
319
- #end
320
- string << "#{base}#{key}=\"#{value}\" "
321
- end
322
- end
323
- string.strip
324
- end
325
- end