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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 677ccd64e0e49f6488478cf3f432fa19a52d39b053310f8ff8fc95f0e838d664
4
- data.tar.gz: dae8024850dde1d0ebe919496d163975aa7b94421eb7731df7ddcc7f8acd529e
3
+ metadata.gz: 3242d22727eedd059279b0878df7f1d902005f496913cfcbb23597bd7188ab7e
4
+ data.tar.gz: c68fbc9a261302737414dc60ab047ebf4a5a71f53b3ef0c7528504f6439ff61c
5
5
  SHA512:
6
- metadata.gz: bfd1dbadb0fccfbb128659a3d55ea489c15a26dd1721dbb864c0799af4ade39aaa2ff304cac374ec287bed53fc06fdc765af2309830cc7d4cdc1c8badcfd1a6f
7
- data.tar.gz: fd182ec12728971df04a0f5853faac255bbadba9f302640fe1aa1b4de86282b7454f05a2b4d2e0f14f7c1dfd8550fdd2217e9ce83e289078fcdef27ad3f44e5d
6
+ metadata.gz: 7f2ebbe290eab9076541761dfd02f93397d975ac8d5a832a2f91d8f1743a837bec8e52402da56768cea7597e3b9c0acc1172ce4c291ca7e5f90c2baa85163a3d
7
+ data.tar.gz: 339156f66b60557116b897f98d4ba5e9388e32abcc754ad7e209b96db8f85d20cf03eed9fedf79d27903c509583bb472bbafe34a1bbe5450b95d28a96dbb4750
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HtmlSlice
4
- VERSION = "0.2.2"
4
+ VERSION = "0.2.3"
5
5
  end
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
- @html_slice[@html_slice_current_id] = wrap[0].dup
38
+ buffer = String.new
39
+ buffer << wrap[0]
40
+ @html_slice[@html_slice_current_id] = buffer
39
41
  instance_eval(&block)
40
- @html_slice[@html_slice_current_id] << wrap[1]
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
- open_tag = build_html_open_tag(tag_name, attributes)
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
- @html_slice[@html_slice_current_id] << open_tag << ">"
104
+ buffer << ">"
96
105
  instance_eval(&block)
97
- @html_slice[@html_slice_current_id] << "</#{tag_name}>"
106
+ buffer << "</" << tag_name.to_s << ">"
98
107
  elsif content.empty? && EMPTY_TAGS.include?(tag_name)
99
- @html_slice[@html_slice_current_id] << open_tag << "/>"
108
+ buffer << "/>"
100
109
  else
101
- @html_slice[@html_slice_current_id] << open_tag << ">" << content << "</#{tag_name}>"
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.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-06 00:00:00.000000000 Z
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: