wrap_it 0.1.5 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +17 -11
  3. data/.rspec +2 -0
  4. data/Gemfile +0 -3
  5. data/Gemfile.rails4 +5 -0
  6. data/Gemfile.sinatra +5 -0
  7. data/README.md +138 -24
  8. data/Rakefile +14 -1
  9. data/lib/wrap_it/base.rb +47 -20
  10. data/lib/wrap_it/callbacks.rb +10 -5
  11. data/lib/wrap_it/container.rb +91 -38
  12. data/lib/wrap_it/enums.rb +1 -1
  13. data/lib/wrap_it/frameworks.rb +24 -0
  14. data/lib/wrap_it/helpers.rb +74 -0
  15. data/lib/wrap_it/module_helpers.rb +23 -0
  16. data/lib/wrap_it/sections.rb +81 -0
  17. data/lib/wrap_it/switches.rb +11 -10
  18. data/lib/wrap_it/text_container.rb +6 -1
  19. data/lib/wrap_it/version.rb +1 -1
  20. data/lib/wrap_it.rb +9 -63
  21. data/log/development.log +174 -0
  22. data/sections_explained.md +70 -0
  23. data/spec/frameworks/log/development.log +1633 -0
  24. data/spec/frameworks/rails_app.rb +61 -0
  25. data/spec/frameworks/sinatra_app.rb +32 -0
  26. data/spec/{rails → integration}/base_spec.rb +7 -7
  27. data/spec/integration/container_spec.rb +92 -0
  28. data/spec/integration/examples_spec.rb +54 -0
  29. data/spec/integration/text_container_spec.rb +13 -0
  30. data/spec/lib/base_spec.rb +0 -6
  31. data/spec/lib/container_spec.rb +1 -6
  32. data/spec/lib/helpers_spec.rb +26 -0
  33. data/spec/lib/html_class_spec.rb +2 -2
  34. data/spec/lib/sections_spec.rb +72 -0
  35. data/spec/lib/text_container_spec.rb +19 -0
  36. data/spec/spec_helper.rb +8 -0
  37. data/spec/support/example_groups/integration_example_group.rb +72 -0
  38. data/spec/support/example_groups/wrap_it_example_group.rb +6 -4
  39. data/wrap_it.gemspec +7 -4
  40. metadata +49 -25
  41. data/spec/internal/log/test.log +0 -619
  42. data/spec/rails/container_spec.rb +0 -30
  43. data/spec/support/example_groups/rails_example_group.rb +0 -79
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 452ea9b6986b74655e20c2b05043adfee92a6f3b
4
- data.tar.gz: 5f9afcec73b2e3fcd904f918df595a3c884cce54
3
+ metadata.gz: 505e7bd562594a96b7765484ddd4332d6d6142e4
4
+ data.tar.gz: 82ff97e143fb9867e5cc0c3bb743ae28eb34bab3
5
5
  SHA512:
