hlt 0.6.1 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data/lib/hlt.rb +79 -68
- data.tar.gz.sig +0 -0
- metadata +32 -68
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 48ef4fe61faa5abb7df415fe54610141405c880325c0ab12e63cdf0d5d82887b
|
4
|
+
data.tar.gz: 27b5664cc8436b75db26e926c626e3da1c9727346e73e3cf9d8e6bc56c482ffe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ceb3873c51582d0b17bd87dbeaa0059ccb7659dc1c0d843690e52937c348d095fcc926363dcedebcb217e9b6b1446db9a513a2ff2af02bbde3ed17ca4dabe4a
|
7
|
+
data.tar.gz: 2a05a52b8e1b4be7108595396f5719824f9263bfbdda48c8a50cfe1a18b74610a1405e9059acc296fdd71e3e60702ce710f1b62e8e9806f453c61c5ae38fb501
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/hlt.rb
CHANGED
@@ -2,43 +2,48 @@
|
|
2
2
|
|
3
3
|
# file: hlt.rb
|
4
4
|
|
5
|
+
|
5
6
|
require 'martile'
|
6
|
-
require 'line-tree'
|
7
7
|
require 'rexle-builder'
|
8
8
|
|
9
9
|
|
10
10
|
class Hlt
|
11
|
+
using ColouredText
|
11
12
|
|
12
13
|
attr_reader :to_html, :to_doc
|
13
14
|
|
14
|
-
def initialize(raw_s, pretty: true, declaration: true, style: true,
|
15
|
-
debug: false)
|
16
|
-
|
17
|
-
|
15
|
+
def initialize(raw_s, pretty: true, declaration: true, style: true,
|
16
|
+
nocomment: true, debug: false)
|
17
|
+
|
18
|
+
|
19
|
+
@debug = debug
|
18
20
|
# strip out lines which are blank or only contain a comment
|
19
21
|
#s = raw_s.lines.to_a.reject!{|x| x[/(^\s+\#\s)|(^\s*$)/] }
|
20
|
-
|
22
|
+
|
21
23
|
raw_s.strip!
|
22
|
-
|
24
|
+
|
23
25
|
s2, martile = fetch_martile raw_s
|
26
|
+
puts 'martile: ' + martile.inspect if @debug
|
24
27
|
s, xml_list = filter_xml(s2)
|
25
28
|
|
26
29
|
#s = raw_s
|
27
30
|
# strip out the text from the line containing a comment
|
28
31
|
s.gsub!(/((^#\s|\s#\s).*)/,'').strip if s[/((^#\s|\s#\s).*)/]
|
29
|
-
|
30
|
-
s.
|
32
|
+
puts ('s: ' + s.inspect).debug if @debug
|
33
|
+
a_code = s.scan(/^\[([^\]]+)\]\B/).map(&:first)
|
34
|
+
puts ('a_code: ' + a_code.inspect).debug if @debug
|
35
|
+
s.gsub!(/\n\[[^\]]+\]\B/, " !CODE\n")
|
31
36
|
|
32
|
-
s2 = s.lines.to_a.map!{|line|
|
37
|
+
s2 = s.lines.to_a.map!{|line|
|
33
38
|
|
34
39
|
hash = "(\s*\{[^\}]+\})?"
|
35
|
-
|
40
|
+
|
36
41
|
line.prepend ' '
|
37
42
|
|
38
43
|
line.sub!(/^(\s*)\w+: /,'\0' + "\n" + '\1')
|
39
|
-
|
40
|
-
r = line.sub(/^\s*(\w+)?(?:[\.#]\w+){1,}#{hash}/) do |x|
|
41
|
-
|
44
|
+
|
45
|
+
r = line.sub(/^\s*(\w+)?(?:[\.#]\w+){1,}#{hash}/) do |x|
|
46
|
+
|
42
47
|
raw_attrs = x.slice!(/\{.*\}/)
|
43
48
|
attrs = raw_attrs[1..-2] if raw_attrs
|
44
49
|
|
@@ -46,7 +51,7 @@ class Hlt
|
|
46
51
|
tag = x[/(^\s*\w*)[#\.]/,1] || 'div'
|
47
52
|
tag += 'div' if tag.strip.empty?
|
48
53
|
|
49
|
-
x.sub(/(?:\.\w+){1,}/) do |x2|
|
54
|
+
x.sub(/(?:\.\w+){1,}/) do |x2|
|
50
55
|
a = x2[/(?:\.\w+){1,}/].split('.')
|
51
56
|
a.shift
|
52
57
|
a2 << "class: '%s'" % a.join(' ')
|
@@ -61,65 +66,71 @@ class Hlt
|
|
61
66
|
|
62
67
|
r
|
63
68
|
}
|
64
|
-
|
69
|
+
|
65
70
|
s2.unshift "root\n"
|
66
71
|
s3 = s2.join.gsub(/^(\s*)-\s+/,'\1templatecode ').\
|
67
72
|
gsub(/^(\s*)=\s+/,'\1templateoutput ')
|
68
73
|
|
69
|
-
|
74
|
+
puts ('s3: ' + s3.inspect).debug if @debug
|
70
75
|
|
71
|
-
|
76
|
+
raw_html = LineTree.new(*s3, ignore_non_element: false, debug: debug).to_xml
|
77
|
+
puts ('raw_html: ' + raw_html.inspect).debug if @debug
|
78
|
+
|
79
|
+
html = raw_html.gsub('!CODE').with_index do |x,i|
|
72
80
|
"\n\n" + a_code[i].lines.map{|x| ' ' * 4 + x}.join + "\n"
|
73
81
|
end
|
74
82
|
|
75
83
|
martile.each.with_index do |x,i|
|
76
|
-
|
84
|
+
|
77
85
|
if @debug then
|
78
|
-
puts 'i: ' + i.inspect
|
79
|
-
puts 'x: ' + x.inspect
|
80
|
-
puts 'html: ' + html.inspect
|
86
|
+
puts ('i: ' + i.inspect).debug
|
87
|
+
puts ('x: ' + x.inspect).debug
|
88
|
+
puts ('html: ' + html.inspect).debug
|
81
89
|
end
|
82
|
-
|
90
|
+
|
83
91
|
html.sub!(/<mar(tile|kdown):#{i.to_s}\/>/, RDiscount.new(\
|
84
92
|
Martile.new(x).to_s).to_html\
|
85
93
|
.gsub(/<(\w+)>\s*{style:\s*['"]([^'"]+)[^\}]+\}/,\
|
86
94
|
'<\1 style=\'\2\'>'))
|
87
95
|
end
|
88
|
-
|
89
|
-
puts 'html_: ' + html.inspect if @debug
|
90
|
-
|
96
|
+
|
97
|
+
puts ('html_: ' + html.inspect).debug if @debug
|
98
|
+
|
91
99
|
doc = Rexle.new(html)
|
92
|
-
|
100
|
+
|
93
101
|
xml_list.each.with_index do |xml,i|
|
94
102
|
e = doc.root.element('//xml:' + i.to_s)
|
95
103
|
e.insert_before Rexle.new(xml).root
|
96
104
|
e.delete
|
97
105
|
end
|
98
|
-
|
106
|
+
|
99
107
|
# remove the style attributes from the document if style == false
|
100
108
|
#
|
101
109
|
if style == false then
|
102
|
-
doc.root.xpath('//.[@style]').each do |e|
|
110
|
+
doc.root.xpath('//.[@style]').each do |e|
|
103
111
|
unless e.attributes[:style][/^clear:/] then
|
104
|
-
e.attributes.delete :style
|
112
|
+
e.attributes.delete :style
|
105
113
|
end
|
106
114
|
end
|
107
|
-
end
|
108
|
-
|
109
|
-
|
115
|
+
end
|
116
|
+
|
117
|
+
|
110
118
|
@doc = doc
|
111
119
|
h = {declaration: declaration, pretty: pretty, style: style}
|
112
120
|
html = doc.root.xpath('*'){|x| x.xml(h)}.join("\n")
|
113
|
-
|
121
|
+
|
114
122
|
time = Time.now
|
115
123
|
timestamp = time.strftime("#{ordinalize(time.day)} %B %Y @ %H:%M")
|
116
|
-
comment = "\n <!-- Generated by Hlt-site_builder on the %s -->\n" % timestamp
|
117
124
|
|
118
|
-
|
125
|
+
unless nocomment
|
126
|
+
comment = "\n <!-- Generated by Hlt-site_builder on the %s -->\n" % timestamp
|
127
|
+
html.sub!(/(?=<\/html>)/, comment)
|
128
|
+
end
|
129
|
+
|
119
130
|
@to_html = html
|
120
131
|
|
121
132
|
end
|
122
|
-
|
133
|
+
|
123
134
|
def render(locals: {})
|
124
135
|
|
125
136
|
variables = locals.map do |key, value|
|
@@ -130,24 +141,24 @@ class Hlt
|
|
130
141
|
s << scanbuild(@doc.to_a)
|
131
142
|
|
132
143
|
a = eval variables.join("\n") + "\n" + s
|
133
|
-
|
144
|
+
|
134
145
|
Rexle.new(a).element('root/.')
|
135
146
|
|
136
147
|
end
|
137
|
-
|
148
|
+
|
138
149
|
def to_doc()
|
139
150
|
@doc
|
140
151
|
end
|
141
|
-
|
152
|
+
|
142
153
|
private
|
143
|
-
|
154
|
+
|
144
155
|
def filter_xml(s)
|
145
|
-
|
156
|
+
|
146
157
|
n = s =~ /</
|
147
158
|
return [s,[]] unless n
|
148
|
-
|
159
|
+
|
149
160
|
end_pos = s.length - (s =~ />[^>]+$/)
|
150
|
-
|
161
|
+
|
151
162
|
|
152
163
|
i = 0
|
153
164
|
xml = []
|
@@ -170,9 +181,9 @@ class Hlt
|
|
170
181
|
|
171
182
|
n = s =~ /</
|
172
183
|
end
|
173
|
-
|
184
|
+
|
174
185
|
[s, xml]
|
175
|
-
|
186
|
+
|
176
187
|
end
|
177
188
|
|
178
189
|
def fetch_martile(raw_s)
|
@@ -192,13 +203,13 @@ class Hlt
|
|
192
203
|
martile = []
|
193
204
|
|
194
205
|
s2 = s.lines.map do |line|
|
195
|
-
|
196
|
-
puts 'line: ' + line.inspect if @debug
|
197
|
-
|
206
|
+
|
207
|
+
puts ('line: ' + line.inspect).debug if @debug
|
208
|
+
|
198
209
|
if state == :martile then
|
199
|
-
|
210
|
+
|
200
211
|
spaces = line[/^\s+/].to_s.length
|
201
|
-
|
212
|
+
|
202
213
|
if spaces > md_spaces then
|
203
214
|
martile[index] << line[(md_spaces + 2)..-1]
|
204
215
|
line = ''
|
@@ -206,54 +217,54 @@ class Hlt
|
|
206
217
|
martile[index].strip!
|
207
218
|
index += 1
|
208
219
|
state = :default
|
209
|
-
|
220
|
+
|
210
221
|
r = line[/^(\s+)martile:/,1]
|
211
222
|
|
212
|
-
if r then
|
223
|
+
if r then
|
213
224
|
|
214
|
-
state = :martile
|
215
|
-
md_spaces = r.length
|
225
|
+
state = :martile
|
226
|
+
md_spaces = r.length
|
216
227
|
|
217
228
|
line.sub!(/mar(kdown|tile):/,'\0' + index.to_s)
|
218
229
|
martile[index] = ''
|
219
230
|
end
|
220
|
-
end
|
231
|
+
end
|
221
232
|
|
222
233
|
else
|
223
234
|
|
224
235
|
r = line[/^(\s+)mar(kdown|tile):/,1]
|
225
236
|
|
226
|
-
if r then
|
237
|
+
if r then
|
227
238
|
|
228
|
-
state = :martile
|
229
|
-
md_spaces = r.length
|
239
|
+
state = :martile
|
240
|
+
md_spaces = r.length
|
230
241
|
line.sub!(/mar(kdown|tile):/,'\0' + index.to_s)
|
231
242
|
|
232
243
|
martile[index] = ''
|
233
244
|
end
|
234
245
|
end
|
235
246
|
|
236
|
-
puts 'line: ' + line.inspect
|
247
|
+
puts ('line: ' + line.inspect).debug if @debug
|
237
248
|
line
|
238
249
|
|
239
250
|
end
|
240
251
|
|
241
252
|
[s2.join, martile]
|
242
253
|
end
|
243
|
-
|
254
|
+
|
244
255
|
def ordinalize(n)
|
245
|
-
n.to_s + ( (10...20).include?(n) ? 'th' :
|
256
|
+
n.to_s + ( (10...20).include?(n) ? 'th' :
|
246
257
|
%w{ th st nd rd th th th th th th }[n % 10] )
|
247
258
|
end
|
248
|
-
|
249
|
-
|
259
|
+
|
260
|
+
|
250
261
|
def v(x)
|
251
262
|
|
252
263
|
if x then
|
253
264
|
var = x[/^=\s+(.*)/,1]
|
254
265
|
var ? var : x.inspect
|
255
266
|
end
|
256
|
-
|
267
|
+
|
257
268
|
end
|
258
269
|
|
259
270
|
def scanbuild(x, indent=0)
|
@@ -263,9 +274,9 @@ class Hlt
|
|
263
274
|
children = remaining.shift
|
264
275
|
text = ''
|
265
276
|
|
266
|
-
|
277
|
+
|
267
278
|
if children.is_a? Array then
|
268
|
-
nested = scanbuild(children, indent+1)
|
279
|
+
nested = scanbuild(children, indent+1)
|
269
280
|
elsif children
|
270
281
|
text = children
|
271
282
|
end
|
@@ -291,7 +302,7 @@ class Hlt
|
|
291
302
|
while remaining.any? do
|
292
303
|
children = remaining.shift
|
293
304
|
if children and children.is_a? Array then
|
294
|
-
s2 << "\n" + scanbuild(children, indent+1)
|
305
|
+
s2 << "\n" + scanbuild(children, indent+1)
|
295
306
|
end
|
296
307
|
end
|
297
308
|
|
data.tar.gz.sig
CHANGED
Binary file
|
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.6.
|
4
|
+
version: 0.6.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -10,90 +10,55 @@ bindir: bin
|
|
10
10
|
cert_chain:
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
13
|
+
MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
|
14
|
+
YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMjIwNDA2MTUyODQ3WhcN
|
15
|
+
MjMwNDA2MTUyODQ3WjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
|
16
|
+
cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQCk7o70
|
17
|
+
ZqZrzvVBcLuB90CxEk97gJh05MkB0Xg9yB8oJquZSV18OQa+FHJGM8hQ4qvzH/R/
|
18
|
+
sbRLA2z3qqRTHJ/nDlioEJj8j1a3M+ewYmBpeBl2i5qq1PJQPLHtXDjezEv8hKFF
|
19
|
+
/xFqXJlQADr9DpAtYif/SFHQasMZvBbxlCBzNKD6sTBFTKsXPKDoQYwjT8JJf4ID
|
20
|
+
vBeHs3RIG/puUa46g3Rng/P1s0/dL9wJdvJKHbm8Zv/3XkCk2IMcpCdmEz8kDzDn
|
21
|
+
Xit4kK8IegvjmmV33uazZWHYiAU9FyI3PYGU2tKE2IDgAGYCTTDgbZ88bmMaCjIC
|
22
|
+
NYWm3bXOiE3LlOBxzT4bCexiJQL7B+MQN2t5X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00.000000000 Z
|
34
39
|
dependencies:
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: line-tree
|
37
|
-
requirement: !ruby/object:Gem::Requirement
|
38
|
-
requirements:
|
39
|
-
- - "~>"
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
version: '0.6'
|
42
|
-
- - ">="
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
version: 0.6.4
|
45
|
-
type: :runtime
|
46
|
-
prerelease: false
|
47
|
-
version_requirements: !ruby/object:Gem::Requirement
|
48
|
-
requirements:
|
49
|
-
- - "~>"
|
50
|
-
- !ruby/object:Gem::Version
|
51
|
-
version: '0.6'
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 0.6.4
|
55
40
|
- !ruby/object:Gem::Dependency
|
56
41
|
name: martile
|
57
42
|
requirement: !ruby/object:Gem::Requirement
|
58
43
|
requirements:
|
59
44
|
- - "~>"
|
60
45
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
62
|
-
- - ">="
|
63
|
-
- !ruby/object:Gem::Version
|
64
|
-
version: 0.8.3
|
65
|
-
type: :runtime
|
66
|
-
prerelease: false
|
67
|
-
version_requirements: !ruby/object:Gem::Requirement
|
68
|
-
requirements:
|
69
|
-
- - "~>"
|
70
|
-
- !ruby/object:Gem::Version
|
71
|
-
version: '0.8'
|
72
|
-
- - ">="
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version: 0.8.3
|
75
|
-
- !ruby/object:Gem::Dependency
|
76
|
-
name: rexle-builder
|
77
|
-
requirement: !ruby/object:Gem::Requirement
|
78
|
-
requirements:
|
79
|
-
- - "~>"
|
80
|
-
- !ruby/object:Gem::Version
|
81
|
-
version: '0.3'
|
46
|
+
version: '1.5'
|
82
47
|
- - ">="
|
83
48
|
- !ruby/object:Gem::Version
|
84
|
-
version:
|
49
|
+
version: 1.5.0
|
85
50
|
type: :runtime
|
86
51
|
prerelease: false
|
87
52
|
version_requirements: !ruby/object:Gem::Requirement
|
88
53
|
requirements:
|
89
54
|
- - "~>"
|
90
55
|
- !ruby/object:Gem::Version
|
91
|
-
version: '
|
56
|
+
version: '1.5'
|
92
57
|
- - ">="
|
93
58
|
- !ruby/object:Gem::Version
|
94
|
-
version:
|
59
|
+
version: 1.5.0
|
95
60
|
description:
|
96
|
-
email:
|
61
|
+
email: digital.robertson@gmail.com
|
97
62
|
executables: []
|
98
63
|
extensions: []
|
99
64
|
extra_rdoc_files: []
|
@@ -118,8 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
83
|
- !ruby/object:Gem::Version
|
119
84
|
version: '0'
|
120
85
|
requirements: []
|
121
|
-
|
122
|
-
rubygems_version: 2.6.13
|
86
|
+
rubygems_version: 3.2.22
|
123
87
|
signing_key:
|
124
88
|
specification_version: 4
|
125
89
|
summary: Intended for building HTML from a kind of Slim template.
|
metadata.gz.sig
CHANGED
Binary file
|