hiccdown 1.3.0 → 1.4.0

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hiccdown.rb +21 -3
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e16c613ff62cbd88fb53d8c57c4f9e4a89a06f498e8344fe67f6da3f82ada33
4
- data.tar.gz: 0f32c9b93fde68cf68544fb10a0b1285c0799779245af8b2d91efc066342a248
3
+ metadata.gz: 02ff5c55e4f14971f81caa18567805139f1df00eee7155cb35ec1228660e213d
4
+ data.tar.gz: b45937dd5027f36cdd1f54fb7b1aa0f59dbc653baf2dec2119802943ef0cde72
5
5
  SHA512:
6
- metadata.gz: 686df3dded370832f8d74169dd9fe54fce9ee45b8c9c30c89dd7dc8ab3d8876c9fbf205b37815ea08a133229c01fb091b26c6884126f3e52d7b0047d5b1f48d9
7
- data.tar.gz: 0eb3af3931eb0b91484ea462399702c85fbb29649e3a38a52ac3c7266e5bd2ca43e4f5328fd398fc5775dd9a4099853330f5d759321a822a5c52f9c4801d0ccf
6
+ metadata.gz: 3de2fb6ed892d6de6b4f9fa882a96b2c966f1801f9b33964e94b76d0f18db7bdc3aaeb51193ea5d0acbfbdcdb9342e0b0345c02fc845b83d8a62366f934902d3
7
+ data.tar.gz: 21a036a8cd1511b53dddc430fcf8f8b121a2335a648d8ae1dae8ecc6758b798c8a6054791078cf9c3748da15be63a1070aa4912fa0fed614b19ecd33343914d1
data/lib/hiccdown.rb CHANGED
@@ -39,11 +39,29 @@ module Hiccdown
39
39
  Set.new([:area, :base, :br, :col, :command, :embed, :hr, :img, :input, :keygen, :link, :menuitem, :meta, :param, :source, :track, :wbr])
40
40
  end
41
41
 
42
+ def self.process_hash(hash, prefix = nil, escape)
43
+ hash.flat_map do |key, value|
44
+ attribute_key = prefix ? "#{prefix}-#{key}" : key.to_s
45
+
46
+ if value.is_a?(Hash)
47
+ process_hash(value, attribute_key, escape)
48
+ elsif value.is_a?(Array)
49
+ value_str = value.map { |v| maybe_escape(v.to_s, escape) }.join(' ')
50
+ ["#{attribute_key}=\"#{value_str}\""]
51
+ else
52
+ value_str = maybe_escape(value.to_s, escape)
53
+ ["#{attribute_key}=\"#{value_str}\""]
54
+ end
55
+ end
56
+ end
57
+
58
+ def self.hash_to_html_attributes(hash, escape)
59
+ process_hash(hash, nil, escape).join(' ')
60
+ end
61
+
42
62
  def self.to_html structure, escape = true
43
63
  if structure.is_a? Hash
44
- structure.reduce([]) do |acc, (key, val)|
45
- acc + [[key.to_s, '="', self.maybe_escape(val.to_s, escape), '"'].join]
46
- end.join(' ')
64
+ self.hash_to_html_attributes(structure, escape)
47
65
  elsif structure.is_a? Array
48
66
  if structure.first.is_a?(Array)
49
67
  return structure.map { |s| to_html(s, escape) }.join
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiccdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dennis Hackethal