wrap_it 0.2.0 → 1.0.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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -0
  3. data/.yardopts +3 -0
  4. data/README.md +67 -66
  5. data/lib/wrap_it.rb +16 -16
  6. data/lib/wrap_it/arguments.rb +368 -0
  7. data/lib/wrap_it/base.rb +56 -47
  8. data/lib/wrap_it/callbacks.rb +24 -5
  9. data/lib/wrap_it/capture_array.rb +140 -0
  10. data/lib/wrap_it/container.rb +69 -25
  11. data/lib/wrap_it/derived_attributes.rb +22 -6
  12. data/lib/wrap_it/enums.rb +44 -34
  13. data/lib/wrap_it/frameworks.rb +7 -3
  14. data/lib/wrap_it/helpers.rb +66 -1
  15. data/lib/wrap_it/html.rb +149 -0
  16. data/lib/wrap_it/html_class.rb +164 -183
  17. data/lib/wrap_it/html_data.rb +28 -15
  18. data/lib/wrap_it/link.rb +40 -17
  19. data/lib/wrap_it/sections.rb +90 -2
  20. data/lib/wrap_it/switches.rb +33 -29
  21. data/lib/wrap_it/text_container.rb +83 -10
  22. data/lib/wrap_it/version.rb +2 -1
  23. data/spec/frameworks/log/development.log +2108 -0
  24. data/spec/integration/base_spec.rb +2 -2
  25. data/spec/integration/container_spec.rb +3 -3
  26. data/spec/integration/examples_spec.rb +16 -15
  27. data/spec/integration/text_container_spec.rb +3 -3
  28. data/spec/lib/arguments_array_spec.rb +37 -27
  29. data/spec/lib/arguments_spec.rb +153 -0
  30. data/spec/lib/base_spec.rb +2 -25
  31. data/spec/lib/callbacks_spec.rb +1 -1
  32. data/spec/lib/container_spec.rb +1 -1
  33. data/spec/lib/derived_attributes_spec.rb +1 -1
  34. data/spec/lib/enums_spec.rb +2 -3
  35. data/spec/lib/html_class_spec.rb +269 -80
  36. data/spec/lib/html_data_spec.rb +18 -12
  37. data/spec/lib/html_spec.rb +124 -0
  38. data/spec/lib/link_spec.rb +2 -2
  39. data/spec/lib/sections_spec.rb +1 -1
  40. data/spec/lib/switches_spec.rb +3 -3
  41. data/spec/lib/text_container_spec.rb +2 -2
  42. data/spec/support/example_groups/{wrap_it_example_group.rb → wrapped_example_group.rb} +5 -5
  43. data/wrap_it.gemspec +2 -0
  44. metadata +15 -8
  45. data/lib/wrap_it/arguments_array.rb +0 -128
  46. data/lib/wrap_it/module_helpers.rb +0 -23
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe WrapIt::Link do
3
+ describe WrapIt::Link, type: :wrapped do
4
4
  it 'has `a` tag by default' do
5
5
  expect(successor.tag).to eq 'a'
6
6
  end
@@ -20,6 +20,6 @@ describe WrapIt::Link do
20
20
 
21
21
  it 'takes href from second string arg if no block given' do
22
22
  expect(successor('text', 'url').href).to eq 'url'
23
- expect(successor.instance_variable_get(:@body)).to eq 'text'
23
+ expect(successor.body).to eq 'text'
24
24
  end
25
25
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe WrapIt::Sections do
3
+ describe WrapIt::Sections, type: :wrapped do
4
4
  it_behaves_like 'Base module'
5
5
 
6
6
  describe 'self.section' do
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe WrapIt::Switches do
3
+ describe WrapIt::Switches, type: :wrapped do
4
4
  it_behaves_like 'Base module'
5
5
 
6
6
  context 'wrapper have `active` switch' do
@@ -24,12 +24,12 @@ describe WrapIt::Switches do
24
24
  expect(wrapper(active: true).active?).to be_true
25
25
  @wrapper = nil
26
26
  expect(wrapper(active: false).active?).to be_false
27
- expect(wrapper.options).to_not include :active
27
+ expect(wrapper.html_attr).to_not include :active
28
28
  end
29
29
 
30
30
  it 'runs block' do
31
31
  wrapper_class.class_eval do
