html_attributes 0.1.3 → 0.1.4
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/html_attributes.gemspec +1 -1
- data/lib/html_attributes/version.rb +1 -1
- data/lib/html_attributes.rb +1 -1
- data/spec/html_attributes/array_spec.rb +12 -12
- data/spec/html_attributes/hash_spec.rb +30 -30
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88416dcda26690786311bc8696a7f217496c4edf
|
4
|
+
data.tar.gz: b11b2cc5ded0e65cbfd3b7d6e6e5e3f3288b4432
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80d794781c3457f06c0ba608ba7b6e02854edcddf1ff2e49e5d499dd8d92ddfe8aa9032ac20f4c118c274f0d294b46244e3dfb07f92f9cea1f73898bd3492444
|
7
|
+
data.tar.gz: eb8c9dad5d50c792b026cc8e36f826a5111076d51e711804825762efe7866e9c1c7c830adce87f6b47fed68366a8cd6dd8756eab67df2f87a23f4248a49ed6a9
|
data/html_attributes.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |gem|
|
|
19
19
|
gem.version = HtmlAttributes::VERSION
|
20
20
|
gem.platform = Gem::Platform::RUBY
|
21
21
|
|
22
|
-
gem.add_dependency "actionview", ">= 4.0", "<
|
22
|
+
gem.add_dependency "actionview", ">= 4.0", "< 6"
|
23
23
|
|
24
24
|
gem.add_development_dependency "rspec"
|
25
25
|
|
data/lib/html_attributes.rb
CHANGED
@@ -5,7 +5,7 @@ if defined?(ActionView::Helpers::TagHelper)
|
|
5
5
|
|
6
6
|
require "html_attributes/rails/tag_helper"
|
7
7
|
|
8
|
-
if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR >=
|
8
|
+
if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR >= 2
|
9
9
|
ActionView::Helpers::TagHelper::TagBuilder.send(:include, HtmlAttributes::TagHelper)
|
10
10
|
else
|
11
11
|
ActionView::Helpers::TagHelper.module_eval do
|
@@ -4,38 +4,38 @@ describe Array do
|
|
4
4
|
|
5
5
|
describe "#to_class_attr" do
|
6
6
|
|
7
|
-
it "
|
7
|
+
it "returns nil if array is empty" do
|
8
8
|
classes = []
|
9
|
-
classes.to_class_attr.
|
9
|
+
expect(classes.to_class_attr).to be_nil
|
10
10
|
end
|
11
11
|
|
12
|
-
it "
|
12
|
+
it "returns a space separated string if array contains strings" do
|
13
13
|
classes = ["first", "second", "third"]
|
14
|
-
classes.to_class_attr.
|
14
|
+
expect(classes.to_class_attr).to eql("first second third")
|
15
15
|
end
|
16
16
|
|
17
|
-
it "
|
17
|
+
it "preserves existing spaces" do
|
18
18
|
classes = ["first", "second third", "forth"]
|
19
|
-
classes.to_class_attr.
|
19
|
+
expect(classes.to_class_attr).to eql("first second third forth")
|
20
20
|
end
|
21
21
|
|
22
22
|
end
|
23
23
|
|
24
24
|
describe "#to_style_attr" do
|
25
25
|
|
26
|
-
it "
|
26
|
+
it "returns nil if array is empty" do
|
27
27
|
styles = []
|
28
|
-
styles.to_style_attr.
|
28
|
+
expect(styles.to_style_attr).to be_nil
|
29
29
|
end
|
30
30
|
|
31
|
-
it "
|
31
|
+
it "returns a semicolon separated string if array contains strings" do
|
32
32
|
styles = ["padding-top: 8px", "padding-right: 15px", "font-size: 12pt"]
|
33
|
-
styles.to_style_attr.
|
33
|
+
expect(styles.to_style_attr).to eql("padding-top: 8px; padding-right: 15px; font-size: 12pt;")
|
34
34
|
end
|
35
35
|
|
36
|
-
it "
|
36
|
+
it "preserves existing semicolon" do
|
37
37
|
styles = ["padding-top: 8px; padding-right: 15px", "font-size: 12pt"]
|
38
|
-
styles.to_style_attr.
|
38
|
+
expect(styles.to_style_attr).to eql("padding-top: 8px; padding-right: 15px; font-size: 12pt;")
|
39
39
|
end
|
40
40
|
|
41
41
|
end
|
@@ -4,84 +4,84 @@ describe Hash do
|
|
4
4
|
|
5
5
|
describe "#to_class_attr" do
|
6
6
|
|
7
|
-
it "
|
7
|
+
it "returns nil if hash is empty" do
|
8
8
|
classes = {}
|
9
|
-
classes.to_class_attr.
|
9
|
+
expect(classes.to_class_attr).to be_nil
|
10
10
|
end
|
11
11
|
|
12
|
-
it "
|
12
|
+
it "returns nil if hash only contains false values" do
|
13
13
|
classes = { :foo => false, :bar => false }
|
14
|
-
classes.to_class_attr.
|
14
|
+
expect(classes.to_class_attr).to be_nil
|
15
15
|
end
|
16
16
|
|
17
|
-
it "
|
17
|
+
it "returns space separated string" do
|
18
18
|
classes = { :first => true, :second => true, :third => true }
|
19
|
-
classes.to_class_attr.
|
19
|
+
expect(classes.to_class_attr).to eql("first second third")
|
20
20
|
end
|
21
21
|
|
22
|
-
it "
|
22
|
+
it "returns space separated string only for true values" do
|
23
23
|
classes = { :first => true, :second => false, :third => true }
|
24
|
-
classes.to_class_attr.
|
24
|
+
expect(classes.to_class_attr).to eql("first third")
|
25
25
|
end
|
26
26
|
|
27
27
|
end
|
28
28
|
|
29
29
|
describe "#to_style_attr" do
|
30
30
|
|
31
|
-
it "
|
31
|
+
it "returns nil if hash is empty" do
|
32
32
|
styles = {}
|
33
|
-
styles.to_style_attr.
|
33
|
+
expect(styles.to_style_attr).to be_nil
|
34
34
|
end
|
35
35
|
|
36
|
-
it "
|
36
|
+
it "returns nil if hash only contains nil values" do
|
37
37
|
styles = { :display => nil }
|
38
|
-
styles.to_style_attr.
|
38
|
+
expect(styles.to_style_attr).to be_nil
|
39
39
|
end
|
40
40
|
|
41
|
-
it "
|
41
|
+
it "returns semicolon separated string" do
|
42
42
|
styles = { :display => "none", :visibility => "hidden" }
|
43
|
-
styles.to_style_attr.
|
43
|
+
expect(styles.to_style_attr).to eql("display: none; visibility: hidden;")
|
44
44
|
end
|
45
45
|
|
46
|
-
it "
|
46
|
+
it "replaces '_' in keys with '-'" do
|
47
47
|
styles = { :font_size => "12pt" }
|
48
|
-
styles.to_style_attr.
|
48
|
+
expect(styles.to_style_attr).to eql("font-size: 12pt;")
|
49
49
|
end
|
50
50
|
|
51
|
-
it "
|
51
|
+
it "flattens hash to construct style statements" do
|
52
52
|
styles = { :padding => { :top => "8px", :right => "15px" }, :font_size => "12pt" }
|
53
|
-
styles.to_style_attr.
|
53
|
+
expect(styles.to_style_attr).to eql("font-size: 12pt; padding-right: 15px; padding-top: 8px;")
|
54
54
|
end
|
55
55
|
|
56
56
|
end
|
57
57
|
|
58
58
|
describe "#flatten" do
|
59
59
|
|
60
|
-
it "
|
61
|
-
{}.flatten.
|
60
|
+
it "does nothing for emtpy hash" do
|
61
|
+
expect({}.flatten).to eql({})
|
62
62
|
end
|
63
63
|
|
64
|
-
it "
|
65
|
-
{ "padding" => "8px", "font_size" => "12pt" }.flatten.
|
64
|
+
it "does nothing for unnested hash" do
|
65
|
+
expect({ "padding" => "8px", "font_size" => "12pt" }.flatten).to eql({ "padding" => "8px", "font_size" => "12pt" })
|
66
66
|
end
|
67
67
|
|
68
|
-
it "
|
69
|
-
{ :padding => "8px", :font_size => "12pt" }.flatten.
|
68
|
+
it "converts symbolized keys to stringified keys" do
|
69
|
+
expect({ :padding => "8px", :font_size => "12pt" }.flatten).to eql({ "padding" => "8px", "font_size" => "12pt" })
|
70
70
|
end
|
71
71
|
|
72
|
-
it "
|
72
|
+
it "flattens nested hash" do
|
73
73
|
styles = { :padding => { :top => "8px", :right => "15px" } }
|
74
|
-
styles.flatten.
|
74
|
+
expect(styles.flatten).to eql({ "paddingtop" => "8px", "paddingright" => "15px" })
|
75
75
|
end
|
76
76
|
|
77
|
-
it "
|
77
|
+
it "flattens nested hash using given separator" do
|
78
78
|
styles = { :padding => { :top => "8px", :right => "15px" } }
|
79
|
-
styles.flatten("-").
|
79
|
+
expect(styles.flatten("-")).to eql({ "padding-top" => "8px", "padding-right" => "15px" })
|
80
80
|
end
|
81
81
|
|
82
|
-
it "
|
82
|
+
it "passes array of nested keys if block is given" do
|
83
83
|
styles = { :padding => { :top => "8px", :right => "15px" } }
|
84
|
-
styles.flatten { |keys| keys.join('-') }.
|
84
|
+
expect(styles.flatten { |keys| keys.join('-') }).to eql({ "padding-top" => "8px", "padding-right" => "15px" })
|
85
85
|
end
|
86
86
|
|
87
87
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: html_attributes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Sebastian Siwy
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2019-04-08 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: actionview
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '4.0'
|
22
22
|
- - "<"
|
23
23
|
- !ruby/object:Gem::Version
|
24
|
-
version: '
|
24
|
+
version: '6'
|
25
25
|
type: :runtime
|
26
26
|
prerelease: false
|
27
27
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -31,7 +31,7 @@ dependencies:
|
|
31
31
|
version: '4.0'
|
32
32
|
- - "<"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
34
|
+
version: '6'
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: rspec
|
37
37
|
requirement: !ruby/object:Gem::Requirement
|
@@ -87,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
87
|
version: '0'
|
88
88
|
requirements: []
|
89
89
|
rubyforge_project:
|
90
|
-
rubygems_version: 2.
|
90
|
+
rubygems_version: 2.5.2.3
|
91
91
|
signing_key:
|
92
92
|
specification_version: 4
|
93
93
|
summary: html_attributes provide helper methods to convert arrays and hashes to valid
|