aml 0.0.7 → 0.0.8

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: 5ef62531f3a8d1ffdab780f12c1da037b17dc65c
4
- data.tar.gz: 705a2d167d9afca4bc42f3867b69023688501b4e
3
+ metadata.gz: 99123f17f26debf93e4218deeaba35d2d22caeac
4
+ data.tar.gz: ef412c33d163c79d6e4a91d34563280062846a53
5
5
  SHA512:
6
- metadata.gz: c125e8e7ef2937a39422b19b2179a0b7c97d38be8d396fa8294fb8222dc655bf5dd052f918b6b54218398fb658f0ec09cec02ff7643f3d84f791977f7f79832f
7
- data.tar.gz: b4073acf76760b95276c020f6f93773b0732f9c1bc37ceb75f1ea0c3112609fe2b749c9551b058903bf97ce4e6de7774a017eef8f0f8cef0e587b5192e8370b6
6
+ metadata.gz: fc9d6ee0f6bfd5c4567f87bb58381d634bcad4057e5b494429a6d28f357f73b1ab743bba0a3d4c104bbe04818df5f79bf4ea88c1af847ae6bf2b175111a0e384
7
+ data.tar.gz: 3908079e214a5517704ac033acc20034851791cf41be7962f53c81f7b15eecdcebae7c55d78a15f0a2a4e96ae3d5c0bf5ce64c2ab2661fe60cd8adc833a2ddae
data/lib/aml-bundle.rb CHANGED
@@ -1,4 +1,3 @@
1
- require "awesome_print"
2
1
  require 'fileutils'
3
2
  require 'aml/argument'
4
3
  module AbstractMarkupLanguage
@@ -10,18 +9,13 @@ module AbstractMarkupLanguage
10
9
  #argument.create_action('update')
11
10
  #argument.create_action('delete')
12
11
 
13
-
14
-
12
+ argument.required('action','The required --generate argument has not been defined.')
15
13
  argument.required('name','The required --name argument has not been defined.')
16
14
  if argument.has_requirements?#and directory exists false?)
17
15
  basePath = File.dirname('~')
18
16
 
19
17
  argument.create_if_empty('--','bundle')
20
18
 
21
- #aml-bundle install
22
- #aml-bundle create
23
- #aml-bundle
24
-
25
19
  argument.create_if_empty('method','')
26
20
  argument.create_if_empty('mixin','')
27
21
  argument.create_if_empty('partial','')
data/lib/aml/compile.rb CHANGED
@@ -6,8 +6,17 @@ class Compile
6
6
  error.compile(parse,definition,error)
7
7
  if(error.count == 0)
8
8
  prepare_line_variable(parse.file[:line],definition)
9
+ lines = []
10
+ parse.file[:line].each do |line|
11
+ lines << post_prepare_line_variable(line)
12
+ end
13
+
14
+ parse.file[:line] = lines
15
+
9
16
  prepare_mixin_structure(parse.file[:line],definition)
10
17
  prepare_partial_structure(parse.file[:line],definition)
18
+ prepare_method_structure(parse.file[:line],definition)
19
+
11
20
  structure = prepare_structure(parse.file[:line])
12
21
  structure.each do |group|
13
22
  recursive_close(group)
@@ -16,6 +25,17 @@ class Compile
16
25
  end
17
26
  end
18
27
 
28
+ def prepare_method_structure(lines,definition)
29
+ #Placeholder
30
+ lines.each_with_index do |line,index|
31
+ if line[:type] == :method
32
+ line[:type] = :string
33
+ line[:value] = "<aml bundle=\"#{line[:bundle]}\" method=\"#{line[:name]}\" />"
34
+ end
35
+ end
36
+ lines
37
+ end
38
+
19
39
  def prepare_partial_structure(lines,definition)
20
40
  definition_partial = definition.variables.clone
21
41
  bundle = nil
