hlt 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/lib/hlt.rb +41 -14
  5. metadata +1 -1
  6. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bb7466834814fe0e00f3272371a1d407b9fb73f2
4
- data.tar.gz: 54fdb09907aff7bbf5910f2a075cd9a0632d54a6
3
+ metadata.gz: ecdfac33c7dda8c7efc1d37f99ec0ce904b2c2a9
4
+ data.tar.gz: a31cf0421054fbeaa6548211e8d6d31610928b49
5
5
  SHA512:
6
- metadata.gz: 56ce1329ecd686e7168734f70858eeabfd1c7813a68c8400cfeb1a3f90d622b7f52f7cd64ed14c58e8fbbea596db3ba29f6c79b7cce48143f8dd0a8c04940657
7
- data.tar.gz: 64579a2a9adebd0211907ab930da944bf74f815887645b5b3c8f142abd7ab312951590a1b02a2092f66434d06c2a6c226bccf0706a48cdbe6ee8c72fa518c914
6
+ metadata.gz: 4fd9248c8e7d6577b67f1ecac69d5b82149fde2e54b7213fd2db194b07ecf51816cd2b76704ad2b4a2d91d7fc9b1eef0d748adfbcad7c4827aed4bbcfba1d173
7
+ data.tar.gz: c44ee8b315879205696319316548c441d8d61d183f7f1e52b0367984f6c897fa54d9e233a31fe98847a445de16f0a11ca161e97238b7b310bf149fb17190d19d
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/hlt.rb CHANGED
@@ -105,14 +105,19 @@ class Hlt
105
105
 
106
106
  end
107
107
 
108
- def render()
109
-
108
+ def render(locals: {})
109
+
110
+ variables = locals.map do |key, value|
111
+ "#{key} = locals['#{key}']"
112
+ end
113
+
110
114
  s = "xml = RexleBuilder.new\n"
111
115
  s << scanbuild(@doc.to_a)
112
- a = eval s
116
+
117
+ a = eval variables.join("\n") + "\n" + s
113
118
 
114
119
  Rexle.new(a).element('root/.').xml pretty: true
115
-
120
+
116
121
  end
117
122
 
118
123
  def to_doc()
@@ -223,37 +228,59 @@ class Hlt
223
228
  %w{ th st nd rd th th th th th th }[n % 10] )
224
229
  end
225
230
 
226
- # under development 04-Nov-2015
227
231
 
232
+ def v(x)
233
+
234
+ if x then
235
+ var = x[/^=\s+(.*)/,1]
236
+ var ? var : x.inspect
237
+ end
238
+
239
+ end
240
+
228
241
  def scanbuild(x, indent=0)
229
242
 
230
243
  name, attributes, *remaining = x
231
-
244
+
232
245
  children = remaining.shift
233
246
  text = ''
234
247
 
235
248
 
236
249
  if children.is_a? Array then
237
250
  nested = scanbuild(children, indent+1)
238
- else
251
+ elsif children
239
252
  text = children
240
253
  end
241
254
 
242
255
  pad = ' ' * indent
243
-
256
+
257
+
244
258
  s2 = if children.is_a? Array then
245
- "%sxml.%s(%s,%s) do\n%s" % [pad, name, attributes.to_s, text.inspect, nested]
259
+ if name == 'templatecode' then
260
+ "%s%s" % [pad, text]
261
+ else
262
+ "%sxml.%s(%s,%s) do\n%s" % \
263
+ [pad, name, attributes.to_s, v(text), nested]
264
+ end
246
265
  else
247
- ' ' * indent + "xml.%s(%s,%s)" % [name, attributes.to_s, text.inspect]
266
+ if name == 'templatecode' then
267
+ "%s%s" % [pad, text]
268
+ else
269
+ ' ' * indent + "xml.%s(%s,%s)" % [name, attributes.to_s, v(text)]
270
+ end
248
271
  end
249
272
 
250
- if remaining.any? and remaining[0].is_a? Array then
251
- s2 << "\n" + scanbuild(remaining[0], indent+1)
273
+ while remaining.any? do
274
+ children = remaining.shift
275
+ if children and children.is_a? Array then
276
+ s2 << "\n" + scanbuild(children, indent+1)
277
+ end
252
278
  end
253
279
 
254
- s2 << "\n%send" % [pad] if children.is_a?(Array)
280
+ s2 << "\n%send" % [pad] if children.is_a?(Array) or name == 'templatecode'
255
281
 
256
282
  s2
257
283
  end
258
284
 
259
- end
285
+
286
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hlt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file