keynote 1.0.0 → 1.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4bb2837127985cda52b837475d149b7a0445de3d
4
- data.tar.gz: 1c76f12e8ab9ac25fbcd18183d3e5687a560faed
3
+ metadata.gz: bbd02a5e8d588001102132e7864b294e34290700
4
+ data.tar.gz: d8db8a485b076d070774031959cecbc2f0b9fb68
5
5
  SHA512:
6
- metadata.gz: a95130c4b619eefa804e6bb2df56eb1f07271a7163e63f7b635aaa518485e7dc252ef41102325b8f09f5a0c7dd21aeb62045ed579a43262843b403d188e23258
7
- data.tar.gz: 713dd5c6bbb3d69dc74e5e15360706ab61b92b81cfef00169279ddfb30dde8577ce2d7e680566d88a549d9908d65539ad57a8d1ddfff2207ae27cae37bfbe0e9
6
+ metadata.gz: 2033a7f5c59e895ac0d8f31202591f02f8d4f5f750203b940696f029968a14c0f59d0d8bba990f7f3ef95bb39358605b961326b869b074366210411ef7b80c9a
7
+ data.tar.gz: d683f2f2259fbff0ad2ab280ce5300093f25ed4e6bc68a13a5901a7d422fe0764a61dd50f6fb74de5babe3ed582772d47c224d16262218d9000f40a9506797e9
@@ -1,3 +1,8 @@
1
+ ## v1.1.0
2
+ * Rumble: Fix bug in v1.0.0 that caused an exception if the user passed a `nil`
3
+ value for an attribute.
4
+ * Rumble: Add support for `aria` attr hashes, behaving the same way as `data`.
5
+
1
6
  ## v1.0.0
2
7
  * Add support for Rails 5.1.
3
8
  * Fix all Ruby warnings generated by Keynote itself.
@@ -267,14 +267,8 @@ module Keynote
267
267
  content = nil
268
268
  end
269
269
 
270
- # Flatten `data` hash into individual attributes if necessary
271
- if attrs && attrs[:data].is_a?(Hash)
272
- attrs = attrs.dup
273
- attrs.delete(:data).each do |key, value|
274
- attrs[:"data-#{key}"] = value.to_s
275
- end
276
- end
277
-
270
+ attrs = flatten_attr_hash(attrs, :aria)
271
+ attrs = flatten_attr_hash(attrs, :data)
278
272
  merge_attributes(attrs) if attrs
279
273
 
280
274
  if block_given?
@@ -321,9 +315,25 @@ module Keynote
321
315
 
322
316
  def inspect; to_s.inspect end
323
317
 
318
+ private
319
+
320
+ # If the given attrs contain an `aria` or `data` hash, flatten its
321
+ # contents into hyphenated attribute names.
322
+ def flatten_attr_hash(attrs, name)
323
+ if attrs && attrs[name].is_a?(Hash)
324
+ attrs = attrs.dup
325
+ attrs.delete(name).each do |key, value|
326
+ next if value.nil?
327
+ attrs[:"#{name}-#{key}"] = value.to_s
328
+ end
329
+ end
330
+
331
+ attrs
332
+ end
333
+
324
334
  def attrs_to_s
325
335
  attributes.inject("") do |res, (name, value)|
326
- next unless value
336
+ next res unless value
327
337
 
328
338
  value =
329
339
  if value.is_a?(Array)
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Keynote
4
4
  # @private
5
- VERSION = "1.0.0"
5
+ VERSION = "1.1.0"
6
6
  end
@@ -72,7 +72,34 @@ class TestRumble < klass
72
72
  HTML
73
73
 
74
74
  assert_rumble str do
75
- div data: { modal: true, safe: '"&quot;"'.html_safe, unsafe: '"&quot;"' }
75
+ div data: {
76
+ modal: true,
77
+ safe: '"&quot;"'.html_safe,
78
+ absent: nil,
79
+ unsafe: '"&quot;"'
80
+ }
81
+ end
82
+ end
83
+
84
+ def test_string_aria
85
+ assert_rumble '<div aria="whatever"></div>' do
86
+ div aria: "whatever"
87
+ end
88
+ end
89
+
90
+ def test_hash_aria
91
+ str = <<-HTML
92
+ <div aria-modal="true" aria-safe="&quot;&quot;&quot;" aria-unsafe="&quot;&amp;quot;&quot;">
93
+ </div>
94
+ HTML
95
+
96
+ assert_rumble str do
97
+ div aria: {
98
+ modal: true,
99
+ safe: '"&quot;"'.html_safe,
100
+ absent: nil,
101
+ unsafe: '"&quot;"'
102
+ }
76
103
  end
77
104
  end
78
105
 
@@ -87,6 +114,16 @@ class TestRumble < klass
87
114
  end
88
115
  end
89
116
 
117
+ def test_nil_attr
118
+ str = <<-HTML
119
+ <div id="id" class="class"></div>
120
+ HTML
121
+
122
+ assert_rumble str do
123
+ div id: "id", title: nil, class: "class"
124
+ end
125
+ end
126
+
90
127
  def test_several
91
128
  str = <<-HTML
92
129
  <p>Hello</p>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keynote
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Fitzgerald