papercraft 0.26 → 0.27
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/papercraft/html.rb +15 -0
- data/lib/papercraft/tags.rb +43 -3
- data/lib/papercraft/version.rb +1 -1
- data/lib/papercraft/xml.rb +9 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd2f4f4d1ebc2cfc5718079d68c9393b3d95def9c02b057107425ddd5b45eaf3
|
4
|
+
data.tar.gz: f3f82f29227e22e5e31b0d685bcab211ebbef0ecf8a4433d251cb1f204875cf7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7389861bea04a92e06ce1a53a682ef3b4db1bf975bb7f5e63cef0ed6c1a4ebb4b92920a0bb4ea04eba24dc72b41c70ba8fac0d8aa605a2b5a720d7860198b7e0
|
7
|
+
data.tar.gz: 2a617260deef291c56cd0c3fc1b275d47dd1dc95bdeeafc69289d630260480e49126c29f0ec77c177fd6c1032c633ba2568be1ffb767e13f91e51b5a9c298831
|
data/CHANGELOG.md
CHANGED
data/lib/papercraft/html.rb
CHANGED
@@ -88,6 +88,21 @@ module Papercraft
|
|
88
88
|
|
89
89
|
private
|
90
90
|
|
91
|
+
# Returns true if the given tag is a void element, in order to render a self
|
92
|
+
# closing tag. See spec: https://html.spec.whatwg.org/multipage/syntax.html#void-elements.
|
93
|
+
#
|
94
|
+
# @param text [String] tag
|
95
|
+
# @return [Bool] is it a void element
|
96
|
+
def is_void_element_tag?(tag)
|
97
|
+
case tag
|
98
|
+
#
|
99
|
+
when 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'source', 'track', 'wbr'
|
100
|
+
true
|
101
|
+
else
|
102
|
+
false
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
91
106
|
# Escapes the given text using HTML entities.
|
92
107
|
#
|
93
108
|
# @param text [String] text
|
data/lib/papercraft/tags.rb
CHANGED
@@ -10,6 +10,7 @@ module Papercraft
|
|
10
10
|
S_LT_SLASH = '</'
|
11
11
|
S_SPACE_LT_SLASH = ' </'
|
12
12
|
S_SLASH_GT = '/>'
|
13
|
+
S_GT_LT_SLASH = '></'
|
13
14
|
S_SPACE = ' '
|
14
15
|
S_EQUAL_QUOTE = '="'
|
15
16
|
S_QUOTE = '"'
|
@@ -21,6 +22,36 @@ module Papercraft
|
|
21
22
|
S_TAG_%<TAG>s_PRE = %<tag_pre>s
|
22
23
|
S_TAG_%<TAG>s_CLOSE = %<tag_close>s
|
23
24
|
|
25
|
+
def %<tag>s(text = nil, **props, &block)
|
26
|
+
if text.is_a?(Hash) && props.empty?
|
27
|
+
props = text
|
28
|
+
text = nil
|
29
|
+
end
|
30
|
+
|
31
|
+
@buffer << S_TAG_%<TAG>s_PRE
|
32
|
+
emit_props(props) unless props.empty?
|
33
|
+
|
34
|
+
if block
|
35
|
+
@buffer << S_GT
|
36
|
+
instance_eval(&block)
|
37
|
+
@buffer << S_TAG_%<TAG>s_CLOSE
|
38
|
+
elsif Proc === text
|
39
|
+
@buffer << S_GT
|
40
|
+
emit(text)
|
41
|
+
@buffer << S_TAG_%<TAG>s_CLOSE
|
42
|
+
elsif text
|
43
|
+
@buffer << S_GT << escape_text(text.to_s) << S_TAG_%<TAG>s_CLOSE
|
44
|
+
else
|
45
|
+
@buffer << S_GT << S_TAG_%<TAG>s_CLOSE
|
46
|
+
end
|
47
|
+
end
|
48
|
+
EOF
|
49
|
+
|
50
|
+
S_VOID_TAG_METHOD_LINE = __LINE__ + 2
|
51
|
+
S_VOID_TAG_METHOD = <<~EOF
|
52
|
+
S_TAG_%<TAG>s_PRE = %<tag_pre>s
|
53
|
+
S_TAG_%<TAG>s_CLOSE = %<tag_close>s
|
54
|
+
|
24
55
|
def %<tag>s(text = nil, **props, &block)
|
25
56
|
if text.is_a?(Hash) && props.empty?
|
26
57
|
props = text
|
@@ -149,8 +180,10 @@ module Papercraft
|
|
149
180
|
@buffer << S_LT_SLASH << tag << S_GT
|
150
181
|
elsif text
|
151
182
|
@buffer << S_GT << escape_text(text.to_s) << S_LT_SLASH << tag << S_GT
|
152
|
-
|
183
|
+
elsif is_void_element_tag?(sym)
|
153
184
|
@buffer << S_SLASH_GT
|
185
|
+
else
|
186
|
+
@buffer << S_GT_LT_SLASH << tag << S_GT
|
154
187
|
end
|
155
188
|
end
|
156
189
|
|
@@ -262,13 +295,20 @@ module Papercraft
|
|
262
295
|
# @return [void]
|
263
296
|
def define_tag_method(tag)
|
264
297
|
repr = tag_repr(tag)
|
265
|
-
|
298
|
+
if is_void_element_tag?(tag)
|
299
|
+
tmpl = S_VOID_TAG_METHOD
|
300
|
+
line = S_VOID_TAG_METHOD_LINE
|
301
|
+
else
|
302
|
+
tmpl = S_TAG_METHOD
|
303
|
+
line = S_TAG_METHOD_LINE
|
304
|
+
end
|
305
|
+
code = tmpl % {
|
266
306
|
tag: tag,
|
267
307
|
TAG: tag.upcase,
|
268
308
|
tag_pre: "<#{repr}".inspect,
|
269
309
|
tag_close: "</#{repr}>".inspect
|
270
310
|
}
|
271
|
-
self.class.class_eval(code, __FILE__,
|
311
|
+
self.class.class_eval(code, __FILE__, line)
|
272
312
|
end
|
273
313
|
|
274
314
|
# Defines a namespace referring to the given module.
|
data/lib/papercraft/version.rb
CHANGED
data/lib/papercraft/xml.rb
CHANGED
@@ -10,7 +10,15 @@ module Papercraft
|
|
10
10
|
|
11
11
|
private
|
12
12
|
|
13
|
-
#
|
13
|
+
# Returns false (no void elements in XML)
|
14
|
+
#
|
15
|
+
# @param tag [String] tag
|
16
|
+
# @return [false] false
|
17
|
+
def is_void_element_tag?(tag)
|
18
|
+
false
|
19
|
+
end
|
20
|
+
|
21
|
+
# Converts a tag to its string representation. Underscores will be converted
|
14
22
|
# to dashes, double underscores will be converted to colon.
|
15
23
|
#
|
16
24
|
# @param tag [Symbol, String] tag
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: papercraft
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.27'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sharon Rosner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-01-
|
11
|
+
date: 2023-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: escape_utils
|