32
- switch(:active) { |x| add_html_class(x.to_s) }
32
+ switch(:active) { |x| html_class << x.to_s }
33
33
  end
34
34
  expect(wrapper(:active).html_class).to include 'true'
35
35
  @wrapper = nil
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe WrapIt::TextContainer do
3
+ describe WrapIt::TextContainer, type: :wrapped do
4
4
  it { expect(wrapper_class.default_tag).to eq 'p' }
5
5
 
6
6
  %i(text body).each do |option|
@@ -9,7 +9,7 @@ describe WrapIt::TextContainer do
9
9
  end
10
10
 
11
11
  it "cleanups `#{option}` for options" do
12
- expect(wrapper(option => 'text').options).to_not include option
12
+ expect(wrapper(option => 'text').html_attr).to_not include option
13
13
  end
14
14
  end
15
15
 
@@ -3,9 +3,9 @@
3
3
  #
4
4
  # @author Alexey Ovchinnikov <alexiss@cybernetlab.ru>
5
5
  #
6
- module WrapItExampleGroup
7
- BASE_MODULES = [WrapIt::HTMLClass, WrapIt::HTMLData, WrapIt::Switches,
8
- WrapIt::Enums, WrapIt::Renderer, WrapIt::Sections]
6
+ module WrappedExampleGroup
7
+ BASE_MODULES = [WrapIt::HTML, WrapIt::Switches, WrapIt::Enums,
8
+ WrapIt::Renderer, WrapIt::Sections, WrapIt::Arguments]
9
9
 
10
10
  def self.included(base)
11
11
  base.instance_eval do
@@ -44,8 +44,8 @@ module WrapItExampleGroup
44
44
  RSpec.configure do |config|
45
45
  config.include(
46
46
  self,
47
- type: :wrap_it,
48
- example_group: { file_path: /spec/ }
47
+ type: :wrapped,
48
+ example_group: { file_path: /spec\/(wrapped|integration)/ }
49
49
  )
50
50
  end
51
51
  end
data/wrap_it.gemspec CHANGED
@@ -3,6 +3,8 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require 'wrap_it/version'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
+ spec.required_ruby_version = '>= 2.0.0'
7
+
6
8
  spec.name = 'wrap_it'
7
9
  spec.version = WrapIt::VERSION
8
10
  spec.authors = ['Alexey Ovchinnikov']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wrap_it
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey Ovchinnikov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-20 00:00:00.000000000 Z
11
+ date: 2014-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -104,6 +104,8 @@ files:
104
104
  - .gitignore
105
105
  - .rspec
106
106
  - .rubocop.yml
107
+ - .ruby-version
108
+ - .yardopts
107
109
  - Gemfile
108
110
  - Gemfile.rails4
109
111
  - Gemfile.sinatra
@@ -111,18 +113,19 @@ files:
111
113
  - Rakefile
112
114
  - config.ru
113
115
  - lib/wrap_it.rb
114
- - lib/wrap_it/arguments_array.rb
116
+ - lib/wrap_it/arguments.rb
115
117
  - lib/wrap_it/base.rb
116
118
  - lib/wrap_it/callbacks.rb
119
+ - lib/wrap_it/capture_array.rb
117
120
  - lib/wrap_it/container.rb
118
121
  - lib/wrap_it/derived_attributes.rb
119
122
  - lib/wrap_it/enums.rb
120
123
  - lib/wrap_it/frameworks.rb
121
124
  - lib/wrap_it/helpers.rb
125
+ - lib/wrap_it/html.rb
122
126
  - lib/wrap_it/html_class.rb
123
127
  - lib/wrap_it/html_data.rb
124
128
  - lib/wrap_it/link.rb
125
- - lib/wrap_it/module_helpers.rb
126
129
  - lib/wrap_it/no_rails.rb
127
130
  - lib/wrap_it/rails.rb
128
131
  - lib/wrap_it/sections.rb
@@ -139,6 +142,7 @@ files:
139
142
  - spec/integration/examples_spec.rb
140
143
  - spec/integration/text_container_spec.rb
141
144
  - spec/lib/arguments_array_spec.rb
145
+ - spec/lib/arguments_spec.rb
142
146
  - spec/lib/base_spec.rb
143
147
  - spec/lib/callbacks_spec.rb
144
148
  - spec/lib/container_spec.rb
