wrap_it 0.2.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/.yardopts +3 -0
- data/README.md +67 -66
- data/lib/wrap_it.rb +16 -16
- data/lib/wrap_it/arguments.rb +368 -0
- data/lib/wrap_it/base.rb +56 -47
- data/lib/wrap_it/callbacks.rb +24 -5
- data/lib/wrap_it/capture_array.rb +140 -0
- data/lib/wrap_it/container.rb +69 -25
- data/lib/wrap_it/derived_attributes.rb +22 -6
- data/lib/wrap_it/enums.rb +44 -34
- data/lib/wrap_it/frameworks.rb +7 -3
- data/lib/wrap_it/helpers.rb +66 -1
- data/lib/wrap_it/html.rb +149 -0
- data/lib/wrap_it/html_class.rb +164 -183
- data/lib/wrap_it/html_data.rb +28 -15
- data/lib/wrap_it/link.rb +40 -17
- data/lib/wrap_it/sections.rb +90 -2
- data/lib/wrap_it/switches.rb +33 -29
- data/lib/wrap_it/text_container.rb +83 -10
- data/lib/wrap_it/version.rb +2 -1
- data/spec/frameworks/log/development.log +2108 -0
- data/spec/integration/base_spec.rb +2 -2
- data/spec/integration/container_spec.rb +3 -3
- data/spec/integration/examples_spec.rb +16 -15
- data/spec/integration/text_container_spec.rb +3 -3
- data/spec/lib/arguments_array_spec.rb +37 -27
- data/spec/lib/arguments_spec.rb +153 -0
- data/spec/lib/base_spec.rb +2 -25
- data/spec/lib/callbacks_spec.rb +1 -1
- data/spec/lib/container_spec.rb +1 -1
- data/spec/lib/derived_attributes_spec.rb +1 -1
- data/spec/lib/enums_spec.rb +2 -3
- data/spec/lib/html_class_spec.rb +269 -80
- data/spec/lib/html_data_spec.rb +18 -12
- data/spec/lib/html_spec.rb +124 -0
- data/spec/lib/link_spec.rb +2 -2
- data/spec/lib/sections_spec.rb +1 -1
- data/spec/lib/switches_spec.rb +3 -3
- data/spec/lib/text_container_spec.rb +2 -2
- data/spec/support/example_groups/{wrap_it_example_group.rb → wrapped_example_group.rb} +5 -5
- data/wrap_it.gemspec +2 -0
- metadata +15 -8
- data/lib/wrap_it/arguments_array.rb +0 -128
- data/lib/wrap_it/module_helpers.rb +0 -23
data/spec/lib/html_class_spec.rb
CHANGED
@@ -1,118 +1,307 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe WrapIt::HTMLClass do
|
4
|
-
|
4
|
+
describe 'self.sanitize' do
|
5
|
+
it { expect(described_class.sanitize).to match_array [] }
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
it { expect(described_class.sanitize('test')).to match_array %w(test) }
|
8
|
+
|
9
|
+
it 'removes all except strings and symbols' do
|
10
|
+
expect(described_class.sanitize(0, :some, true, nil, Object, 'test'))
|
11
|
+
.to match_array %w(some test)
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
expect(wrapper.html_class_prefix).to eq ''
|
14
|
+
it 'removes repeated classes' do
|
15
|
+
expect(described_class.sanitize('a', :a, 'b')).to match_array %w(a b)
|
16
16
|
end
|
17
17
|
|
18
|
-
it '
|
19
|
-
|
20
|
-
|
18
|
+
it 'flats recursive arrays' do
|
19
|
+
expect(described_class.sanitize(:a, [:b, [:c, :d, :a]]))
|
20
|
+
.to match_array %w(a b c d)
|
21
21
|
end
|
22
22
|
|
23
|
-
it '
|
24
|
-
|
25
|
-
|
26
|
-
expect(sub_class.new(template_wrapper).html_class_prefix).to eq 'e-'
|
23
|
+
it 'removes repeated and trailing spaces' do
|
24
|
+
expect(described_class.sanitize(" some \n\ttest", 'class array '))
|
25
|
+
.to match_array %w(some test class array)
|
27
26
|
end
|
28
27
|
end
|
29
28
|
|
30
|
-
it '
|
31
|
-
|
32
|
-
|
33
|
-
expect(
|
34
|
-
|
35
|
-
expect(
|
36
|
-
wrapper.add_html_class(:a, [:b, :c]).options[:class]
|
37
|
-
).to eq %w(a b c)
|
29
|
+
it 'overrides #&' do
|
30
|
+
subject << 'a b c'
|
31
|
+
expect(subject & %w(b d c)).to match_array %w(b c)
|
32
|
+
expect(subject & 'b').to match_array %w(b)
|
33
|
+
expect(subject & %w(b)).to be_kind_of described_class
|
38
34
|
end
|
39
35
|
|
40
|
-
it '
|
41
|
-
expect(
|
42
|
-
|
43
|
-
).to
|
36
|
+
it 'overrides #<<' do
|
37
|
+
expect(subject << 'a').to equal subject
|
38
|
+
expect(subject << [0, 1, :b]).to match_array %w(a b)
|
39
|
+
expect(subject << 'c').to match_array %w(a b c)
|
44
40
|
end
|
45
41
|
|
46
|
-
it '
|
47
|
-
|
48
|
-
expect(
|
49
|
-
expect(
|
50
|
-
expect(
|
51
|
-
expect(wrapper.html_class?(/\d+/)).to be_true
|
52
|
-
expect(wrapper.html_class?(%w(a1 c1))).to be_true
|
53
|
-
expect(wrapper.html_class? { |x| x[0] == 'a' }).to be_true
|
42
|
+
it 'overrides #+' do
|
43
|
+
subject << 'a b c'
|
44
|
+
expect(subject + %w(b d c)).to match_array %w(a b c d)
|
45
|
+
expect(subject + 'b').to match_array %w(a b c)
|
46
|
+
expect(subject + %w(b)).to be_kind_of described_class
|
54
47
|
end
|
55
48
|
|
56
|
-
it '
|
57
|
-
|
58
|
-
expect(
|
59
|
-
expect(
|
60
|
-
expect(
|
61
|
-
expect(wrapper.no_html_class?(/\d+./)).to be_true
|
62
|
-
expect(wrapper.no_html_class?(%w(c1 d1))).to be_true
|
63
|
-
expect(wrapper.no_html_class? { |x| x[0] == 'c' }).to be_true
|
49
|
+
it 'overrides #-' do
|
50
|
+
subject << 'a b c d'
|
51
|
+
expect(subject - %w(b c j)).to match_array %w(a d)
|
52
|
+
expect(subject - 'd').to match_array %w(a b c)
|
53
|
+
expect(subject - %w(b)).to be_kind_of described_class
|
64
54
|
end
|
65
55
|
|
66
|
-
it '
|
67
|
-
|
68
|
-
|
56
|
+
it 'overrides #[] and #slice' do
|
57
|
+
subject << 'a b c'
|
58
|
+
%i([] slice).each do |m|
|
59
|
+
expect(subject.send(m, 1)).to eq 'b'
|
60
|
+
expect(subject.send(m, 0, 2)).to match_array %w(a b)
|
61
|
+
expect(subject.send(m, 0, 2)).to be_kind_of described_class
|
62
|
+
expect(subject.send(m, 1..-1)).to match_array %w(b c)
|
63
|
+
expect(subject.send(m, 1..-1)).to be_kind_of described_class
|
64
|
+
end
|
69
65
|
end
|
70
66
|
|
71
|
-
|
72
|
-
|
67
|
+
it 'overrides #slice!' do
|
68
|
+
subject = WrapIt::HTMLClass.new('a b c')
|
69
|
+
expect(subject.slice!(1)).to eq 'b'
|
70
|
+
expect(subject).to match_array %w(a c)
|
71
|
+
subject = WrapIt::HTMLClass.new('a b c')
|
72
|
+
expect(subject.slice!(0, 2)).to match_array %w(a b)
|
73
|
+
expect(subject).to match_array %w(c)
|
74
|
+
subject = WrapIt::HTMLClass.new('a b c')
|
75
|
+
expect(subject.slice!(0, 2)).to be_kind_of described_class
|
76
|
+
subject = WrapIt::HTMLClass.new('a b c')
|
77
|
+
expect(subject.slice!(1..-1)).to match_array %w(b c)
|
78
|
+
expect(subject).to match_array %w(a)
|
79
|
+
subject = WrapIt::HTMLClass.new('a b c')
|
80
|
+
expect(subject.slice!(1..-1)).to be_kind_of described_class
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'overrides #clear' do
|
84
|
+
subject << 'a b c'
|
85
|
+
expect(subject.clear).to equal subject
|
86
|
+
expect(subject).to be_empty
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'overrides #collect' do
|
90
|
+
subject << 'a b c'
|
91
|
+
expect(subject.collect { |x| x + '1' }).to match_array %w(a1 b1 c1)
|
92
|
+
expect(subject.collect { }).to be_kind_of described_class
|
93
|
+
expect(subject.collect).to be_kind_of Enumerator
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'overrides #collect!' do
|
97
|
+
subject << 'a b c'
|
98
|
+
expect(subject.collect! { |x| [x, 'n'] }).to match_array %w(a b c n)
|
99
|
+
expect(subject.collect! { }).to equal subject
|
100
|
+
expect(subject.collect!).to be_kind_of Enumerator
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'overrides #concat' do
|
104
|
+
subject << 'a b c'
|
105
|
+
expect(subject.concat(%w(b d c))).to match_array %w(a b c d)
|
106
|
+
expect(subject.concat('e')).to match_array %w(a b c d e)
|
107
|
+
expect(subject.concat(%w(b))).to equal subject
|
108
|
+
end
|
73
109
|
|
74
|
-
|
75
|
-
|
76
|
-
|
110
|
+
it 'overrides #delete' do
|
111
|
+
subject << 'a b2 c'
|
112
|
+
expect(subject.delete(:a)).to match_array %w(b2 c)
|
113
|
+
expect(subject.delete('d')).to match_array %w(b2 c)
|
114
|
+
expect(subject.delete('d')).to equal subject
|
115
|
+
expect(subject.delete('d', :b2)).to match_array %w(c)
|
116
|
+
subject << 'a b2'
|
117
|
+
expect(subject.delete(/.\d/, 'c')).to match_array %w(a)
|
118
|
+
expect(subject.delete { |x| x == 'a' }).to be_empty
|
119
|
+
end
|
120
|
+
|
121
|
+
%i(index rindex).each do |m|
|
122
|
+
it "overrides ##{m}" do
|
123
|
+
subject << 'a b2 c'
|
124
|
+
expect(subject.index(:a)).to eq 0
|
125
|
+
expect(subject.index('d')).to be_nil
|
126
|
+
expect(subject.index(['d', :b2])).to eq 1
|
127
|
+
expect(subject.index(/.\d/)).to eq 1
|
128
|
+
expect(subject.index { |x| x == 'c' }).to eq 2
|
129
|
+
expect(subject.index).to be_kind_of Enumerator
|
77
130
|
end
|
131
|
+
end
|
78
132
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
133
|
+
it 'overrides #drop' do
|
134
|
+
subject << 'a b c'
|
135
|
+
expect(subject.drop(1)).to match_array %w(b c)
|
136
|
+
expect(subject.drop(1)).to be_kind_of described_class
|
137
|
+
expect(subject).to match_array %w(a b c)
|
138
|
+
end
|
139
|
+
|
140
|
+
{drop_while: %w(c d), reject: %w(c), select: %w(a b d)}.each do |m, v|
|
141
|
+
it "overrides ##{m}" do
|
142
|
+
subject << 'a b c d'
|
143
|
+
expect(subject.send(m) { |x| x != 'c' }).to match_array v
|
144
|
+
expect(subject.send(m) { |x| x != 'c' }).to be_kind_of described_class
|
145
|
+
expect(subject.send(m)).to be_kind_of Enumerator
|
84
146
|
end
|
147
|
+
end
|
85
148
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
expect(
|
149
|
+
{map: %w(ac bc cc dc)}.each do |m, v|
|
150
|
+
it "overrides ##{m}" do
|
151
|
+
subject << 'a b c d'
|
152
|
+
expect(subject.send(m) { |x| x = x + 'c' }).to match_array v
|
153
|
+
expect(subject.send(m) { |x| x = x + 'c' }).to be_kind_of described_class
|
154
|
+
expect(subject.send(m)).to be_kind_of Enumerator
|
90
155
|
end
|
156
|
+
end
|
157
|
+
|
158
|
+
it "overrides #map!" do
|
159
|
+
subject << 'a b c d'
|
160
|
+
expect(subject.map! { |x| x = x + 'c' }).to equal subject
|
161
|
+
expect(subject).to match_array %w(ac bc cc dc)
|
162
|
+
expect(subject.map!).to be_kind_of Enumerator
|
163
|
+
end
|
91
164
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
165
|
+
it "overrides #reject!" do
|
166
|
+
subject << 'a b1 c1 d'
|
167
|
+
expect(subject.reject! { |x| /\d/ =~ x }).to equal subject
|
168
|
+
expect(subject).to match_array %w(a d)
|
169
|
+
expect(subject.reject!).to be_kind_of Enumerator
|
170
|
+
end
|
171
|
+
|
172
|
+
%i(each each_index).each do |m|
|
173
|
+
it "overrides ##{m}" do
|
174
|
+
subject << 'a b c'
|
175
|
+
i = 0
|
176
|
+
expect(subject.send(m) { |x| i += 1 }).to equal subject
|
177
|
+
expect(i).to eq 3
|
178
|
+
expect(subject.send(m)).to be_kind_of Enumerator
|
98
179
|
end
|
180
|
+
end
|
99
181
|
|
100
|
-
|
101
|
-
|
102
|
-
expect(
|
103
|
-
|
104
|
-
expect(
|
182
|
+
{first: %w(a b), last: %w(c b)}.each do |m, v|
|
183
|
+
it "overrides ##{m}" do
|
184
|
+
expect(subject.send(m)).to be_nil
|
185
|
+
subject << 'a b c'
|
186
|
+
expect(subject.send(m)).to eq v[0]
|
187
|
+
expect(subject.send(m, 2)).to match_array v
|
188
|
+
expect(subject.send(m, 2)).to be_kind_of described_class
|
105
189
|
end
|
190
|
+
end
|
191
|
+
|
192
|
+
it "overrides #pop" do
|
193
|
+
expect(subject.pop).to be_nil
|
194
|
+
subject << 'a b c'
|
195
|
+
expect(subject.pop).to eq 'c'
|
196
|
+
expect(subject).to match_array %w(a b)
|
197
|
+
subject << 'c'
|
198
|
+
expect(subject.pop(2)).to match_array %w(b c)
|
199
|
+
expect(subject).to match_array %w(a)
|
200
|
+
subject << 'b c'
|
201
|
+
expect(subject.pop(2)).to be_kind_of described_class
|
202
|
+
end
|
203
|
+
|
204
|
+
it "overrides #shift" do
|
205
|
+
expect(subject.shift).to be_nil
|
206
|
+
subject << 'a b c'
|
207
|
+
expect(subject.shift).to eq 'a'
|
208
|
+
expect(subject).to match_array %w(b c)
|
209
|
+
subject << 'a'
|
210
|
+
expect(subject.shift(2)).to match_array %w(b c)
|
211
|
+
expect(subject).to match_array %w(a)
|
212
|
+
subject << 'b c'
|
213
|
+
expect(subject.shift(2)).to be_kind_of described_class
|
214
|
+
end
|
215
|
+
|
216
|
+
it 'overrides #include?' do
|
217
|
+
subject << 'a b2 c'
|
218
|
+
expect(subject.include?(:a)).to be_true
|
219
|
+
expect(subject.include?('d')).to be_false
|
220
|
+
expect(subject.include?('d', :b2)).to be_false
|
221
|
+
expect(subject.include?('a', :b2)).to be_true
|
222
|
+
expect(subject.include?(/.\d/)).to be_true
|
223
|
+
expect(subject.include?(proc { |x| x == 'c' })).to be_true
|
224
|
+
end
|
225
|
+
|
226
|
+
it 'overrides #replace' do
|
227
|
+
subject << 'a b c'
|
228
|
+
expect(subject.replace('d e f')).to match_array %w(d e f)
|
229
|
+
expect(subject.replace('a b')).to equal subject
|
230
|
+
end
|
231
|
+
|
232
|
+
it 'overrides #keep_if' do
|
233
|
+
subject << 'a b c'
|
234
|
+
expect(subject.keep_if { |x| x != 'c' }).to match_array %w(a b)
|
235
|
+
expect(subject.keep_if { |x| x != 'c' }).to equal subject
|
236
|
+
expect(subject.keep_if).to be_kind_of Enumerator
|
237
|
+
end
|
238
|
+
|
239
|
+
it 'overrides #push' do
|
240
|
+
subject << 'a b c'
|
241
|
+
expect(subject.push('a d')).to equal subject
|
242
|
+
expect(subject).to match_array %w(a b c d)
|
243
|
+
end
|
244
|
+
|
245
|
+
it 'overrides #unshift' do
|
246
|
+
subject << 'a b c'
|
247
|
+
expect(subject.unshift('a d')).to equal subject
|
248
|
+
expect(subject).to match_array %w(a d b c)
|
249
|
+
end
|
250
|
+
|
251
|
+
it 'overrides #values_at' do
|
252
|
+
subject << 'a b c'
|
253
|
+
expect(subject.values_at(0, 2)).to match_array %w(a c)
|
254
|
+
expect(subject.values_at(1)).to be_kind_of described_class
|
255
|
+
end
|
256
|
+
|
257
|
+
it 'overrides #|' do
|
258
|
+
subject << 'a b c'
|
259
|
+
expect(subject | 'b c d').to match_array %w(a b c d)
|
260
|
+
expect(subject | 'b c d').to be_kind_of described_class
|
261
|
+
end
|
106
262
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
263
|
+
{
|
264
|
+
:'<=>' => [%w(b c d e)],
|
265
|
+
:== => [%w(b c d e)],
|
266
|
+
at: [1],
|
267
|
+
count: [],
|
268
|
+
count: ['a'],
|
269
|
+
delete_at: [1],
|
270
|
+
fetch: [1],
|
271
|
+
hash: [],
|
272
|
+
inspect: [],
|
273
|
+
to_s: [],
|
274
|
+
join: ['-'],
|
275
|
+
length: [],
|
276
|
+
size: [],
|
277
|
+
take: [2],
|
278
|
+
to_a: [],
|
279
|
+
}.each do |m, args|
|
280
|
+
it "passes through ##{m}" do
|
281
|
+
a = %w(a b c d)
|
282
|
+
subject << a
|
283
|
+
expect(subject.send(m, *args)).to eq a.send(m, *args)
|
111
284
|
end
|
285
|
+
end
|
286
|
+
|
287
|
+
it 'passes through #empty?' do
|
288
|
+
expect(subject.empty?).to be_true
|
289
|
+
end
|
112
290
|
|
113
|
-
|
114
|
-
|
115
|
-
|
291
|
+
it 'resticts unusefull methods' do
|
292
|
+
%i(
|
293
|
+
* []= assoc bsearch combination compact compact! fill flatten flatten!
|
294
|
+
insert pack permutation product rassoc repeated_combination rotate
|
295
|
+
repeated_permutation reverse reverse! reverse_each sample rotate! shuffle
|
296
|
+
shuffle! sort sort! sort_by! transpose uniq uniq! zip flat_map max max_by
|
297
|
+
min min_by minmax minmax_by
|
298
|
+
).each do |m|
|
299
|
+
expect { subject.send(m) }.to raise_error
|
116
300
|
end
|
117
301
|
end
|
302
|
+
|
303
|
+
it 'provides #to_html' do
|
304
|
+
subject << [:a, :b, :c]
|
305
|
+
expect(subject.to_html).to eq 'a b c'
|
306
|
+
end
|
118
307
|
end
|
data/spec/lib/html_data_spec.rb
CHANGED
@@ -1,21 +1,27 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe WrapIt::HTMLData do
|
4
|
-
|
4
|
+
describe 'self.sanitize' do
|
5
|
+
it { expect(described_class.sanitize).to eq ({}) }
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
it 'stringifies values' do
|
8
|
+
expect(described_class.sanitize(test: 1, subj: 2))
|
9
|
+
.to eq(test: '1', subj: '2')
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'splits dashed keys' do
|
13
|
+
expect(described_class.sanitize(:'test-me-now' => 1, subj: 2))
|
14
|
+
.to eq(test: {me: {now: '1'}}, subj: '2')
|
10
15
|
end
|
11
|
-
end
|
12
16
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
17
|
+
it 'parses nested hash' do
|
18
|
+
expect(described_class.sanitize(test: {:'me-now' => 1}, subj: 2))
|
19
|
+
.to eq(test: {me: {now: '1'}}, subj: '2')
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'removes bogous symbols from keys' do
|
23
|
+
expect(described_class.sanitize(test: {:'me_n%ow' => 1}, subj: 2))
|
24
|
+
.to eq(test: {me_now: '1'}, subj: '2')
|
18
25
|
end
|
19
26
|
end
|
20
27
|
end
|
21
|
-
|
@@ -0,0 +1,124 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe WrapIt::HTML, type: :wrapped do
|
4
|
+
it_behaves_like 'Base module'
|
5
|
+
|
6
|
+
describe '#html_data' do
|
7
|
+
it 'sets data as {} by default' do
|
8
|
+
expect(wrapper.html_data).to be_kind_of(Hash)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#html_attr' do
|
13
|
+
it 'sets attr as {} by default' do
|
14
|
+
expect(wrapper.html_attr).to be_kind_of(Hash)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#html_class' do
|
19
|
+
it 'sets class HTMLClass by default' do
|
20
|
+
expect(wrapper.html_class).to be_kind_of(WrapIt::HTMLClass)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'has self.html_class and #html_class methods' do
|
25
|
+
wrapper_class.class_eval { html_class :a, [:b, 'c'] }
|
26
|
+
expect(wrapper.html_class).to match_array %w(a b c)
|
27
|
+
sub_class = Class.new(wrapper_class) { html_class :a, [:d, 'e'] }
|
28
|
+
expect(sub_class.new(template_wrapper).html_class)
|
29
|
+
.to match_array %w(a d e b c)
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#html_class_prefix' do
|
33
|
+
it 'returns empty string by default' do
|
34
|
+
expect(wrapper.html_class_prefix).to eq ''
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'returns value setted by class method' do
|
38
|
+
wrapper_class.class_eval { html_class_prefix 'e-' }
|
39
|
+
expect(wrapper.html_class_prefix).to eq 'e-'
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'returns derived value' do
|
43
|
+
wrapper_class.class_eval { html_class_prefix 'e-' }
|
44
|
+
sub_class = Class.new(wrapper_class)
|
45
|
+
expect(sub_class.new(template_wrapper).html_class_prefix).to eq 'e-'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe WrapIt::HTMLClass do
|
51
|
+
it 'has #<< with chaining' do
|
52
|
+
expect(subject << :test).to match_array %w(test)
|
53
|
+
subject.clear
|
54
|
+
expect(subject << :a << 'b').to match_array %w(a b)
|
55
|
+
subject.clear
|
56
|
+
expect(subject << :a << [:b, :c]).to match_array %w(a b c)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'has #delete' do
|
60
|
+
subject << :a << :b
|
61
|
+
expect(subject.delete('a')).to match_array %w(b)
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'has #include? method' do
|
65
|
+
subject << [:a1, :b1]
|
66
|
+
expect(subject.include?('a1')).to be_true
|
67
|
+
expect(subject.include?(:a1, :b1)).to be_true
|
68
|
+
expect(subject.include?(:a1, :b2)).to be_false
|
69
|
+
expect(subject.include?(:a2)).to be_false
|
70
|
+
expect(subject.include?(/\d+/)).to be_true
|
71
|
+
expect(subject.include?(%w(a1 c1))).to be_true
|
72
|
+
expect(subject.include? { |x| x[0] == 'a' }).to be_true
|
73
|
+
end
|
74
|
+
|
75
|
+
=begin
|
76
|
+
describe 'documentation examples' do
|
77
|
+
let(:element) { wrapper }
|
78
|
+
|
79
|
+
it 'html_class=' do
|
80
|
+
element.html_class = [:a, 'b', ['c', :d, 'a']]
|
81
|
+
expect(element.html_class).to eq %w(a b c d)
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'add_html_class' do
|
85
|
+
element.html_class = 'a'
|
86
|
+
element.add_html_class :b, :c, ['d', :c, :e, 'a']
|
87
|
+
expect(element.html_class).to include(*%w(a b c d e))
|
88
|
+
expect(element.html_class.size).to eq 5
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'remove_html_class' do
|
92
|
+
element.add_html_class %w(a b c d e)
|
93
|
+
element.remove_html_class :b, ['c', :e]
|
94
|
+
expect(element.html_class).to eq %w(a d)
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'html_class? with Symbol or String' do
|
98
|
+
element.html_class = [:a, :b, :c]
|
99
|
+
expect(element.html_class?(:a)).to be_true
|
100
|
+
expect(element.html_class?(:d)).to be_false
|
101
|
+
expect(element.html_class?(:a, 'b')).to be_true
|
102
|
+
expect(element.html_class?(:a, :d)).to be_false
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'html_class? with Regexp' do
|
106
|
+
element.html_class = [:some, :test]
|
107
|
+
expect(element.html_class?(/some/)).to be_true
|
108
|
+
expect(element.html_class?(/some/, /bad/)).to be_false
|
109
|
+
expect(element.html_class?(/some/, :test)).to be_true
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'html_class? with Array' do
|
113
|
+
element.html_class = [:a, :b, :c]
|
114
|
+
expect(element.html_class?(%w(a d))).to be_true
|
115
|
+
expect(element.html_class?(%w(e d))).to be_false
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'html_class? with block' do
|
119
|
+
element.html_class = [:a, :b, :c]
|
120
|
+
expect(element.html_class? { |x| x == 'a' }).to be_true
|
121
|
+
end
|
122
|
+
end
|
123
|
+
=end
|
124
|
+
end
|