blocks 3.0.0.rc4 → 3.0.0.rc5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -2
  3. data/.ruby-version +1 -0
  4. data/.travis.yml +3 -0
  5. data/CHANGELOG.rdoc +7 -0
  6. data/Gemfile +10 -3
  7. data/README.md +25 -9
  8. data/_config.yml +20 -0
  9. data/bin/deploy_docs +2 -0
  10. data/docs/.gitignore +4 -0
  11. data/docs/404.html +23 -0
  12. data/docs/_includes/acknowledgements.md +13 -0
  13. data/docs/_includes/caller-id.md +3 -0
  14. data/docs/_includes/configuration.md +3 -0
  15. data/docs/_includes/custom-builders.md +3 -0
  16. data/docs/_includes/defining.md +615 -0
  17. data/docs/_includes/demos/hooks-and-wrappers-output.html +109 -0
  18. data/docs/_includes/hooks.md +1156 -0
  19. data/docs/_includes/installation.md +25 -0
  20. data/docs/_includes/introduction.md +18 -0
  21. data/docs/_includes/option-merging.md +5 -0
  22. data/docs/_includes/rendering.md +622 -0
  23. data/docs/_includes/reserved-keywords.md +59 -0
  24. data/docs/_includes/skipping.md +403 -0
  25. data/docs/_includes/slate/assets.html +34 -0
  26. data/docs/_includes/slate/language-tabs.html +11 -0
  27. data/docs/_includes/templating.md +48 -0
  28. data/docs/_includes/templating/bootstrap_4_cards.md +753 -0
  29. data/docs/_includes/use-cases.md +23 -0
  30. data/docs/_includes/wip.md +34 -0
  31. data/docs/_includes/wrappers.md +629 -0
  32. data/docs/_layouts/slate.html +75 -0
  33. data/docs/_plugins/gem_version.rb +11 -0
  34. data/docs/_plugins/highlight_with_div.rb +25 -0
  35. data/docs/_sass/_default_styling.scss +627 -0
  36. data/docs/_sass/_icon-font.scss +26 -0
  37. data/docs/_sass/_normalize.scss +427 -0
  38. data/docs/_sass/_styling_overrides.scss +31 -0
  39. data/docs/_sass/_syntax.scss +78 -0
  40. data/docs/_sass/_variable_overrides.scss +10 -0
  41. data/docs/_sass/_variables.scss +105 -0
  42. data/docs/assets/javascripts/script.js +18 -0
  43. data/docs/assets/stylesheets/formChanges.less +106 -0
  44. data/docs/assets/stylesheets/style.css +46 -0
  45. data/docs/fonts/slate.eot +0 -0
  46. data/docs/fonts/slate.svg +14 -0
  47. data/docs/fonts/slate.ttf +0 -0
  48. data/docs/fonts/slate.woff +0 -0
  49. data/docs/fonts/slate.woff2 +0 -0
  50. data/docs/hooks.html +149 -0
  51. data/docs/hooks_and_wrappers_demo.html +313 -0
  52. data/docs/images/favicon.ico +0 -0
  53. data/docs/images/logo.png +0 -0
  54. data/docs/images/navbar.png +0 -0
  55. data/docs/images/placeholder.jpg +0 -0
  56. data/docs/images/render_strategies.png +0 -0
  57. data/docs/images/templating.png +0 -0
  58. data/docs/index.md +32 -0
  59. data/docs/javascripts/all.js +4 -0
  60. data/docs/javascripts/all_nosearch.js +3 -0
  61. data/docs/javascripts/app/lang.js +166 -0
  62. data/docs/javascripts/app/search.js +75 -0
  63. data/docs/javascripts/app/toc.js +57 -0
  64. data/docs/javascripts/demos/hooks_and_wrappers.js +9 -0
  65. data/docs/javascripts/lib/energize.js +169 -0
  66. data/docs/javascripts/lib/imagesloaded.min.js +7 -0
  67. data/docs/javascripts/lib/jquery.highlight.js +108 -0
  68. data/docs/javascripts/lib/jquery.js +9831 -0
  69. data/docs/javascripts/lib/jquery.tocify.js +1042 -0
  70. data/docs/javascripts/lib/jquery_ui.js +566 -0
  71. data/docs/javascripts/lib/lunr.js +1910 -0
  72. data/docs/stylesheets/demos/hooks_and_wrappers.scss +32 -0
  73. data/docs/stylesheets/print.scss +150 -0
  74. data/docs/stylesheets/screen.scss +10 -0
  75. data/lib/blocks/action_view_extensions/view_extensions.rb +1 -0
  76. data/lib/blocks/renderers/renderer.rb +1 -0
  77. data/lib/blocks/renderers/runtime_context.rb +30 -17
  78. data/lib/blocks/utilities/hash_with_render_strategy.rb +3 -0
  79. data/lib/blocks/version.rb +1 -1
  80. metadata +70 -2
