wrap_it 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/.gitignore +1 -0
- data/README.md +10 -3
- data/lib/wrap_it/enums.rb +49 -23
- data/lib/wrap_it/html_class.rb +52 -12
- data/lib/wrap_it/html_data.rb +7 -0
- data/lib/wrap_it/no_rails.rb +7 -0
- data/lib/wrap_it/rails.rb +7 -0
- data/lib/wrap_it/switches.rb +55 -22
- data/lib/wrap_it/version.rb +1 -1
- data/spec/lib/enums_spec.rb +10 -0
- data/spec/lib/html_class_spec.rb +14 -3
- data/spec/lib/html_data_spec.rb +21 -0
- data/spec/lib/switches_spec.rb +13 -0
- data/spec/support/example_groups/wrap_it_example_group.rb +12 -2
- data/spec/support/shared_examples/base_module.rb +8 -0
- metadata +5 -4
- data/wrap_it-0.1.0.gem +0 -0
- data/wrap_it-0.1.1.gem +0 -0
- data/wrap_it-0.1.2.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0bff3652d6d84abb2e4b5fd7e0fcfd1b3077c97
|
4
|
+
data.tar.gz: d7d2c2031a7f3329f7f22e23378e217c9a1248a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96022ed7bb7fff92f6c0ee5cea9dd0be8c0e53d670a66014a7685edaeb51910a72692e23d308ef236eb8898acffef37bbd5b97ee406695078acfe53c209d2db1
|
7
|
+
data.tar.gz: d3b6e268405b869b07ac024a824f13589647e2e8d9ebc94edf295791ea4a0e2aea1bd04ad51ae538fbf7eb140d64cd0a59f3275fb2b0b409089c2dfcc2407803
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -148,6 +148,10 @@ Use `default_tag` DSL method inside your class to specify HTML tag name for elem
|
|
148
148
|
|
149
149
|
Use `html_class` DSL method to add default html classes, thats are automatically added when element created.
|
150
150
|
|
151
|
+
#### html_class_prefix(prefix)
|
152
|
+
|
153
|
+
Sets html class prefix. It can be `Symbol` or `String` and converted to `String`. This value used with `switch` and `enum` functionality. See its descriptions below.
|
154
|
+
|
151
155
|
#### omit_content
|
152
156
|
|
153
157
|
Once this method called from class, this class will ommit any text content, captured from template. For example, `<%= element do %><p>Any content</p><% end %>` normally will produce `<div><p>Any content</p></div>`. In some cases you whant to drop `<p>Any content</p>`, for exmaple, inside tables.
|
@@ -158,8 +162,8 @@ Adds `switch`. Switch is a boolean flag. When element created, creation argument
|
|
158
162
|
|
159
163
|
This method also adds getter and setter for this switch in form `name?` and `name=` respectively.
|
160
164
|
|
161
|
-
|
162
|
-
|
165
|
+
When `html_class` option specified and switch changes its state, HTML class for element will be computed as follows. if `html_class` options is `true`, html class produced from `html_class_prefix` and `name` of switch. If `html_class` is a String, Symbol or Array of this types, html class produced as array of `html_class_prefix` and each `html_class` concatinations. This classes added to element if switch is on or removed in other case.
|
166
|
+
|
163
167
|
Also `aliases` option available. So if some of aliases founded in arguments it also changes switch state. You should pass only `Symbol` or `Array` if symbols to this optioin.
|
164
168
|
|
165
169
|
If block given, it will be called each time switch changes its state in context of element with the switch state as argument.
|
@@ -170,7 +174,7 @@ Adds `enum`. When element created, creation arguments will be scanned for `Symbo
|
|
170
174
|
|
171
175
|
This method also adds getter and setter for this enum.
|
172
176
|
|
173
|
-
|
177
|
+
If you set `html_class` option to `true`, with each enum change, HTML class, composed from `html_class_prefix` and enum `value` will be added to element. If you want to override this prefix, specify it with `html_class_prefix` option. By default, enum changes are not affected to html classes.
|
174
178
|
|
175
179
|
Also `aliases` option available. So if some of aliases founded in creation options keys it also changes enum value. You should pass only `Symbol` or `Array` if symbols to this optioin.
|
176
180
|
|
@@ -269,6 +273,9 @@ Creates your own DSL method to create child items. In arguments, you should spec
|
|
269
273
|
|
270
274
|
# Changes
|
271
275
|
|
276
|
+
`0.1.4`
|
277
|
+
* added: html_class_prefix
|
278
|
+
|
272
279
|
`0.1.3`
|
273
280
|
* this is a fix for 0.1.2, that it was not properly compiled.
|
274
281
|
|
data/lib/wrap_it/enums.rb
CHANGED
@@ -5,22 +5,22 @@ module WrapIt
|
|
5
5
|
# @author Alexey Ovchinnikov <alexiss@cybernetlab.ru>
|
6
6
|
#
|
7
7
|
module Enums
|
8
|
+
extend DerivedAttributes
|
9
|
+
|
8
10
|
def self.included(base)
|
9
|
-
base
|
11
|
+
base == Base || fail(
|
10
12
|
TypeError,
|
11
|
-
"#{self.class.name} can be included only into WrapIt::Base
|
13
|
+
"#{self.class.name} can be included only into WrapIt::Base"
|
12
14
|
)
|
13
|
-
extend DerivedAttributes
|
14
15
|
base.extend ClassMethods
|
15
|
-
|
16
|
-
base.after_initialize :enums_init if base == Base
|
16
|
+
base.after_initialize :enums_init
|
17
17
|
end
|
18
18
|
|
19
19
|
private
|
20
20
|
|
21
21
|
def enums_init
|
22
22
|
opt_keys = @options.keys
|
23
|
-
|
23
|
+
enums.each do |name, opts|
|
24
24
|
value = nil
|
25
25
|
names = [name] + [opts[:aliases] || []].flatten
|
26
26
|
opt_keys.select { |o| names.include? o }.each do |key|
|
@@ -35,6 +35,10 @@ module WrapIt
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
def enums
|
39
|
+
@nums ||= self.class.collect_derived(:@enums, {}, :merge)
|
40
|
+
end
|
41
|
+
|
38
42
|
#
|
39
43
|
# Class methods to include
|
40
44
|
#
|
@@ -47,6 +51,12 @@ module WrapIt
|
|
47
51
|
# `name: value` key-value pair with valid value, this pair removed from
|
48
52
|
# options and enum takes this value.
|
49
53
|
#
|
54
|
+
# If you set `html_class` option to `true`, with each enum change, HTML
|
55
|
+
# class, composed from `html_class_prefix` and enum `value` will be
|
56
|
+
# added to element. If you want to override this prefix, specify it
|
57
|
+
# with `html_class_prefix` option. By default, enum changes are not
|
58
|
+
# affected to html classes.
|
59
|
+
#
|
50
60
|
# This method also adds getter and setter for this enum.
|
51
61
|
#
|
52
62
|
# @param name [String, Symbol] Enum name. Converted to `Symbol`.
|
@@ -54,6 +64,8 @@ module WrapIt
|
|
54
64
|
# @options options [String, Symbol] :html_class_prefix prefix of HTML
|
55
65
|
# class that will automatically added to element if enum changes its
|
56
66
|
# value.
|
67
|
+
# @options options [Boolean] :html_class whether this enum changes
|
68
|
+
# should affect to html class.
|
57
69
|
# @options options [Symbol, Array<Symbol>] :aliases list of enum aliases.
|
58
70
|
# Warning! Values are not converted - pass only `Symbols` here.
|
59
71
|
# @options options [String, Symbol] :default default value for enum,
|
@@ -63,27 +75,41 @@ module WrapIt
|
|
63
75
|
# @yieldreturn [void]
|
64
76
|
#
|
65
77
|
# @return [void]
|
66
|
-
def enum(name, values,
|
67
|
-
|
78
|
+
def enum(name, values, opts = {}, &block)
|
79
|
+
opts.symbolize_keys!
|
68
80
|
name = name.to_sym
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
81
|
+
opts.merge!(block: block, name: name, values: values)
|
82
|
+
opts.key?(:default) && opts[:default] = opts[:default].to_sym
|
83
|
+
if opts.delete(:html_class) == true || opts.key?(:html_class_prefix)
|
84
|
+
opts[:html_class_prefix].is_a?(Symbol) &&
|
85
|
+
opts[:html_class_prefix] = opts[:html_class_prefix].to_s
|
86
|
+
prefix = html_class_prefix
|
87
|
+
opts[:html_class_prefix].is_a?(String) &&
|
88
|
+
prefix = opts[:html_class_prefix]
|
89
|
+
opts[:regexp] = /\A#{prefix}(?:#{values.join('|')})\z/
|
90
|
+
opts[:html_class_prefix] = prefix
|
91
|
+
end
|
73
92
|
var = "@#{name}".to_sym
|
74
93
|
define_method("#{name}") { instance_variable_get(var) }
|
75
|
-
define_method("#{name}="
|
76
|
-
v = value if values.include?(value)
|
77
|
-
v ||= options[:default] if options.key?(:default)
|
78
|
-
instance_variable_set(var, v)
|
79
|
-
block.nil? || instance_exec(v, &block)
|
80
|
-
if options.key?(:regexp)
|
81
|
-
remove_html_class(options[:regexp])
|
82
|
-
v.nil? || add_html_class("#{options[:html_class_prefix]}#{v}")
|
83
|
-
end
|
84
|
-
end
|
94
|
+
define_method("#{name}=", &Enums.setter(name, &block))
|
85
95
|
@enums ||= {}
|
86
|
-
@enums[name] =
|
96
|
+
@enums[name] = opts
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
private
|
101
|
+
|
102
|
+
def self.setter(name, &block)
|
103
|
+
proc do |value|
|
104
|
+
opts = enums[name]
|
105
|
+
v = value if opts[:values].include?(value)
|
106
|
+
v ||= opts[:default] if opts.key?(:default)
|
107
|
+
instance_variable_set("@#{name}", v)
|
108
|
+
block.nil? || instance_exec(v, &block)
|
109
|
+
if opts.key?(:regexp)
|
110
|
+
remove_html_class(opts[:regexp])
|
111
|
+
v.nil? || add_html_class("#{opts[:html_class_prefix]}#{v}")
|
112
|
+
end
|
87
113
|
end
|
88
114
|
end
|
89
115
|
end
|
data/lib/wrap_it/html_class.rb
CHANGED
@@ -10,23 +10,47 @@ module WrapIt
|
|
10
10
|
extend DerivedAttributes
|
11
11
|
|
12
12
|
def self.included(base)
|
13
|
-
base
|
13
|
+
base == Base || fail(
|
14
14
|
TypeError,
|
15
|
-
"#{self.class.name} can be included only into WrapIt::Base
|
15
|
+
"#{self.class.name} can be included only into WrapIt::Base"
|
16
16
|
)
|
17
17
|
base.extend ClassMethods
|
18
18
|
end
|
19
19
|
|
20
20
|
#
|
21
|
-
#
|
21
|
+
# Sanitize HTML class list. Arguments list flatten and filtered for only
|
22
|
+
# Strings and Symbols. Duplicates are removed.
|
22
23
|
#
|
23
|
-
# @
|
24
|
+
# @override sanitize([html_class, ...])
|
25
|
+
# @param html_class [Object] HTML class
|
26
|
+
#
|
27
|
+
# @return [Array<String>] sanitized HTML classes list
|
28
|
+
def self.sanitize(*args)
|
29
|
+
args
|
30
|
+
.flatten
|
31
|
+
.map { |a| a.is_a?(String) || a.is_a?(Symbol) ? a.to_s : nil }
|
32
|
+
.compact
|
33
|
+
.uniq
|
34
|
+
end
|
35
|
+
|
36
|
+
#
|
37
|
+
# html class getter.
|
38
|
+
#
|
39
|
+
# @return [Array<String>] array of html classes of element.
|
24
40
|
def html_class
|
25
41
|
@options[:class]
|
26
42
|
end
|
27
43
|
|
28
44
|
#
|
29
|
-
#
|
45
|
+
# HTML class prefix getter.
|
46
|
+
#
|
47
|
+
# @return [String] HTML class prefix.
|
48
|
+
def html_class_prefix
|
49
|
+
self.class.html_class_prefix
|
50
|
+
end
|
51
|
+
|
52
|
+
#
|
53
|
+
# Sets html class(es) for element.
|
30
54
|
# @param value [Symbol, String, Array<Symbol, String>] HTML class or list
|
31
55
|
# of classes. All classes will be converted to Strings, duplicates are
|
32
56
|
# removed.
|
@@ -53,13 +77,16 @@ module WrapIt
|
|
53
77
|
# element.add_html_class :b, :c, ['d', :c, :e, 'a']
|
54
78
|
# element.html_class #=> ['a', 'b', 'c', 'd', 'e']
|
55
79
|
def add_html_class(*args)
|
56
|
-
@options
|
57
|
-
|
80
|
+
if @options.key?(:class)
|
81
|
+
@options[:class].is_a?(Array) || options[:class] = [options[:class]]
|
82
|
+
args += @options[:class]
|
83
|
+
end
|
84
|
+
@options[:class] = HTMLClass.sanitize(*args)
|
58
85
|
self # allow chaining
|
59
86
|
end
|
60
87
|
|
61
88
|
#
|
62
|
-
# Removes html class(es) from element. Chaining allowed
|
89
|
+
# Removes html class(es) from element. Chaining allowed.
|
63
90
|
# @override add_html_class([[html_class], ...])
|
64
91
|
# @param html_class [Symbol, String, Regexp, Array<Symbol, String, Regexp>]
|
65
92
|
# HTML class or list of HTML classes.
|
@@ -148,7 +175,7 @@ module WrapIt
|
|
148
175
|
protected
|
149
176
|
|
150
177
|
def add_default_classes
|
151
|
-
add_html_class
|
178
|
+
add_html_class(self.class.collect_derived(:@html_class))
|
152
179
|
end
|
153
180
|
|
154
181
|
private
|
@@ -184,9 +211,22 @@ module WrapIt
|
|
184
211
|
#
|
185
212
|
# @return [void]
|
186
213
|
def html_class(*args)
|
187
|
-
@html_class
|
188
|
-
@html_class
|
189
|
-
|
214
|
+
@html_class.nil? || args += @html_class
|
215
|
+
@html_class = HTMLClass.sanitize(*args)
|
216
|
+
end
|
217
|
+
|
218
|
+
#
|
219
|
+
# @dsl
|
220
|
+
# Sets HTML class prefix. It used in switchers and enums
|
221
|
+
# @param prefix [String] HTML class prefix
|
222
|
+
#
|
223
|
+
# @return [void]
|
224
|
+
def html_class_prefix(prefix = nil)
|
225
|
+
return get_derived(:@html_class_prefix) || '' if prefix.nil?
|
226
|
+
prefix.is_a?(String) || prefix.is_a?(Symbol) || fail(
|
227
|
+
ArgumentError, 'prefix should be a String or Symbol'
|
228
|
+
)
|
229
|
+
@html_class_prefix = prefix.to_s
|
190
230
|
end
|
191
231
|
end
|
192
232
|
end
|
data/lib/wrap_it/html_data.rb
CHANGED
@@ -5,6 +5,13 @@ module WrapIt
|
|
5
5
|
# @author Alexey Ovchinnikov <alexiss@cybernetlab.ru>
|
6
6
|
#
|
7
7
|
module HTMLData
|
8
|
+
def self.included(base)
|
9
|
+
base == Base || fail(
|
10
|
+
TypeError,
|
11
|
+
"#{self.class.name} can be included only into WrapIt::Base"
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
8
15
|
def set_html_data(name, value)
|
9
16
|
@options[:data] ||= {}
|
10
17
|
@options[:data][name.to_sym] = value
|
data/lib/wrap_it/no_rails.rb
CHANGED
@@ -32,6 +32,13 @@ module WrapIt
|
|
32
32
|
# Non rails render implementation
|
33
33
|
#
|
34
34
|
module Renderer
|
35
|
+
def self.included(base)
|
36
|
+
base == Base || fail(
|
37
|
+
TypeError,
|
38
|
+
"#{self.class.name} can be included only into WrapIt::Base"
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
35
42
|
protected
|
36
43
|
|
37
44
|
def empty_html
|
data/lib/wrap_it/rails.rb
CHANGED
@@ -5,6 +5,13 @@ module WrapIt
|
|
5
5
|
# @author Alexey Ovchinnikov <alexiss@cybernetlab.ru>
|
6
6
|
#
|
7
7
|
module Renderer
|
8
|
+
def self.included(base)
|
9
|
+
base == Base || fail(
|
10
|
+
TypeError,
|
11
|
+
"#{self.class.name} can be included only into WrapIt::Base"
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
8
15
|
protected
|
9
16
|
|
10
17
|
def empty_html
|
data/lib/wrap_it/switches.rb
CHANGED
@@ -5,21 +5,20 @@ module WrapIt
|
|
5
5
|
# @author Alexey Ovchinnikov <alexiss@cybernetlab.ru>
|
6
6
|
#
|
7
7
|
module Switches
|
8
|
+
extend DerivedAttributes
|
9
|
+
|
8
10
|
def self.included(base)
|
9
|
-
base
|
11
|
+
base == Base || fail(
|
10
12
|
TypeError,
|
11
|
-
"#{self.class.name} can be included only into WrapIt::Base
|
13
|
+
"#{self.class.name} can be included only into WrapIt::Base"
|
12
14
|
)
|
13
|
-
extend DerivedAttributes
|
14
15
|
base.extend ClassMethods
|
15
|
-
|
16
|
-
base.after_initialize :switches_init if base == Base
|
16
|
+
base.after_initialize :switches_init
|
17
17
|
end
|
18
18
|
|
19
19
|
private
|
20
20
|
|
21
21
|
def switches_init
|
22
|
-
switches = self.class.collect_derived(:@switches, {}, :merge)
|
23
22
|
keys = switches.keys
|
24
23
|
keys.each { |switch| instance_variable_set("@#{switch}", false) }
|
25
24
|
@options.keys.select { |o| keys.include?(o) }.each do |switch|
|
@@ -30,6 +29,10 @@ module WrapIt
|
|
30
29
|
end
|
31
30
|
end
|
32
31
|
|
32
|
+
def switches
|
33
|
+
@switches ||= self.class.collect_derived(:@switches, {}, :merge)
|
34
|
+
end
|
35
|
+
|
33
36
|
#
|
34
37
|
# Class methods to include
|
35
38
|
#
|
@@ -45,12 +48,20 @@ module WrapIt
|
|
45
48
|
# This method also adds getter and setter for this switch in form `name?`
|
46
49
|
# and `name=` respectively.
|
47
50
|
#
|
51
|
+
# When `html_class` option specified and switch changes its state, HTML
|
52
|
+
# class for element will be computed as follows. if `html_class` options
|
53
|
+
# is `true`, html class produced from `html_class_prefix` and `name` of
|
54
|
+
# switch. If `html_class` is a String, Symbol or Array of this types,
|
55
|
+
# html class produced as array of `html_class_prefix` and each
|
56
|
+
# `html_class` concatinations. This classes added to element if switch is
|
57
|
+
# on or removed in other case.
|
58
|
+
#
|
48
59
|
# @param name [String, Symbol] Switch name. Converted to `Symbol`.
|
49
|
-
# @param
|
50
|
-
# @options
|
51
|
-
# HTML
|
52
|
-
# or removed from element if switch id off.
|
53
|
-
# @options
|
60
|
+
# @param opts = {} [Hash] Switch options
|
61
|
+
# @options opts [true, String, Symbol, Array<String, Symbol>] :html_class
|
62
|
+
# HTML classes list that will automatically added to element if switch
|
63
|
+
# is on or removed from element if switch id off.
|
64
|
+
# @options opts [Symbol, Array<Symbol>] :aliases list of aliases.
|
54
65
|
# Warning! Values are not converted - pass only `Symbols` here.
|
55
66
|
# @yield [state] Runs block when switch state changed, gives it to block.
|
56
67
|
# @yieldparam state [Boolean] Whether switch is on or off.
|
@@ -61,23 +72,45 @@ module WrapIt
|
|
61
72
|
options.symbolize_keys!
|
62
73
|
name = name.to_sym
|
63
74
|
options.merge!(block: block, name: name)
|
75
|
+
if options.key?(:html_class)
|
76
|
+
options[:html_class] =
|
77
|
+
if options[:html_class] == true
|
78
|
+
[html_class_prefix + name.to_s]
|
79
|
+
else
|
80
|
+
HTMLClass.sanitize(options[:html_class]).map do |c|
|
81
|
+
html_class_prefix + c
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
64
85
|
names = [name] + [[options[:aliases]] || []].flatten.compact
|
65
86
|
var = "@#{name}".to_sym
|
66
87
|
define_method("#{name}?") { instance_variable_get(var) == true }
|
67
|
-
define_method("#{name}="
|
68
|
-
instance_variable_set(var, value == true)
|
69
|
-
if value == true
|
70
|
-
options.key?(:html_class) && add_html_class(options[:html_class])
|
71
|
-
block.nil? || instance_exec(true, &block)
|
72
|
-
else
|
73
|
-
options.key?(:html_class) &&
|
74
|
-
remove_html_class(options[:html_class])
|
75
|
-
block.nil? || instance_exec(false, &block)
|
76
|
-
end
|
77
|
-
end
|
88
|
+
define_method("#{name}=", &Switches.setter(name, &block))
|
78
89
|
@switches ||= {}
|
79
90
|
names.each { |n| @switches[n] = options }
|
80
91
|
end
|
81
92
|
end
|
93
|
+
|
94
|
+
private
|
95
|
+
|
96
|
+
#
|
97
|
+
# Makes switch setter block
|
98
|
+
# @param name [String] switch name
|
99
|
+
# @param &block [Proc] switch block
|
100
|
+
#
|
101
|
+
# @return [Proc] switch setter block
|
102
|
+
def self.setter(name, &block)
|
103
|
+
proc do |value|
|
104
|
+
opts = switches[name]
|
105
|
+
instance_variable_set("@#{name}", value == true)
|
106
|
+
if value == true
|
107
|
+
opts.key?(:html_class) && add_html_class(*opts[:html_class])
|
108
|
+
block.nil? || instance_exec(true, &block)
|
109
|
+
else
|
110
|
+
opts.key?(:html_class) && remove_html_class(*opts[:html_class])
|
111
|
+
block.nil? || instance_exec(false, &block)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
82
115
|
end
|
83
116
|
end
|
data/lib/wrap_it/version.rb
CHANGED
data/spec/lib/enums_spec.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe WrapIt::Enums do
|
4
|
+
it_behaves_like 'Base module'
|
5
|
+
|
4
6
|
context 'wrapper have `kind` enum' do
|
5
7
|
before { wrapper_class.class_eval { enum :kind, [:white, :black] } }
|
6
8
|
|
@@ -54,6 +56,14 @@ describe WrapIt::Enums do
|
|
54
56
|
expect(wrapper.html_class).to_not include 'test-white'
|
55
57
|
end
|
56
58
|
|
59
|
+
it 'adds and removes html class with default html_class_prefix' do
|
60
|
+
wrapper_class.class_eval do
|
61
|
+
html_class_prefix 'test-'
|
62
|
+
enum :kind, [:white, :black], html_class: true
|
63
|
+
end
|
64
|
+
expect(wrapper(:white).html_class).to include 'test-white'
|
65
|
+
end
|
66
|
+
|
57
67
|
it 'detects aliases' do
|
58
68
|
wrapper_class.class_eval do
|
59
69
|
enum :kind, [:white, :black], aliases: [:appearence]
|
data/spec/lib/html_class_spec.rb
CHANGED
@@ -1,13 +1,23 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe WrapIt::HTMLClass do
|
4
|
-
|
4
|
+
it_behaves_like 'Base module'
|
5
|
+
|
6
|
+
it 'has self.html_class and #html_class methods' do
|
5
7
|
wrapper_class.class_eval { html_class :a, [:b, 'c'] }
|
6
8
|
expect(wrapper.html_class).to eq %w(a b c)
|
7
9
|
sub_class = Class.new(wrapper_class) { html_class :a, [:d, 'e'] }
|
8
10
|
expect(sub_class.new(template).html_class).to eq %w(a d e b c)
|
9
11
|
end
|
10
12
|
|
13
|
+
it 'has self.html_class_prefix and #html_class_prefix methods' do
|
14
|
+
expect(wrapper.html_class_prefix).to eq ''
|
15
|
+
wrapper_class.class_eval { html_class_prefix 'e-' }
|
16
|
+
expect(wrapper.html_class_prefix).to eq 'e-'
|
17
|
+
sub_class = Class.new(wrapper_class)
|
18
|
+
expect(sub_class.new(template).html_class_prefix).to eq 'e-'
|
19
|
+
end
|
20
|
+
|
11
21
|
it 'has #add_html_class with chaining' do
|
12
22
|
expect(wrapper.add_html_class(:test).options[:class]).to eq %w(test)
|
13
23
|
@wrapper = nil
|
@@ -34,7 +44,7 @@ describe WrapIt::HTMLClass do
|
|
34
44
|
expect(wrapper.html_class? { |x| x[0] == 'a' }).to be_true
|
35
45
|
end
|
36
46
|
|
37
|
-
it 'has #
|
47
|
+
it 'has #no_html_class? method' do
|
38
48
|
expect(wrapper.add_html_class(:a1, :b1).no_html_class?('a2')).to be_true
|
39
49
|
expect(wrapper.no_html_class?(:a2, :b2)).to be_true
|
40
50
|
expect(wrapper.no_html_class?(:a1, :b2)).to be_false
|
@@ -60,7 +70,8 @@ describe WrapIt::HTMLClass do
|
|
60
70
|
it 'add_html_class' do
|
61
71
|
element.html_class = 'a'
|
62
72
|
element.add_html_class :b, :c, ['d', :c, :e, 'a']
|
63
|
-
expect(element.html_class).to
|
73
|
+
expect(element.html_class).to include(*%w(a b c d e))
|
74
|
+
expect(element.html_class.size).to eq 5
|
64
75
|
end
|
65
76
|
|
66
77
|
it 'remove_html_class' do
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe WrapIt::HTMLData do
|
4
|
+
it_behaves_like 'Base module'
|
5
|
+
|
6
|
+
describe '#set_html_data' do
|
7
|
+
it 'sets data' do
|
8
|
+
wrapper.set_html_data(:one, 'test')
|
9
|
+
expect(wrapper.options[:data]).to eq(one: 'test')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#remove_html_data' do
|
14
|
+
it 'removes data' do
|
15
|
+
wrapper.set_html_data(:one, 'test')
|
16
|
+
wrapper.remove_html_data(:one)
|
17
|
+
expect(wrapper.options[:data]).to be_empty
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
data/spec/lib/switches_spec.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe WrapIt::Switches do
|
4
|
+
it_behaves_like 'Base module'
|
5
|
+
|
4
6
|
context 'wrapper have `active` switch' do
|
5
7
|
before { wrapper_class.class_eval { switch :active } }
|
6
8
|
|
@@ -53,6 +55,17 @@ describe WrapIt::Switches do
|
|
53
55
|
expect(wrapper.html_class).to_not include 'active'
|
54
56
|
end
|
55
57
|
|
58
|
+
it 'adds and remove html class with html_class_prefix' do
|
59
|
+
wrapper_class.class_eval do
|
60
|
+
html_class_prefix 'btn-'
|
61
|
+
switch :active, html_class: true
|
62
|
+
switch :big, html_class: 'large'
|
63
|
+
end
|
64
|
+
expect(wrapper(:active).html_class).to include 'btn-active'
|
65
|
+
@wrapper = nil
|
66
|
+
expect(wrapper(:big).html_class).to include 'btn-large'
|
67
|
+
end
|
68
|
+
|
56
69
|
it 'detects aliases' do
|
57
70
|
wrapper_class.class_eval { switch :active, aliases: :act }
|
58
71
|
expect(wrapper(:act).active?).to be_true
|
@@ -4,11 +4,17 @@
|
|
4
4
|
# @author Alexey Ovchinnikov <alexiss@cybernetlab.ru>
|
5
5
|
#
|
6
6
|
module WrapItExampleGroup
|
7
|
+
BASE_MODULES = [WrapIt::HTMLClass, WrapIt::HTMLData, WrapIt::Switches,
|
8
|
+
WrapIt::Enums, WrapIt::Renderer]
|
9
|
+
|
7
10
|
def self.included(base)
|
8
11
|
base.instance_eval do
|
9
12
|
metadata[:type] = :wrap_it
|
10
13
|
|
11
|
-
after
|
14
|
+
after do
|
15
|
+
@successor = nil
|
16
|
+
@wrapper = nil
|
17
|
+
end
|
12
18
|
|
13
19
|
let(:template) { Object.new }
|
14
20
|
|
@@ -16,7 +22,11 @@ module WrapItExampleGroup
|
|
16
22
|
|
17
23
|
let(:wrapper_class) do
|
18
24
|
mod = described_class
|
19
|
-
|
25
|
+
if BASE_MODULES.include? mod
|
26
|
+
Class.new(WrapIt::Base)
|
27
|
+
else
|
28
|
+
Class.new(WrapIt::Base) { include mod }
|
29
|
+
end
|
20
30
|
end
|
21
31
|
end
|
22
32
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wrap_it
|
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
|
- Alexey Ovchinnikov
|
@@ -129,15 +129,14 @@ files:
|
|
129
129
|
- spec/lib/derived_attributes_spec.rb
|
130
130
|
- spec/lib/enums_spec.rb
|
131
131
|
- spec/lib/html_class_spec.rb
|
132
|
+
- spec/lib/html_data_spec.rb
|
132
133
|
- spec/lib/switches_spec.rb
|
133
134
|
- spec/rails/base_spec.rb
|
134
135
|
- spec/rails/container_spec.rb
|
135
136
|
- spec/spec_helper.rb
|
136
137
|
- spec/support/example_groups/rails_example_group.rb
|
137
138
|
- spec/support/example_groups/wrap_it_example_group.rb
|
138
|
-
-
|
139
|
-
- wrap_it-0.1.1.gem
|
140
|
-
- wrap_it-0.1.2.gem
|
139
|
+
- spec/support/shared_examples/base_module.rb
|
141
140
|
- wrap_it.gemspec
|
142
141
|
homepage: https://github.com/cybernetlab/wrap_it
|
143
142
|
licenses:
|
@@ -174,10 +173,12 @@ test_files:
|
|
174
173
|
- spec/lib/derived_attributes_spec.rb
|
175
174
|
- spec/lib/enums_spec.rb
|
176
175
|
- spec/lib/html_class_spec.rb
|
176
|
+
- spec/lib/html_data_spec.rb
|
177
177
|
- spec/lib/switches_spec.rb
|
178
178
|
- spec/rails/base_spec.rb
|
179
179
|
- spec/rails/container_spec.rb
|
180
180
|
- spec/spec_helper.rb
|
181
181
|
- spec/support/example_groups/rails_example_group.rb
|
182
182
|
- spec/support/example_groups/wrap_it_example_group.rb
|
183
|
+
- spec/support/shared_examples/base_module.rb
|
183
184
|
has_rdoc:
|
data/wrap_it-0.1.0.gem
DELETED
Binary file
|
data/wrap_it-0.1.1.gem
DELETED
Binary file
|
data/wrap_it-0.1.2.gem
DELETED
Binary file
|