html_slice 0.2.2 → 0.2.3
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/lib/html_slice/version.rb +1 -1
- data/lib/html_slice.rb +22 -23
- 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: 3242d22727eedd059279b0878df7f1d902005f496913cfcbb23597bd7188ab7e
|
4
|
+
data.tar.gz: c68fbc9a261302737414dc60ab047ebf4a5a71f53b3ef0c7528504f6439ff61c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f2ebbe290eab9076541761dfd02f93397d975ac8d5a832a2f91d8f1743a837bec8e52402da56768cea7597e3b9c0acc1172ce4c291ca7e5f90c2baa85163a3d
|
7
|
+
data.tar.gz: 339156f66b60557116b897f98d4ba5e9388e32abcc754ad7e209b96db8f85d20cf03eed9fedf79d27903c509583bb472bbafe34a1bbe5450b95d28a96dbb4750
|
data/lib/html_slice/version.rb
CHANGED
data/lib/html_slice.rb
CHANGED
@@ -14,11 +14,11 @@ module HtmlSlice
|
|
14
14
|
|
15
15
|
EMPTY_TAGS = %i[
|
16
16
|
area br embed hr img input link meta source
|
17
|
-
].freeze
|
17
|
+
].to_set.freeze
|
18
18
|
|
19
19
|
TAGS_WITHOUT_HTML_ESCAPE = %i[
|
20
20
|
style script
|
21
|
-
].freeze
|
21
|
+
].to_set.freeze
|
22
22
|
|
23
23
|
DEFAULT_SLICE = :default
|
24
24
|
|
@@ -35,12 +35,14 @@ module HtmlSlice
|
|
35
35
|
@html_slice ||= {}
|
36
36
|
|
37
37
|
if block
|
38
|
-
|
38
|
+
buffer = String.new
|
39
|
+
buffer << wrap[0]
|
40
|
+
@html_slice[@html_slice_current_id] = buffer
|
39
41
|
instance_eval(&block)
|
40
|
-
|
42
|
+
buffer << wrap[1]
|
41
43
|
end
|
42
44
|
|
43
|
-
@html_slice[@html_slice_current_id] || ""
|
45
|
+
(@html_slice[@html_slice_current_id] || "").to_s
|
44
46
|
end
|
45
47
|
|
46
48
|
TAGS.each do |name|
|
@@ -69,16 +71,16 @@ module HtmlSlice
|
|
69
71
|
def ensure_html_slice
|
70
72
|
@html_slice ||= {}
|
71
73
|
@html_slice_current_id ||= DEFAULT_SLICE
|
72
|
-
@html_slice[@html_slice_current_id] ||=
|
74
|
+
@html_slice[@html_slice_current_id] ||= String.new
|
73
75
|
end
|
74
76
|
|
75
77
|
def parse_html_tag_arguments(args, escape: true)
|
76
|
-
content =
|
78
|
+
content = ""
|
77
79
|
attributes = {}
|
78
80
|
|
79
81
|
first = args.shift
|
80
82
|
if first.is_a?(String)
|
81
|
-
content = escape ? CGI.escapeHTML(first) : first
|
83
|
+
content = escape && !first.empty? ? CGI.escapeHTML(first) : first
|
82
84
|
attributes = args.pop || {}
|
83
85
|
elsif first.is_a?(Hash)
|
84
86
|
attributes = first
|
@@ -89,26 +91,23 @@ module HtmlSlice
|
|
89
91
|
|
90
92
|
def generate_and_append_html_tag(tag_name, content, attributes, &block)
|
91
93
|
ensure_html_slice
|
92
|
-
|
94
|
+
buffer = @html_slice[@html_slice_current_id]
|
95
|
+
buffer << "<" << tag_name.to_s
|
96
|
+
|
97
|
+
unless attributes.empty?
|
98
|
+
attributes.each do |key, value|
|
99
|
+
buffer << " " << key.to_s.tr("_", "-") << "='" << value.to_s << "'"
|
100
|
+
end
|
101
|
+
end
|
93
102
|
|
94
103
|
if block
|
95
|
-
|
104
|
+
buffer << ">"
|
96
105
|
instance_eval(&block)
|
97
|
-
|
106
|
+
buffer << "</" << tag_name.to_s << ">"
|
98
107
|
elsif content.empty? && EMPTY_TAGS.include?(tag_name)
|
99
|
-
|
108
|
+
buffer << "/>"
|
100
109
|
else
|
101
|
-
|
110
|
+
buffer << ">" << content << "</" << tag_name.to_s << ">"
|
102
111
|
end
|
103
112
|
end
|
104
|
-
|
105
|
-
def build_html_open_tag(tag_name, attributes)
|
106
|
-
return "<#{tag_name}" if attributes.empty?
|
107
|
-
|
108
|
-
attr_string = attributes.map do |key, value|
|
109
|
-
" #{key.to_s.tr("_", "-")}='#{value}'"
|
110
|
-
end.join
|
111
|
-
|
112
|
-
"<#{tag_name}#{attr_string}"
|
113
|
-
end
|
114
113
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: html_slice
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- henrique-ft
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-04-
|
10
|
+
date: 2025-04-21 00:00:00.000000000 Z
|
11
11
|
dependencies: []
|
12
12
|
description: Enable Ruby classes the ability to generate reusable pieces of html
|
13
13
|
email:
|