@@ -147,13 +151,14 @@ files:
147
151
  - spec/lib/helpers_spec.rb
148
152
  - spec/lib/html_class_spec.rb
149
153
  - spec/lib/html_data_spec.rb
154
+ - spec/lib/html_spec.rb
150
155
  - spec/lib/link_spec.rb
151
156
  - spec/lib/sections_spec.rb
152
157
  - spec/lib/switches_spec.rb
153
158
  - spec/lib/text_container_spec.rb
154
159
  - spec/spec_helper.rb
155
160
  - spec/support/example_groups/integration_example_group.rb
156
- - spec/support/example_groups/wrap_it_example_group.rb
161
+ - spec/support/example_groups/wrapped_example_group.rb
157
162
  - spec/support/shared_examples/base_module.rb
158
163
  - wrap_it.gemspec
159
164
  homepage: https://github.com/cybernetlab/wrap_it
@@ -169,7 +174,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
169
174
  requirements:
170
175
  - - '>='
171
176
  - !ruby/object:Gem::Version
172
- version: '0'
177
+ version: 2.0.0
173
178
  required_rubygems_version: !ruby/object:Gem::Requirement
174
179
  requirements:
175
180
  - - '>='
@@ -177,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
182
  version: '0'
178
183
  requirements: []
179
184
  rubyforge_project:
180
- rubygems_version: 2.2.1
185
+ rubygems_version: 2.0.14
181
186
  signing_key:
182
187
  specification_version: 4
183
188
  summary: This library provides set of classes and modules with simple DSL for quick
@@ -192,6 +197,7 @@ test_files:
192
197
  - spec/integration/examples_spec.rb
193
198
  - spec/integration/text_container_spec.rb
194
199
  - spec/lib/arguments_array_spec.rb
200
+ - spec/lib/arguments_spec.rb
195
201
  - spec/lib/base_spec.rb
196
202
  - spec/lib/callbacks_spec.rb
197
203
  - spec/lib/container_spec.rb
@@ -200,12 +206,13 @@ test_files:
200
206
  - spec/lib/helpers_spec.rb
201
207
  - spec/lib/html_class_spec.rb
202
208
  - spec/lib/html_data_spec.rb
209
+ - spec/lib/html_spec.rb
203
210
  - spec/lib/link_spec.rb
204
211
  - spec/lib/sections_spec.rb
205
212
  - spec/lib/switches_spec.rb
206
213
  - spec/lib/text_container_spec.rb
207
214
  - spec/spec_helper.rb
208
215
  - spec/support/example_groups/integration_example_group.rb
209
- - spec/support/example_groups/wrap_it_example_group.rb
216
+ - spec/support/example_groups/wrapped_example_group.rb
210
217
  - spec/support/shared_examples/base_module.rb
211
218
  has_rdoc:
@@ -1,128 +0,0 @@
1
- module WrapIt
2
- #
3
- # Adds #extract! and #extarct_first! methods to array. Theese methods are
4
- # extracts items from array by some condirions and returns its as separate
5
- # array for #extract! and as first item for #extract_first!.
6
- #
7
- # @author Alexey Ovchinnikov <alexiss@cybernetlab.ru>
8
- #
9
- module ArgumentsArray
10
- REQUIRED_METHODS = %i(reject! find_index delete_at)
11
-
12
- def self.included(base)
13
- methods = base.methods
14
- # avoid including in classes thats doen't have methods, used in
15
- # inplementation
16
- REQUIRED_METHODS.all? { |m| methods.include?(m) } || fail(
17
- TypeError,
18
- "#{self.class.name} can't be included into #{base.class.name}"
19
- )
20
- end
21
- #
22
- # Extracts elements from array by conditions, passed in arguments nad
23
- # returns theese elements as new array.
24
- #
25
- # Condition can be Regexp, class, Array and any other value. If condition
26
- # is `Regexp`, all elements of array are tested for matching to this
27
- # regexp, previously converted to String by their `to_s` method. If
28
- # condition is an `Array`, all elements tested if it included in these
29
- # array. If the condition is a class, then elements are tested via `is_a?`
30
- # method for this class. For any other value, elements are tested with
31
- # equality operator `==`.
32
- #
33
- # You can provide a block. In this case, all arguments are ignored, and
34
- # block yielded for each element of array. If block returns `true`,
35
- # element extracted from array.
36
- #
37
- # All conditions, passed as arguments are `or`-ed so `String, Symbol` means
38
- # select Symbol or String elements.
39
- #
40
- # @overload extract!([condition, ..., options])
41
- # @param [Object] condition one of `or`-ed conditions for comparing
42
- # @param [Hash] options options for axtracting
43
- # @options options [Object, Array] :and one or array of `and`-ed conditions
44
- #
45
- # @overload extract!(&block)
46
- # @yield [element] Gives each element of array to block. You should return
47
- # `true` to extract this element or `false` to keep it in array.
48
- # @yieldparam [Object] element element of array to inspect
49
- # @yieldreturn [Boolean] whether exclude this element or not
50
- #
51
- # @return [Array] array of extracted elements
52
- #
53
- # @example extract by class
54
- # arr = [1, 2, 3, 'and', 'string']
55
- # arr.extend WrapIt::ArgumentsArray
56
- # arr.extract(String) #=> ['and', 'string']
57
- # arr #=> [1, 2, 3]
58
- #
59
- # @example extract by value
60
- # arr = [1, 2, 3, 'and', 'string']
61
- # arr.extend WrapIt::ArgumentsArray
62
- # arr.extract(1, 2) #=> [1, 2]
63
- # arr #=> [3, 'and', 'string']
64
- #
65
- # @example extract by Regexp
66
- # arr = [1, 2, 3, 'and', 'string', :str]
67
- # arr.extend WrapIt::ArgumentsArray
68
- # arr.extract(/^str/) #=> ['string', :str]
69
- # arr #=> [1, 2, 3, 'and']
70
- #
71
- # @example extract by Array
72
- # arr = [1, 2, 3, 'and', 'string']
73
- # arr.extend WrapIt::ArgumentsArray
74
- # arr.extract([1, 10, 'and']) #=> [1, 'and']
75
- # arr #=> [2, 3, 'string']
76
- #
77
- # @example extract by block
78
- # arr = [1, 2, 3, 'and', 'string']
79
- # arr.extend WrapIt::ArgumentsArray
80
- # arr.extract {|x| x < 3} #=> [1, 2]
81
- # arr #=> [3, 'and', 'string']
82
- #
83
- # @example extract with `and` condition
84
- # arr = [1, 2, 3, 'and', 'string', :str]
85
- # arr.extend WrapIt::ArgumentsArray
86
- # arr.extract(String, and: [/^str/]) #=> ['string']
87
- # arr #=> [1, 2, 3, 'and', :str]
88
- def extract!(*args, &block)
89
- extracted = []
90
- reject! do |arg|
91
- do_compare(arg, *args, &block) && extracted << arg && true
92
- end
93
- extracted
94
- end
95
-
96
- #
97
- # Extracts first element from array that is satisfy conditions, passed in
98
- # arguments and returns these element.
99
- #
100
- # @see #extract!
101
- def extract_first!(*args, &block)
102
- index = find_index { |arg| do_compare(arg, *args, &block) }
103
- index.nil? ? nil : delete_at(index)
104
- end
105
-
106
- private
107
-
108
- def do_compare(target, *compare_args)
109
- if block_given?
110
- yield target
111
- else
112
- options = compare_args.extract_options!
113
- result = compare_args.any? do |dest|
114
- case
115
- when dest.is_a?(Array) then dest.include?(target)
116
- when dest.is_a?(Regexp) then dest.match(target.to_s)
117
- when dest.is_a?(Class) then target.is_a?(dest)
118
- else dest == target
119
- end
120
- end
121
- if options[:and].is_a?(Array)
122
- result &&= do_compare(target, *options[:and])
123
- end
124
- result
125
- end
126
- end
127
- end
128
- end
@@ -1,23 +0,0 @@
1
- module WrapIt
2
- module ModuleHelpers
3
- def self.included(base)
4
- base.extend(ClassMethods)
5
- end
6
-
7
- module ClassMethods
8
- def placement(name)
9
- define_method(
10
- "#{name}_placement", &ModuleHelpers.placement_block(name)
11
- )
12
- end
13
- end
14
-
15
- private
16
-
17
- def placement_block(name)
18
- proc do |hash = {before: :content}|
19
-
20
- end
21
- end
22
- end
23
- end