@@ -0,0 +1,23 @@
1
+ # Use Cases
2
+
3
+ TODO
4
+
5
+ ## Removing the Logic from the View
6
+
7
+ TODO
8
+
9
+ ## Building Reusable UI Components
10
+
11
+ TODO
12
+
13
+ ## Revamping Rails Layouts
14
+
15
+ TODO
16
+
17
+ ## A/B Testing
18
+
19
+ TODO
20
+
21
+ ## Themes
22
+
23
+ TODO
@@ -0,0 +1,34 @@
1
+ <!-- Defining multiple blocks at once -->
2
+ ## Multiple Blocks at Once
3
+
4
+ ```haml
5
+ - namer = Proc.new {|i| "block #{i}" }
6
+ blocks.define_each ["a", 1, "b"],
7
+ namer do |item|
8
+ ="Hello from #{item}"
9
+ &br
10
+
11
+ = blocks.render("block a")
12
+ = blocks.render("block 1")
13
+ = blocks.render("block b")
14
+ ```
15
+
16
+ ```ruby
17
+ # where builder is an instance of
18
+ # Blocks::Builder
19
+ namer = Proc.new {|i| "block #{i}" }
20
+ builder.define_each ["a", 1, "b"],
21
+ namer do |item|
22
+ "Hello from #{item}<br>".html_safe
23
+ end
24
+
25
+ builder.render("block a") +
26
+ builder.render("block 1") +
27
+ builder.render("block b")
28
+ ```
29
+
30
+ Multiple different blocks may be defined at once using the #define_each method.
31
+
32
+ #define_each expects at least two parameters: the collection and a proc that can be used to calculate the block name. The proc must at least one parameter, the first being the item in the collection.
33
+
34
+ The method also expects either an options hash designating the render strategy or a Ruby block.
@@ -0,0 +1,629 @@
1
+ # Wrapping Blocks
2
+
3
+ Wrappers work similarly to hooks with a few notable exceptions:
4
+
5
+ 1. Wrappers are singular in nature. While there are three different wrappers that may be applied to a block, only one of each may be applied.
6
+ 2. They are defined directly on the block themselves or provided to the render call.
7
+
8
+ Wrappers may be defined with either the name of another block, method, or a Proc. That block, method, or Proc must be prepared to take at least one argument, which is the content_block to call when the wrapper is ready to yield control to the content it is wrapping.
9
+
10
+ <aside class="notice">
11
+ Like hooks, wrappers will still render even if there is no associated block to be rendered.
12
+ </aside>
13
+
14
+ ## "wrap_all" Wrapper
15
+
16
+ ```erb
17
+ <% blocks.define :wrap_all do |c, o| %>
18
+ Wrap All Start
19
+ <%= c.call %>
20
+ <br>Wrap All End
21
+ <% end %>
22
+
23
+ <% blocks.define :wrap_each do |c, i, o| %>
24
+ <% if o.nil?; o = i; i = nil end %>
25
+ <br>Wrap Each Start <%= i %><br>
26
+ <%= c.call %>
27
+ <br>Wrap Each End <%= i %>
28
+ <% end %>
29
+
30
+ <% blocks.around_all :my_block do |c, o| %>
31
+ Around All Start<br>
32
+ <%= c.call %>
33
+ <br>Around All End<br>
34
+ <% end %>
35
+
36
+ <% blocks.define :my_block,
37
+ wrap_all: :wrap_all,
38
+ wrap_each: :wrap_each do %>
39
+ content
40
+ <% end %>
41
+
42
+ With Collection:
43
+ <br>
44
+ <%= blocks.render :my_block,
45
+ collection: ["a", "b"] %>
46
+ <br>
47
+ No Collection:
48
+ <br>
49
+ <%= blocks.render :my_block %>
50
+
51
+ <!-- OR -->
52
+ With Collection:
53
+ <br>
54
+ <%= blocks.render :my_block,
55
+ wrap_all: :wrap_all,
56
+ wrap_each: :wrap_each,
57
+ collection: ["a", "b"] %>
58
+ <br>
59
+ No Collection:
60
+ <br>
61
+ <%= blocks.render :my_block,
62
+ wrap_all: :wrap_all,
63
+ wrap_each: :wrap_each %>
64
+ ```
65
+
66
+ ```haml
67
+ - blocks.define :wrap_all do |c, o|
68
+ Wrap All Start
69
+ = c.call
70
+ %br
71
+ Wrap All End
72
+
73
+ - blocks.define :wrap_each do |c, i, o|
74
+ - if o.nil?; o = i; i = nil end
75
+ %br
76
+ Wrap Each Start
77
+ = i
78
+ %br
79
+ = c.call
80
+ %br
81
+ Wrap Each End
82
+ = i
83
+
84
+ - blocks.around_all :my_block do |c, o|
85
+ Around All Start
86
+ %br
87
+ = c.call
88
+ %br
89
+ Around All End
90
+ %br
91
+
92
+ - blocks.define :my_block,
93
+ wrap_all: :wrap_all,
94
+ wrap_each: :wrap_each do
95
+ content
96
+
97
+ With Collection:
98
+ %br
99
+ = blocks.render :my_block,
100
+ collection: ["a", "b"]
101
+ %br
102
+ No Collection:
103
+ %br
104
+ = blocks.render :my_block
105
+
106
+ #- OR
107
+ With Collection:
108
+ %br
109
+ = blocks.render :my_block,
110
+ wrap_all: :wrap_all,
111
+ wrap_each: :wrap_each,
112
+ collection: ["a", "b"]
113
+ %br
114
+ No Collection:
115
+ %br
116
+ = blocks.render :my_block,
117
+ wrap_all: :wrap_all,
118
+ wrap_each: :wrap_each
119
+ ```
120
+
121
+ ```ruby
122
+ # where builder is an instance
123
+ # of Blocks::Builder
124
+ builder.define :wrap_all do |c, o|
125
+ "Wrap All Start" +
126
+ c.call +
127
+ "<br>Wrap All End".html_safe
128
+ end
129
+
130
+ builder.define :wrap_each do |c, i, o|
131
+ if o.nil?
132
+ o = i
133
+ i = nil
134
+ end
135
+ "<br>Wrap Each Start #{i}<br>".html_safe +
136
+ c.call +
137
+ "<br>Wrap Each End #{i}".html_safe
138
+ end
139
+
140
+ builder.around_all :my_block do |c, o|
141
+ "Around All Start<br>".html_safe +
142
+ c.call +
143
+ "<br>Around All End<br>".html_safe
144
+ end
145
+
146
+ builder.define :my_block,
147
+ wrap_all: :wrap_all,
148
+ wrap_each: :wrap_each do
149
+ "content"
150
+ end
151
+
152
+ "With Collection:<br>".html_safe +
153
+ builder.render(:my_block,
154
+ collection: ["a", "b"]) +
155
+ "<br>No Collection:<br>".html_safe +
156
+ builder.render(:my_block)
157
+
158
+ # OR
159
+ "With Collection:<br>".html_safe +
160
+ builder.render(:my_block,
161
+ wrap_all: :wrap_all,
162
+ wrap_each: :wrap_each,
163
+ collection: ["a", "b"]) +
164
+ "<br>No Collection:<br>".html_safe +
165
+ builder.render(:my_block,
166
+ wrap_all: :wrap_all,
167
+ wrap_each: :wrap_each)
168
+ ```
169
+
170
+ > The above code will output the following:
171
+
172
+ ```
173
+ With Collection:
174
+ Around All Start
175
+ Wrap All Start
176
+ Wrap Each Start a
177
+ content
178
+ Wrap Each End a
179
+ Wrap Each Start b
180
+ content
181
+ Wrap Each End b
182
+ Wrap All End
183
+ Around All End
184
+
185
+ No Collection:
186
+ Around All Start
187
+ Wrap All Start
188
+ Wrap Each Start
189
+ content
190
+ Wrap Each End
191
+ Wrap All End
192
+ Around All End
193
+ ```
194
+
195
+ "wrap_all" is a wrapper that surrounds content just inside any "around_all" hooks and around a potential "wrap_each" wrapper (or multiple "wrap_each" wrappers if rendering a collection).
196
+
197
+ ## "wrap_each" Wrapper
198
+
199
+ ```erb
200
+ <% blocks.define :wrap_all do |c, o| %>
201
+ Wrap All Start
202
+ <%= c.call %>
203
+ <br>Wrap All End<br>
204
+ <% end %>
205
+
206
+ <% blocks.define :wrap_each do |c, i, o| %>
207
+ <% if o.nil?; o = i; i = nil end %>
208
+ <br>Wrap Each Start <%= i %><br>
209
+ <%= c.call %>
210
+ <br>Wrap Each End <%= i %>
211
+ <% end %>
212
+
213
+ <% blocks.around :my_block do |c, o| %>
214
+ Around Start<br>
215
+ <%= c.call %>
216
+ <br>Around End
217
+ <% end %>
218
+
219
+ <% blocks.define :my_block,
220
+ wrap_all: :wrap_all,
221
+ wrap_each: :wrap_each do %>
222
+ content
223
+ <% end %>
224
+
225
+ With Collection:
226
+ <br>
227
+ <%= blocks.render :my_block,
228
+ collection: ["a", "b"] %>
229
+ <br>
230
+ No Collection:
231
+ <br>
232
+ <%= blocks.render :my_block %>
233
+
234
+ <!-- OR -->
235
+ With Collection:
236
+ <br>
237
+ <%= blocks.render :my_block,
238
+ wrap_all: :wrap_all,
239
+ wrap_each: :wrap_each,
240
+ collection: ["a", "b"] %>
241
+ <br>
242
+ No Collection:
243
+ <br>
244
+ <%= blocks.render :my_block,
245
+ wrap_all: :wrap_all,
246
+ wrap_each: :wrap_each %>
247
+ ```
248
+
249
+ ```haml
250
+ - blocks.define :wrap_all do |c, o|
251
+ Wrap All Start
252
+ = c.call
253
+ %br
254
+ Wrap All End
255
+ %br
256
+
257
+ - blocks.define :wrap_each do |c, i, o|
258
+ - if o.nil?; o = i; i = nil end
259
+ %br
260
+ Wrap Each Start
261
+ = i
262
+ %br
263
+ = c.call
264
+ %br
265
+ Wrap Each End
266
+ = i
267
+
268
+ - blocks.around :my_block do |c, o|
269
+ Around Start
270
+ %br
271
+ = c.call
272
+ %br
273
+ Around End
274
+
275
+ - blocks.define :my_block,
276
+ wrap_all: :wrap_all,
277
+ wrap_each: :wrap_each do
278
+ content
279
+
280
+ With Collection:
281
+ %br
282
+ = blocks.render :my_block,
283
+ collection: ["a", "b"]
284
+ %br
285
+ No Collection:
286
+ %br
287
+ = blocks.render :my_block
288
+
289
+ #- OR
290
+ With Collection:
291
+ %br
292
+ = blocks.render :my_block,
293
+ wrap_all: :wrap_all,
294
+ wrap_each: :wrap_each,
295
+ collection: ["a", "b"]
296
+ %br
297
+ No Collection:
298
+ %br
299
+ = blocks.render :my_block,
300
+ wrap_all: :wrap_all,
301
+ wrap_each: :wrap_each
302
+ ```
303
+
304
+ ```ruby
305
+ # where builder is an instance
306
+ # of Blocks::Builder
307
+ builder.define :wrap_all do |c, o|
308
+ "Wrap All Start" +
309
+ c.call +
310
+ "<br>Wrap All End".html_safe
311
+ end
312
+
313
+ builder.define :wrap_each do |c, i, o|
314
+ if o.nil?
315
+ o = i
316
+ i = nil
317
+ end
318
+ "<br>Wrap Each Start #{i}<br>".html_safe +
319
+ c.call +
320
+ "<br>Wrap Each End #{i}<br>".html_safe
321
+ end
322
+
323
+ builder.around :my_block do |c, o|
324
+ "Around Start<br>".html_safe +
325
+ c.call +
326
+ "<br>Around End".html_safe
327
+ end
328
+
329
+ builder.define :my_block,
330
+ wrap_all: :wrap_all,
331
+ wrap_each: :wrap_each do
332
+ "content"
333
+ end
334
+
335
+ "With Collection:<br>".html_safe +
336
+ builder.render(:my_block,
337
+ collection: ["a", "b"]) +
338
+ "<br>No Collection:<br>".html_safe +
339
+ builder.render(:my_block)
340
+
341
+ # OR
342
+ "With Collection:<br>".html_safe +
343
+ builder.render(:my_block,
344
+ wrap_all: :wrap_all,
345
+ wrap_each: :wrap_each,
346
+ collection: ["a", "b"]) +
347
+ "<br>No Collection:<br>".html_safe +
348
+ builder.render(:my_block,
349
+ wrap_all: :wrap_all,
350
+ wrap_each: :wrap_each)
351
+ ```
352
+
353
+ > The above code will output the following:
354
+
355
+ ```
356
+ With Collection:
357
+ With Collection:
358
+ Wrap All Start
359
+ Wrap Each Start a
360
+ Around Start
361
+ content
362
+ Around End
363
+ Wrap Each End a
364
+ Wrap Each Start b
365
+ Around Start
366
+ content
367
+ Around End
368
+ Wrap Each End b
369
+ Wrap All End
370
+
371
+ No Collection:
372
+ Wrap All Start
373
+ Wrap Each Start
374
+ Around Start
375
+ content
376
+ Around End
377
+ Wrap Each End
378
+ Wrap All End
379
+ ```
380
+
381
+ *Also aliased to "outer_wrapper"*
382
+
383
+ When a collection is involved, the "wrap_each" wrapper will wrap each item in the collection with this wrapper, and all of these wrappers can be wrapped together using the "wrap_all" wrapper.
384
+
385
+ When no collection is involved, the "wrap_each" wrapper will simply act as another wrapper that can be wrapped within the "wrap_all" wrapper and just outside any "wrap_each" wrappers.
386
+
387
+ ## "wrap_with" Wrapper
388
+
389
+ ```erb
390
+ <% blocks.surround :my_block do |c, i| %>
391
+ <% i = nil if i.is_a?(Blocks::RuntimeContext) %>
392
+ Surround Start <%= i %><br>
393
+ <%= c.call %>
394
+ <br>Surround End <%= i %>
395
+ <% end %>
396
+
397
+ <% blocks.define :wrap_with do |c, i| %>
398
+ <% i = nil if i.is_a?(Blocks::RuntimeContext) %>
399
+ Wrap With Start <%= i %><br>
400
+ <%= c.call %>
401
+ <br>Wrap Wrap End <%= i %>
402
+ <% end %>
403
+
404
+ <% blocks.before :my_block do |i| %>
405
+ <% i = nil if i.is_a?(Blocks::RuntimeContext) %>
406
+ Before <%= i %><br>
407
+ <% end %>
408
+
409
+ <% blocks.after :my_block do |i| %>
410
+ <% i = nil if i.is_a?(Blocks::RuntimeContext) %>
411
+ <br>After <%= i %><br>
412
+ <% end %>
413
+
414
+ <% blocks.define :my_block,
415
+ wrap_with: :wrap_with do %>
416
+ content
417
+ <% end %>
418
+
419
+ With Collection:
420
+ <br>
421
+ <%= blocks.render :my_block,
422
+ collection: ["a", "b"] %>
423
+ <br>
424
+ No Collection:
425
+ <br>
426
+ <%= blocks.render :my_block %>
427
+
428
+ <!-- OR -->
429
+ With Collection:
430
+ <br>
431
+ <%= blocks.render :my_block,
432
+ wrap_with: :wrap_with,
433
+ collection: ["a", "b"] %>
434
+ <br>
435
+ No Collection:
436
+ <br>
437
+ <%= blocks.render :my_block,
438
+ wrap_with: :wrap_with %>
439
+ ```
440
+
441
+ ```haml
442
+ - blocks.surround :my_block do |c, i|
443
+ - i = nil if i.is_a?(Blocks::RuntimeContext)
444
+ Surround Start
445
+ = i
446
+ %br
447
+ = c.call
448
+ %br
449
+ Surround End
450
+ = i
451
+
452
+
453
+ - blocks.define :wrap_with do |c, i|
454
+ - i = nil if i.is_a?(Blocks::RuntimeContext)
455
+ Wrap With Start
456
+ = i
457
+ %br
458
+ = c.call
459
+ %br
460
+ Wrap Wrap End
461
+ = i
462
+
463
+ - blocks.before :my_block do |i|
464
+ - i = nil if i.is_a?(Blocks::RuntimeContext)
465
+ Before
466
+ = i
467
+ %br
468
+
469
+ - blocks.after :my_block do |i|
470
+ - i = nil if i.is_a?(Blocks::RuntimeContext)
471
+ %br
472
+ After
473
+ = i
474
+ %br
475
+
476
+ - blocks.define :my_block,
477
+ wrap_with: :wrap_with do
478
+ content
479
+
480
+ With Collection:
481
+ %br
482
+ = blocks.render :my_block,
483
+ collection: ["a", "b"]
484
+ %br
485
+ No Collection:
486
+ %br
487
+ = blocks.render :my_block
488
+
489
+ -# OR
490
+ With Collection:
491
+ %br
492
+ = blocks.render :my_block,
493
+ wrap_with: :wrap_with,
494
+ collection: ["a", "b"]
495
+ %br
496
+ No Collection:
497
+ %br
498
+ = blocks.render :my_block,
499
+ wrap_with: :wrap_with
500
+ ```
501
+
502
+ ```ruby
503
+ # where builder is an instance
504
+ # of Blocks::Builder
505
+ builder.surround :my_block do |c, i|
506
+ i = nil if i.is_a?(Blocks::RuntimeContext)
507
+ "Surround Start #{i}<br>".html_safe +
508
+ c.call +
509
+ "<br>Surround End #{i}".html_safe
510
+ end
511
+
512
+ builder.define :wrap_with do |c, i|
513
+ i = nil if i.is_a?(Blocks::RuntimeContext)
514
+ "Wrap With Start #{i}<br>".html_safe +
515
+ c.call +
516
+ "<br>Wrap Wrap End #{i}".html_safe
517
+ end
518
+
519
+ builder.before :my_block do |i|
520
+ i = nil if i.is_a?(Blocks::RuntimeContext)
521
+ "Before #{i}<br>".html_safe
522
+ end
523
+
524
+ builder.after :my_block do |i|
525
+ i = nil if i.is_a?(Blocks::RuntimeContext)
526
+ "<br>After #{i}<br>".html_safe
527
+ end
528
+
529
+ builder.define :my_block,
530
+ wrap_with: :wrap_with do
531
+ "content"
532
+ end
533
+
534
+ "With Collection:<br>".html_safe
535
+ builder.render(:my_block,
536
+ wrap_with: :wrap_with,
537
+ collection: ["a", "b"]) +
538
+ "<br>No Collection:<br>".html_safe +
539
+ builder.render(:my_block,
540
+ wrap_with: :wrap_with)
541
+
542
+ # OR
543
+ "With Collection:<br>".html_safe
544
+ builder.render(:my_block,
545
+ wrap_with: :wrap_with,
546
+ collection: ["a", "b"]) +
547
+ "<br>No Collection:<br>".html_safe +
548
+ builder.render(:my_block,
549
+ wrap_with: :wrap_with)
550
+ ```
551
+
552
+ > The above code will output the following:
553
+
554
+ ```
555
+ With Collection:
556
+ Before a
557
+ Wrap With Start a
558
+ Surround Start a
559
+ content
560
+ Surround End a
561
+ Wrap Wrap End a
562
+ After a
563
+ Before b
564
+ Wrap With Start b
565
+ Surround Start b
566
+ content
567
+ Surround End b
568
+ Wrap Wrap End b
569
+ After b
570
+
571
+ No Collection:
572
+ Before
573
+ Wrap With Start
574
+ Surround Start
575
+ content
576
+ Surround End
577
+ Wrap Wrap End
578
+ After
579
+ ```
580
+
581
+ *Also aliased to "wrap", "wrapper", and "inner_wrapper"*
582
+
583
+ The "wrap_with" wrapper is preceded by "before" hooks, followed by "after" hooks, surrounded by "around" hooks, and wraps around "surround" hooks.
584
+
585
+ ## Defining a wrapper with a Proc
586
+
587
+ Wrappers can also be defined with Procs. The Proc must take, at a minimum, the content_block that they are wrapping, as the first argument. They may optionally take the options hash as their second argument.
588
+
589
+ ```erb
590
+ <% wrapper = Proc.new do |b| %>
591
+ <div>
592
+ <%= b.call %>
593
+ </div>
594
+ <% end %>
595
+ <% blocks.define :my_block,
596
+ wrapper: wrapper %>
597
+ <%= blocks.render :my_block do %>
598
+ Hello
599
+ <% end %>
600
+ ```
601
+
602
+ ```haml
603
+ - wrapper = Proc.new do |b|
604
+ %div= b.call
605
+ - blocks.define :my_block,
606
+ wrapper: wrapper
607
+ = blocks.render :my_block do
608
+ Hello
609
+ ```
610
+
611
+ ```ruby
612
+ # where builder is an instance
613
+ # of Blocks::Builder
614
+ wrapper = Proc.new do |b|
615
+ builder.content_tag :div, &b
616
+ end
617
+
618
+ builder.define :my_block,
619
+ wrapper: wrapper
620
+ builder.render :my_block do
621
+ "Hello"
622
+ end
623
+ ```
624
+
625
+ > The above code will output the following
626
+
627
+ ```html
628
+ <div>Hello</div>
629
+ ```