aml 0.0.4 → 0.0.5

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: a98badb3128b249e2d67f97138c00077cf9c29c9
4
- data.tar.gz: ff741aa149c9b20fa610348db5ec7269f53d91f7
3
+ metadata.gz: 56b842efcba90148f5942d42734c201b2ad9a50f
4
+ data.tar.gz: 3fe39d419cc1b58aa15023ef03a63c66eeb9fce2
5
5
  SHA512:
6
- metadata.gz: d63d25dfd2b9677de627606cc2695fb35a7ab79653471aa445fd5051a7d15244d0a974ec29d0e3dc203078779f5fbd4b22e48969965312a94d041507df23347e
7
- data.tar.gz: ab2c457d4b293613ba8faf02e5dc7458d023cf5d3635f40d0352ab48ddc13181bace788cba48a8610c06461869d0cdb7838c9c594c6b28addda98b156f5c65b7
6
+ metadata.gz: 212d3cdc3ef4380fe682a7ae76ed1171858169bf226c87c34c898b554e432ab5cf6d289b90473bfd902c40dd97e4929fd3f98cc281a4b0fb0cd56d5984c7d8a3
7
+ data.tar.gz: f21a2425a47952923c091cdfd4b3438f930efe6ac77f302c422ad96049daa8a326b095602e3f5903a3cf8c4c0d611113a193e44ad04eb6b3a5bc7a9d8a71eaa4
data/lib/aml/compile.rb CHANGED
@@ -7,6 +7,7 @@ class Compile
7
7
  if(error.count == 0)
8
8
  prepare_line_variable(parse.file[:line],definition)
9
9
  prepare_mixin_structure(parse.file[:line],definition)
10
+ prepare_partial_structure(parse.file[:line],definition)
10
11
  structure = prepare_structure(parse.file[:line])
11
12
  structure.each do |group|
12
13
  recursive_close(group)
@@ -15,6 +16,39 @@ class Compile
15
16
  end
16
17
  end
17
18
 
19
+ def prepare_partial_structure(lines,definition)
20
+ definition_partial = definition.variables.clone
21
+ bundle = nil
22
+ lines.each_with_index do |line,index|
23
+ if line[:type] == :partial
24
+ lines.delete_at index
25
+ bundle = line[:bundle]
26
+ directory = 'partial'
27
+ directory = File.join(line[:bundle],directory) if line[:bundle]
28
+ directory = File.join(AbstractMarkupLanguage::Base.basePath, directory)
29
+ variable = {}
30
+ definition.variables[line[:bundle]].each do |var,val|
31
+ value = val.count > 1 ? val.to_a.last[1] : val[1]
32
+ value = line[:attributes][var.to_sym] if line[:attributes].has_key?(var.to_sym)
33
+ variable[var] = {1 => value} if value != nil
34
+ end
35
+ partial = Parse.new(File.join(directory),"#{line[:name]}.aml",true, line[:bundle])
36
+ partial.file[:line].each_with_index do |pline,pindex|
37
+ pline[:index] += line[:index]
38
+ pline[:number] = line[:number]
39
+ lines.insert(index+pindex,pline)
40
+ end
41
+ definition_partial[line[:bundle]] = definition_partial[line[:bundle]].merge(variable)
42
+ vars = DefinitionVariable.new(definition_partial)
43
+ prepare_line_variable(lines,vars)
44
+ break
45
+ end
46
+ end
47
+ prepare_partial_structure(lines,definition) if(lines.select{|k|k[:type]==:partial}).count > 0
48
+ prepare_line_variable(lines,definition)
49
+ lines
50
+ end
51
+
18
52
  def prepare_line_variable(lines,definition)
19
53
  regex = /\@\(((?<bundle>[\w|\-]+)\.)?(?<name>[\w|\-]+)\)/
20
54
  if lines.kind_of?(Array)
@@ -150,16 +184,17 @@ class Compile
150
184
 
151
185
  end
152
186
 
153
- def tag_line_attributes(line)
187
+ def tag_line_attributes(line,base="")
154
188
  if line[:type] == :tag
155
189
  line[:attributes][:id] = line[:id] if line[:id].to_s.length > 0 and line[:attributes][:id].to_s.length == 0
156
190
  line[:attributes][:class] = line[:class] if line[:class].to_s.length > 0 and line[:attributes][:class].to_s.length == 0
157
191
  attributes = ""
158
- line[:attributes].each do |attribute,value|
159
- attributes += " #{attribute.to_s}=\"#{value.to_s}\"" if(value.to_s.length) > 0 and value.to_s != 'nil'
160
- attributes += " #{attribute.to_s}" if(value.to_s) == "nil"
192
+ line[:attributes].each do |key,value|
193
+ attributes << " #{key.to_s}=\"#{value.to_s}\"" if(value.to_s.length) > 0 and value.to_s != 'nil'
194
+ attributes << " #{key.to_s}" if(value.to_s) == "nil"
161
195
  end
162
196
  attributes
163
197
  end
164
198
  end
199
+
165
200
  end
@@ -1,3 +1,13 @@
1
+ class DefinitionVariable
2
+ @variable = {}
3
+ def initialize(variable)
4
+ @variable = variable
5
+ end
6
+ def variable(name,line,bundle=false)
7
+ @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))
8
+ end
9
+ end
10
+
1
11
  class Definition
2
12
  def initialize(parse,scope=false,add_bundle=true,add_mixin=true,add_variable=true)
3
13
  @bundle = {}
data/lib/aml/parse.rb CHANGED
@@ -5,7 +5,7 @@ class Parse
5
5
  def watch
6
6
  return @watch
7
7
  end
8
- def initialize(path, file)
8
+ def initialize(path, file, partial=false, bundle=false)
9
9
  @path = path
10
10
  @regex = {
11
11
  :attribute => /@\(\:(?<name>[\w|\-]+)\)/,
@@ -26,9 +26,9 @@ class Parse
26
26
  }
27
27
  @file = {}
28
28
  @watch = []
29
- read(file, false)
29
+ read(file, partial, bundle)
30
30
  end
31
- def read(file, partial)
31
+ def read(file, partial, bundle)
32
32
  line_number = 0
33
33
  line_struct = []
34
34
  File.open(File.join(@path,file)).read.gsub(@regex[:comment],'').each_line do |line|
@@ -50,6 +50,8 @@ class Parse
50
50
  struct[:bundle] = false if struct[:bundle].to_s.length == 0
51
51
  #set undefined method bundle
52
52
  struct[:bundle] = 'core' if struct[:type] == :method and !struct[:bundle]
53
+
54
+ struct[:bundle] = bundle if bundle != false
53
55
  struct[:id] = struct[:id_first].to_s.length > 0 ? struct[:id_first] : struct[:id_last]
54
56
  struct.delete(:id_first)
55
57
  struct.delete(:id_last)
@@ -1,3 +1,4 @@
1
+ #require "awesome_print"
1
2
  require 'aml/error'
2
3
  require 'aml/argument'
3
4
  require 'aml/line_type'
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.0.4
4
+ version: 0.0.5
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-07 00:00:00.000000000 Z
11
+ date: 2013-12-10 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.