6
- metadata.gz: 4ced26c53ee1c80985c120ce7edde26b5a5a9306c8c37e25aee711bac374215f17a1b1dc9541bc279705cbd73664a6183e759c6c488b33ead6750a268c4b9c8a
7
- data.tar.gz: d0565411c8abde8db3f6225adf5fe814a58ba100609573c3954887a3cab6e1b971c55e698a4b27cb2ea0a6a3ca10e0919aca8f422587cace395ec6171c423703
6
+ metadata.gz: bad8623fbebe0f97ab7ca7045f9c3a167254af82240147e282ee7d7d599925106bd1ec3d21ffe0418d2defb9d1987f3a890a986575e6d12070caebbef9a02624
7
+ data.tar.gz: 8c25e53fca0f92d4ba82e2c05d32b1be2d48e869ea21f03beb8759a78aeedd1f9b72553031f4800b4ee8dc38e5c0ba5337875d0b9c602e2c404d70158ba46731
data/.gitignore CHANGED
@@ -1,12 +1,18 @@
1
- .rspec
2
- Gemfile.lock
3
-
4
-
5
- # Ignore bundler config.
6
- /.bundle
7
-
8
- # Ignore all logfiles and tempfiles.
9
- /log/*.log
10
- /tmp
11
-
12
1
  *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ Gemfile.*.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile CHANGED
@@ -2,6 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- group :test, :development do
6
- gem 'rails', require: false
7
- end
data/Gemfile.rails4 ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'rails', '~> 4'
data/Gemfile.sinatra ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'sinatra'
data/README.md CHANGED
@@ -5,22 +5,26 @@ This library provides set of classes and modules with simple DSL for quick and e
5
5
  For example, your designer makes perfect button style for some site. This element will appears in many places of site in some variations. The button have `danger`, `success` and `default` look, and can have `active` state. Button can have some icon. So, you make some CSS styles, and now you should place HTML markup of this element in many places of site. With `wrap_it` library you can do it with following code:
6
6
 
7
7
  ```ruby
8
- class PerfectButton < WrapIt::Container
9
- include TextContainer
10
- html_class 'button'
11
- enum :look, [:default, :success, :danger], html_class_prefix: 'button-'
12
- switch :active, html_class: 'button-active'
13
- child :icon, [tag: 'img', class: 'button-icon']
14
- end
8
+ WrapIt.register_module Helpers
9
+
10
+ module Helpers
11
+ class PerfectButton < WrapIt::Container
12
+ include TextContainer
13
+ html_class 'button'
14
+ enum :look, [:default, :success, :danger], html_class_prefix: 'button-'
15
+ switch :active, html_class: 'button-active'
16
+ child :icon, [tag: 'img', class: 'button-icon']
17
+ end
15
18
 
16
- WrapIt.register :p_button, 'PerfectButton'
19
+ register :p_button, 'PerfectButton'
20
+ end
17
21
  ```
18
22
 
19
23
  Now, include this helper into you template engine. For Rails:
20
24
 
21
25
  ```ruby
22
26
  class MyController < ApplicationController
23
- helper WrapIt.helpers
27
+ helper Helpers
24
28
  ...
25
29
  end
26
30
  ```
@@ -51,6 +55,8 @@ This will produce following code:
51
55
 
52
56
  Note, that lines 2 and 3 produces same html markup.
53
57
 
58
+ > **Wraning!** Module registration process changed since 0.2.0. So, if you migrate from 0.1.5, look above examples again and fix your startup code.
59
+
54
60
  # Status
55
61
 
56
62
  Project in pre-release state. First release version `1.0.0` planned to February of 2014.
@@ -81,9 +87,11 @@ Library have no specific configuration.
81
87
 
82
88
  # Usage
83
89
 
90
+ > This library actively used in [BootstrapIt](https://github.com/cybernetlab/bootstrap_it) package, so explore this project, especially it's [lib/bootstrap_it/view_helpers](https://github.com/cybernetlab/bootstrap_it/tree/master/lib/bootstrap_it/view_helpers) folder for usage examples.
91
+
84
92
  All helpers classes derived from `WrapIt::Base` class, that provides allmost all functionality. For helpers, thats includes other helpers, use `WrapIt::Container` class. Where are some library-specific methods, defined directly in `WrapIt` module.
85
93
 
86
- Simple example explained above. More complex usage is to provide some logic to initalization, capturing and rendering process. To do this, use `after` or `before` `initialize`, `capture` and `reder` callbacks respectively. Usually `after` callbacks used. `initialize` callbacks runs around arguments and optioins parsed, `capture` callbacks runs around capturing content of element and `render` callbacks runs around wrapping content into element tag.
94
+ Simple example explained above. More complex usage is to provide some logic to initalization, capturing and rendering process. To do this, use `after` or `before` `initialize`, `capture` and `reder` callbacks respectively. Usually `after` callbacks used. `initialize` callbacks runs around arguments and optioins parsing, `capture` callbacks runs around capturing element sections and `render` callbacks runs around wrapping content into element tag.
87
95
 
88
96
  Inside callbacks some usefull instance variables available.
89
97
 
@@ -93,9 +101,11 @@ Inside callbacks some usefull instance variables available.
93
101
 
94
102
  `@arguments` array available only in `after_initialize` callback and contains creation arguments. Its recommended to extract arguments, related to your class from this array if you plan to subclass your helper in future, so when subclasses `after_initialize` called these arguments will not available there.
95
103
 
96
- `@content` string available in `capture` and `render` callbacks and contains captured content. You can change it to any value. If you want to render some html markup with `@content`, use `html_safe` method (see below) to prevent HTML escaping.
104
+ Inside `capture` callback you deals with sections. This mechanism described in [Sections explained](https://github.com/cybernetlab/wrap_it/blob/master/sections_explained.md) article.
105
+
106
+ `@rendered` string available in `render` callbacks and contains rendered content. You can change it to any value. If you want to include some html markup use `html_safe` method (see below) to prevent HTML escaping.
97
107
 
98
- `@template` contains rendering template. Use this variable carefully, so if you call `@template.content_tag` or something else Rails-related, your library will not be portable to other frameworks. So, if you use this gem in user-end application, or Rails-only library, you are free to use all of `@template` methods.
108
+ `@template` contains rendering template. Use this variable carefully, so if you call `@template.link_to` or something else Rails-related, your library will not be portable to other frameworks. So, if you use this gem in user-end application, or Rails-only library, you are free to use all of `@template` methods.
99
109
 
100
110
  *Examples*
101
111
 
@@ -110,31 +120,79 @@ end
110
120
  Including some simple HTML into content
111
121
 
112
122
  ```ruby
113
- class Helper < WrapIt::Base
123
+ class IconHelper < WrapIt::Base
114
124
  after_initialize do
115
125
  @icon = optioins.delete(:icon)
116
126
  end
117
127
 
118
128
  after_capture do
119
129
  unless @icon.nil?
120
- @content = html_safe("<i class=\"#{@icon}\"></i>") + @content
130
+ self[:content] = html_safe("<i class=\"#{@icon}\"></i>")
121
131
  end
122
132
  end
123
133
  ```
124
134
 
125
135
  ## WrapIt
126
136
 
127
- #### WrapIt.register(*args)
137
+ #### WrapIt.register_module(*args)
138
+
139
+ Registers helpers module and defines `register` and `unregister` class methods in this module for registering helper methods. You can specify module to register in first argument. If ommited, anonymous module will be created and returned from method. Use `prefix` option to add specified prefix to all methods in helper module.
140
+
141
+ Typical usage of library and this method is:
142
+
143
+ Define empty module and register it with `register_method`:
144
+
145
+ ```ruby
146
+ module YourPerfectLib
147
+ module PerfectHelpers; end
148
+
149
+ WrapIt.register_module PerfectHelpers, prefix: 'perfect_'
150
+
151
+ # You can register all your helper methods right here, but in complex
152
+ # projects recommended to keep calls to register inside file where
153
+ # helper class defined.
154
+ #
155
+ # PerfectHelpers.register :button, 'YourPerfectLib::PerfectHelpers::Button'
156
+ end
157
+ ```
158
+
159
+ Describe your classes and register helper methods for it:
160
+
161
+ ```ruby
162
+ module YourPerfectLib
163
+ module PerfectHelpers
164
+ class Button < WrapIt::Base
165
+ include WrapIt::TextContainer
166
+ html_class 'button'
167
+
168
+ ...
169
+ end
170
+ end
171
+
172
+ register :button, 'YourPerfectLib::PerfectHelpers::Button'
173
+ end
174
+ ```
128
175
 
129
- Registers helper class. In arguments, first specify helper method names as `Symbols` and in last argument fully qualified helper class name as `String`.
176
+ Include it in your template (example for Rails):
130
177
 
131
- #### WrapIt.unregister(*args)
178
+ ```ruby
179
+ class MyController < ApplicationController
180
+ helper Helpers
181
+ ...
182
+ end
183
+ ```
132
184
 
133
- Unregisters helper class. Just pass list of method names as `Symbols`.
185
+ And now use it in templates:
134
186
 
135
- #### WrapIt.helpers
187
+ ```html
188
+ <%= perfect_button 'button text' %>
189
+ ```
136
190
 
137
- Returns a module, that contains all registered helpers. Usefull to provide all helpers to template engine.
191
+ will produce:
192
+
193
+ ```html
194
+ <div class="button">button text</button>
195
+ ```
138
196
 
139
197
  ## WrapIt::Base
140
198
 
@@ -166,7 +224,7 @@ When `html_class` option specified and switch changes its state, HTML class for
166
224
 
167
225
  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.
168
226
 
169
- If block given, it will be called each time switch changes its state in context of element with the switch state as argument.
227
+ If block given, it will be called each time switch changes its state in context of element with the switch state as argument. If you return `false` from this block, value is ommited.
170
228
 
171
229
  #### enum(name, options = {}, &block)
172
230
 
@@ -182,8 +240,28 @@ Also `aliases` option available. So if some of aliases founded in creation optio
182
240
 
183
241
  If block given, it will be called each time enum changes its value in context of element with the new value as argument.
184
242
 
243
+ #### section(*args)
244
+
245
+ Adds one ore more sections to element. Refer to [Sections explained](https://github.com/cybernetlab/wrap_it/blob/master/sections_explained.md) article for description.
246
+
247
+ #### place(src, dst)
248
+
249
+ Places section `src` to destination, specified in `dst` hash. `dst` is a single key-value Hash. Key can be `:before` and `:after`. Value can be `:begin`, `:end` or any section name. Refer to [Sections explained](https://github.com/cybernetlab/wrap_it/blob/master/sections_explained.md) article for description.
250
+
251
+ #### sections
252
+
253
+ Returns list of all sections, including derived from parent classes.
254
+
255
+ #### placement
256
+
257
+ Returns placed sections.
258
+
185
259
  ### Instance methods
186
260
 
261
+ #### self[name] and self[name]=
262
+
263
+ Retrieves or sets `name` section. Refer to [Sections explained](https://github.com/cybernetlab/wrap_it/blob/master/sections_explained.md) article for description.
264
+
187
265
  #### wrap(*args, &block)
188
266
 
189
267
  Wraps element with another.
@@ -258,11 +336,23 @@ Removes HTML data attribute named `name`.
258
336
 
259
337
  ## WrapIt::Container
260
338
 
339
+ This class used for elements, that can hold other elements.
340
+
341
+ At first, note, that children can be created by two ways. First - inside template and second - from code. If child created from template, you have two choises again: first to keep child in place, where it defined in template, second - to cut it from there and place together with other childs. Two variables affects on this process: `ommit_content`, defined in `WrapIt::Base` and `extarct_children`. If `ommit_content` is `true`, all content will be dropped and children placed inside `children` section. If `extract_children` is true, children also placed into `children` section, but `content` is keeped.
342
+
343
+ At second, you have two choises of moment, when children rendered. If `deffered_render` set to `false`, that is as default, all children will be rendered immideately after creation, so you can't change any of them later. If you plan to render your container after children, you chould set it to `true`, so childrens are collected in buffer and will be rendered with parent.
344
+
345
+ All children, added to container injected with `render_to` and `parent` methods, that are gives you rendering section name and container itself.
346
+
261
347
  ### DSL methods
262
348
 
263
- #### child(*args, &block)
349
+ #### child(name, *args, &block)
264
350
 
265
- Creates your own DSL method to create child items. In arguments, you should specify list of method names (aliases if more that one). Then you can specify class name for shild. If ommited, `WrapIt::Base` will be used. and as last argument you can specify array of arguments, that will be passed to child constructor. This array will be mixed with arguments, specified by user, with higher priority. At last, you can define block, that will be called after creating child, but before its rendering. This child passed as argument to block.
351
+ Creates your own DSL method to create child items. In arguments, you should specify name of method. Then you can specify class name or class itself for child. If ommited, `WrapIt::Base` will be used. All other arguments will be mixed with arguments, specified by user and passed to child constructor. **Warning!** Make shure, that your child arguments don't begins with `String` if you ommit class argument. As workaround, don't ommit class argument and specify it as 'WrapIt::Base'. At last, you can define block, that will be called after creating child, but before its rendering. This child passed as argument to block.
352
+
353
+ You can render children to section, other than `:children`. To do this, specify `section` option with section name.
354
+
355
+ Look into [lib/bootstrap_it/view_helpers](https://github.com/cybernetlab/bootstrap_it/tree/master/lib/bootstrap_it/view_helpers) folder for usage examples.
266
356
 
267
357
  # Todo
268
358
 
@@ -273,6 +363,12 @@ Creates your own DSL method to create child items. In arguments, you should spec
273
363
 
274
364
  # Changes
275
365
 
366
+ `0.2.0`
367
+ * added: sections mechanism
368
+ * many fixes
369
+ * testing improvement
370
+ * preparing testing for multiple frameworks
371
+
276
372
  `0.1.5`
277
373
  * fixed: switches and enums can damage instance variables
278
374
  * fixed: process helper_name option before initialize callbacks
@@ -297,6 +393,25 @@ Creates your own DSL method to create child items. In arguments, you should spec
297
393
  `0.1.0`
298
394
  * initial version
299
395
 
396
+ # Testing
397
+
398
+ This package developed for different frameworks, so testing is not so simple. At first, prepare testing environment with:
399
+
400
+ ```sh
401
+ bundle install
402
+ bundle install --gemfile Gemfile.rails4
403
+ bundle install --gemfile Gemfile.sinatra
404
+ ```
405
+
406
+ And then you can run tests as follows:
407
+
408
+ ```sh
409
+ FRAMEWORK=rails4 bundle exec rake spec
410
+ FRAMEWORK=sinatra bundle exec rake spec
411
+ ```
412
+
413
+ As sinatra support is in progress, its test will not pass yet.
414
+
300
415
  # License
301
416
 
302
417
  The MIT License (MIT)
@@ -320,4 +435,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
320
435
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
321
436
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
322
437
  THE SOFTWARE.
323
-
data/Rakefile CHANGED
@@ -1,6 +1,19 @@
1
+ # http://stackoverflow.com/questions/15752774/ \
2
+ # strategies-for-gem-tests-to-ensure-the-gem-works-with-rails-3-x-and-4-0
3
+
4
+ unless ENV['FRAMEWORK'].nil?
5
+ ENV['BUNDLE_GEMFILE'] = "Gemfile.#{ENV['FRAMEWORK']}"
6
+ end
7
+
8
+ begin
9
+ require 'bundler/setup'
10
+ rescue LoadError
11
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
12
+ end
13
+
1
14
  require 'bundler/gem_tasks'
2
- # require 'yard'
3
15
  require 'rspec/core/rake_task'
16
+ # require 'yard'
4
17
  # require 'rake/testtask'
5
18
 
6
19
  # Rake::TestTask.new do |t|
data/lib/wrap_it/base.rb CHANGED
@@ -24,6 +24,7 @@ module WrapIt
24
24
 
25
25
  callback :initialize, :capture, :render
26
26
 
27
+ include Sections
27
28
  include HTMLClass
28
29
  include HTMLData
29
30
  include Switches
@@ -35,6 +36,11 @@ module WrapIt
35
36
  attr_reader :tag
36
37
  attr_reader :options
37
38
 
39
+ section :content, :render_arguments, :render_block
40
+ place :content, :after, :begin
41
+ place :render_block, :after, :begin
42
+ place :render_arguments, :after, :begin
43
+
38
44
  def initialize(template, *args, &block)
39
45
  @template, @arguments, @block = template, args, block
40
46
  self.options = @arguments.extract_options!
@@ -50,8 +56,6 @@ module WrapIt
50
56
  self.class.get_derived(:@default_tag) || 'div'
51
57
  @tag = @tag.to_s
52
58
  end
53
-
54
- @arguments = nil
55
59
  end
56
60
 
57
61
  def omit_content?
@@ -72,16 +76,15 @@ module WrapIt
72
76
  # @return [String] rendered HTML for element
73
77
  def render(*args, &render_block)
74
78
  # return cached copy if it available
75
- return @content unless @content.nil?
76
- @content = empty_html
79
+ return @rendered unless @rendered.nil?
77
80
 
78
- do_capture
81
+ capture_sections
79
82
 
80
83
  # add to content string args and block result if its present
81
- args.flatten.each { |a| @content << a if a.is_a? String }
84
+ args.flatten.each { |a| self[:render_arguments] << a if a.is_a? String }
82
85
  if block_given?
83
86
  result = instance_exec(self, &render_block) || empty_html
84
- result.is_a?(String) && @content << result
87
+ result.is_a?(String) && self[:render_block] << result
85
88
  end
86
89
 
87
90
  do_render
@@ -89,10 +92,10 @@ module WrapIt
89
92
 
90
93
  if @template.output_buffer.nil?
91
94
  # when render called from code, just return content as a String
92
- @content
95
+ @rendered
93
96
  else
94
97
  # in template context, write content to templates buffer
95
- concat(@content)
98
+ concat(@rendered)
96
99
  empty_html
97
100
  end
98
101
  end
@@ -137,11 +140,15 @@ module WrapIt
137
140
 
138
141
  #
139
142
  # @dsl
140
- # Defines default tag name for element. This tag can be changed soon.
143
+ # Defines or gets default tag name for element. This tag can be changed
144
+ # soon. Without parameters returns current default_tag value.
141
145
  # @param name [<Symbol, String>] Tag name. Converted to `String`.
146
+ # @param override [Boolean] Whether to override default tag value if it
147
+ # allready exists.
142
148
  #
143
- # @return [void]
144
- def self.default_tag(name, override = true)
149
+ # @return [String] new default_tag value.
150
+ def self.default_tag(name = nil, override = true)
151
+ return @default_tag if name.nil?
145
152
  name.is_a?(String) || name.is_a?(Symbol) ||
146
153
  fail(ArgumentError, 'Tag name should be a String or Symbol')
147
154
  override ? @default_tag = name.to_s : @default_tag ||= name.to_s
@@ -162,29 +169,49 @@ module WrapIt
162
169
  @options = hash
163
170
  end
164
171
 
165
- private
166
-
167
- def do_capture
172
+ def capture_sections
168
173
  run_callbacks :capture do
169
- @content ||= empty_html
170
- unless @block.nil? || omit_content?
171
- @content << (capture(self, &@block) || empty_html)
174
+ unless @block.nil?
175
+ captured = capture(self, &@block) || empty_html
176
+ omit_content? || self[:content] << captured
172
177
  end
173
178
  end
174
179
  end
175
180
 
181
+ def render_sections(*sections)
182
+ opts = sections.extract_options!
183
+ sections.empty? && sections = self.class.sections
184
+ if opts.key?(:except)
185
+ opts[:except].is_a?(Array) || opts[:except] = [opts[:except]]
186
+ sections.reject! { |s| opts[:except].include?(s) }
187
+ end
188
+ # glew sections
189
+ self.class.placement
190
+ .select { |s| sections.include?(s) }
191
+ .reduce(empty_html) do |a, e|
192
+ a << self[e]
193
+ self[e] = empty_html
194
+ a
195
+ end
196
+ end
197
+
198
+ private
199
+
176
200
  def do_render
177
201
  # cleanup options from empty values
178
202
  @options.select! do |k, v|
179
203
  !v.nil? && (!v.respond_to?(:empty?) || !v.empty?)
180
204
  end
205
+ @rendered = render_sections
181
206
  run_callbacks :render do
182
- @content = content_tag(tag, @content, options)
207
+ @rendered = content_tag(@tag, @rendered, @options)
183
208
  end
184
209
  end
185
210
 
186
211
  def do_wrap
187
- @wrapper.is_a?(Base) && @content = @wrapper.render(html_safe(@content))
212
+ @wrapper.is_a?(Base) && @rendered = capture do
213
+ @wrapper.render(html_safe(@rendered))
214
+ end
188
215
  end
189
216
  end
190
217
  end
@@ -12,18 +12,22 @@ module WrapIt
12
12
  end
13
13
 
14
14
  def run_callbacks(name)
15
- self.class.collect_derived("@before_#{name}".to_sym).each do |cb|
15
+ self.class.collect_derived("@before_#{name}").each do |cb|
16
16
  if cb.is_a?(Symbol)
17
- send(cb)# if respond_to?(cb)
17
+ # break if send(cb) == false # if respond_to?(cb)
18
+ send(cb) # if respond_to?(cb)
18
19
  else
20
+ # break if instance_eval(&cb) == false
19
21
  instance_eval(&cb)
20
22
  end
21
23
  end
22
24
  yield if block_given?
23
- self.class.collect_derived("@after_#{name}".to_sym).reverse.each do |cb|
25
+ self.class.collect_derived("@after_#{name}").reverse.each do |cb|
24
26
  if cb.is_a?(Symbol)
25
- send(cb)# if respond_to?(cb)
27
+ # break if send(cb) == false # if respond_to?(cb)
28
+ send(cb) # if respond_to?(cb)
26
29
  else
30
+ # break if instance_eval(&cb) == false
27
31
  instance_eval(&cb)
28
32
  end
29
33
  end
@@ -55,7 +59,8 @@ module WrapIt
55
59
  else
56
60
  instance_variable_set(var, [])
57
61
  end
58
- arr << (block || method)
62
+ action = self == ancestors.first ? :unshift : :push
63
+ arr.send(action, block || method)
59
64
  instance_variable_set(var, arr)
60
65
  end
61
66
  end