@@ -57,7 +77,7 @@ class Compile
57
77
  line = line_variable_replace(line,definition)
58
78
  end
59
79
  else
60
- lines = line_variable_replace(lines,definition)
80
+ lines = line_variable_replace(lines,definition)
61
81
  end
62
82
  check = 0
63
83
  if lines.kind_of?(Array)
@@ -69,6 +89,43 @@ class Compile
69
89
  lines
70
90
  end
71
91
 
92
+ def post_prepare_line_variable(line)
93
+ types = {
94
+ :method => LineType.new(/^(\s{1,})?::((?<bundle>[\w|\-]+)\.)?(?<name>[\w|\-]+)(\{(?<attributes>.+)\})?/),
95
+ :mixin => LineType.new(/^(\s{1,})?%\(((?<bundle>[\w|\-]+)\.)?(?<name>[^~][\w|\-]+)\)(\{(?<attributes>.+)\})?[^\{]?/),
96
+ :partial => LineType.new(/^(\s{1,})?%\(\~((?<bundle>[\w|\-]+)\.)?(?<name>[\w|\-]+)\)(\{(?<attributes>.+)\}[^\{]?)?$/),
97
+ :tag => LineType.new(/^(\s{1,})?(?<!%)%(?<close>\/{0,2})?(?<name>[\w|\-]+)(\#(?<id_first>[\w|\-]+))?(?<class>(\.[\w|\-]+)?{1,})?(\#(?<id_last>[\w|\-]+))?(\{(?<attributes>.+)\})?(?<text>.+)?/)
98
+ }
99
+ if line[:type] == :string
100
+ types.each do |type, line_type|
101
+ if match = line_type.match?(line[:value])
102
+ struct = Hash[match.names.zip(match.captures)]
103
+ struct = Hash[struct.map{|(k,v)| [k.to_sym,v]}]
104
+ struct[:index] = line[:index]
105
+ struct[:number] = line[:number]
106
+ struct[:type] = type
107
+ match.names.each do |name|
108
+ struct[name.to_sym] = line_type.send(name.to_s, match)
109
+ end
110
+ if struct[:name].to_s[0,1] == '.'
111
+ #set undefined bundle
112
+ struct[:bundle] = 'core'
113
+ struct[:name] = struct[:name][1,struct[:name].length]
114
+ end
115
+ struct[:bundle] = false if struct[:bundle].to_s.length == 0
116
+ #set undefined method bundle
117
+ struct[:bundle] = 'core' if struct[:type] == :method and !struct[:bundle]
118
+ struct[:id] = struct[:id_first].to_s.length > 0 ? struct[:id_first] : struct[:id_last]
119
+ struct.delete(:id_first)
120
+ struct.delete(:id_last)
121
+ line = struct
122
+ break
123
+ end
124
+ end
125
+ end
126
+ line
127
+ end
128
+
72
129
  def line_variable_replace(line,definition)
73
130
  regex = /\@\(((?<bundle>[\w|\-]+)\.)?(?<name>[\w|\-]+)\)/
74
131
  %w"text value".each do |key|
@@ -79,10 +136,11 @@ class Compile
79
136
  end
80
137
  if line.has_key?(:attributes) and line[:attributes].count > 0
81
138
  line[:attributes].each do |k,v|
82
- 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
139
+ if v.is_a?(Hash) == false
140
+ 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
141
+ end
83
142
  end
84
143
  end
85
- line
86
144
  end
87
145
 
88
146
  def line_attribute_replace(line,default_attributes,mixin_attributes)
@@ -189,13 +247,22 @@ class Compile
189
247
  if line[:type] == :tag
190
248
  line[:attributes][:id] = line[:id] if line[:id].to_s.length > 0 and line[:attributes][:id].to_s.length == 0
191
249
  line[:attributes][:class] = line[:class] if line[:class].to_s.length > 0 and line[:attributes][:class].to_s.length == 0
192
- attributes = ""
193
- line[:attributes].each do |key,value|
194
- attributes << " #{key.to_s}=\"#{value.to_s}\"" if(value.to_s.length) > 0 and value.to_s != 'nil'
195
- attributes << " #{key.to_s}" if(value.to_s) == "nil"
196
- end
197
- attributes
250
+ attributes = hash_to_attribute_build(line[:attributes])
251
+ attributes = " #{attributes}" if(attributes.length > 0)
198
252
  end
199
253
  end
200
254
 
255
+ def hash_to_attribute_build(hash,base="")
256
+ hash = hash.sort_by{|key, value| key}
257
+ string = ""
258
+ hash.each do |key, value|
259
+ if(value.is_a?(Hash))
260
+ value.sort_by{|key, value| key}
261
+ string << "#{hash_to_attribute_build(value,"#{base}#{key}-")} "
262
+ else
263
+ string << "#{base}#{key}=\"#{value}\" "
264
+ end
265
+ end
266
+ string.strip
267
+ end
201
268
  end
@@ -64,7 +64,7 @@
64
64
  %!-- HELPERS ---%
65
65
 
66
66
  %%css(:href=>'', :media=>'screen'){
67
- %/link{:href=>'@(:href)',:media=>'@(:media)', :rel=>'stylesheet'}
67
+ %/link{:href=>'@(:href)', :media=>'@(:media)', :rel=>'stylesheet'}
68
68
  }
69
69
  %%js(:src=>''){
70
70
  %script{:type=>'text/javascript', :src=>'@(:src)'}
data/lib/aml/line_type.rb CHANGED
@@ -4,7 +4,7 @@ LineType = Struct.new(:regex) do
4
4
  end
5
5
  def attributes(match)
6
6
  begin
7
- eval("{#{match[:attributes].to_s}}")
7
+ stringHashToHash(match[:attributes])
8
8
  rescue Exception => e
9
9
  {:abstract_markup_language_exception=>true}
10
10
  end
@@ -35,4 +35,20 @@ LineType = Struct.new(:regex) do
35
35
  type = %w(tag self none)
36
36
  type[match[:close].to_s.length]
37
37
  end
38
+ def stringHashToHash(string)
39
+ hash = {}
40
+ regex = /:(?<name>\w+)\s?=>\s?(?<hash>{(.+?)?}|(?<quote>'|")(?<value>.+?)?\k<quote>)/
41
+ names = regex.names
42
+ if string != nil
43
+ string.scan(regex){|match|
44
+ thisHash = Hash[names.zip(match)]
45
+ if thisHash["value"] != nil
46
+ hash[thisHash["name"].to_sym] = thisHash["value"].to_s
47
+ else
48
+ hash[thisHash["name"].to_sym] = stringHashToHash(thisHash["hash"])
49
+ end
50
+ }
51
+ end
52
+ hash
53
+ end
38
54
  end
data/lib/aml/parse.rb CHANGED
@@ -50,7 +50,6 @@ 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
53
  struct[:bundle] = bundle if bundle != false
55
54
  struct[:id] = struct[:id_first].to_s.length > 0 ? struct[:id_first] : struct[:id_last]
56
55
  struct.delete(:id_first)
metadata CHANGED
@@ -1,18 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
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-01-13 00:00:00.000000000 Z
11
+ date: 2014-02-01 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
- email: daniel@aml-info.org
15
+ email: daniel@abstractmarkup.com
16
16
  executables:
17
17
  - aml
18
18
  - aml-bundle
@@ -34,7 +34,7 @@ files:
34
34
  - lib/aml/watch.rb
35
35
  - lib/aml/compile.rb
36
36
  - lib/aml/requirement.rb
37
- homepage: https://aml-info.org/
37
+ homepage: https://abstractmarkup.com
38
38
  licenses:
39
39
  - MIT
40
40
  metadata: {}