deas-erbtags 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/deas-erbtags/utils.rb +6 -0
- data/lib/deas-erbtags/version.rb +1 -1
- data/test/unit/utils_tests.rb +18 -1
- metadata +4 -4
data/lib/deas-erbtags/utils.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
1
3
|
module Deas; end
|
2
4
|
module Deas::ErbTags
|
3
5
|
|
@@ -29,6 +31,10 @@ module Deas::ErbTags
|
|
29
31
|
end.join
|
30
32
|
end
|
31
33
|
|
34
|
+
def self.insert_html_class(current_class_str, *classes_to_insert)
|
35
|
+
(Set.new(current_class_str.split(' ')) + classes_to_insert).sort.join(' ')
|
36
|
+
end
|
37
|
+
|
32
38
|
end
|
33
39
|
|
34
40
|
# alias for brevity
|
data/lib/deas-erbtags/version.rb
CHANGED
data/test/unit/utils_tests.rb
CHANGED
@@ -7,12 +7,29 @@ module Deas::ErbTags::Utils
|
|
7
7
|
desc 'Deas::ErbTags::Helpers'
|
8
8
|
subject { Deas::ErbTags::Utils }
|
9
9
|
|
10
|
-
should have_imeths :html_attrs, :escape_attr_value
|
10
|
+
should have_imeths :html_attrs, :escape_attr_value, :insert_html_class
|
11
11
|
|
12
12
|
should "alias itself as `Deas::ErbTags::U`" do
|
13
13
|
assert_same Deas::ErbTags::Utils, Deas::ErbTags::U
|
14
14
|
end
|
15
15
|
|
16
|
+
should "insert html class values into a given html class string" do
|
17
|
+
none = ''
|
18
|
+
assert_equal '', subject.insert_html_class(none)
|
19
|
+
assert_equal 'a', subject.insert_html_class(none, 'a')
|
20
|
+
assert_equal 'a b', subject.insert_html_class(none, 'b', 'a')
|
21
|
+
|
22
|
+
single = 'z-class'
|
23
|
+
assert_equal 'z-class', subject.insert_html_class(single)
|
24
|
+
assert_equal 'a z-class', subject.insert_html_class(single, 'a')
|
25
|
+
assert_equal 'a b z-class', subject.insert_html_class(single, 'a', 'b')
|
26
|
+
|
27
|
+
multi = 'z-class y-class'
|
28
|
+
assert_equal 'y-class z-class', subject.insert_html_class(multi)
|
29
|
+
assert_equal 'a y-class z-class', subject.insert_html_class(multi, 'a')
|
30
|
+
assert_equal 'a b y-class z-class', subject.insert_html_class(multi, 'a', 'b')
|
31
|
+
end
|
32
|
+
|
16
33
|
end
|
17
34
|
|
18
35
|
class HashAttrsTests < BaseTests
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deas-erbtags
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 4
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kelly Redding
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2013-05-
|
19
|
+
date: 2013-05-21 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: assert
|