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,109 @@
1
+ <div id="blocks">
2
+ <div class="before_all2 bg-danger hide">
3
+ Second Before All
4
+ </div>
5
+ <div class="before_all1 bg-danger hide">
6
+ First Before All
7
+ </div>
8
+ <div class="around_all2">
9
+ Second Around All
10
+ <div class="around_all1">
11
+ First Around All
12
+ <div class="container-wrapper">
13
+ Test Block Wrapper for all
14
+ <div class="item-wrapper">
15
+ Test Block Wrapper for each item
16
+ <div class="around2">
17
+ Second Around for item 1
18
+ <div class="around1">
19
+ First Around for item 1
20
+ <div class="before2 bg-success hide">
21
+ Second Before for item 1
22
+ </div>
23
+ <div class="before1 bg-success hide">
24
+ First Before for item 1
25
+ </div>
26
+ <div class="wrapper">
27
+ Test Block Wrapper for item 1
28
+ <div class="surround2">
29
+ Second Surround for item 1
30
+ <div class="surround1">
31
+ First Surround for item 1
32
+ <div class="prepend2 bg-primary hide">Second Prepended block 1</div>
33
+ <div class="prepend1 bg-primary hide">First Prepended block 1</div>
34
+ <div id="actual_block" class="bg-primary">Actual block 1</div>
35
+ <div class="append1 bg-primary hide">First Appended block 1</div>
36
+ <div class="append2 bg-primary hide">Second Appended block 1</div>
37
+
38
+ </div>
39
+
40
+ </div>
41
+
42
+ </div>
43
+ <div class="after1 bg-success hide">
44
+ First After for item 1
45
+ </div>
46
+ <div class="after2 bg-success hide">
47
+ Second After for item 1
48
+ </div>
49
+
50
+ </div>
51
+
52
+ </div>
53
+
54
+ </div>
55
+ <div class="item-wrapper">
56
+ Test Block Wrapper for each item
57
+ <div class="around2">
58
+ Second Around for item 2
59
+ <div class="around1">
60
+ First Around for item 2
61
+ <div class="before2 bg-success hide">
62
+ Second Before for item 2
63
+ </div>
64
+ <div class="before1 bg-success hide">
65
+ First Before for item 2
66
+ </div>
67
+ <div class="wrapper">
68
+ Test Block Wrapper for item 2
69
+ <div class="surround2">
70
+ Second Surround for item 2
71
+ <div class="surround1">
72
+ First Surround for item 2
73
+ <div class="prepend2 bg-primary hide">Second Prepended block 2</div>
74
+ <div class="prepend1 bg-primary hide">First Prepended block 2</div>
75
+ <div id="actual_block" class="bg-primary">Actual block 2</div>
76
+ <div class="append1 bg-primary hide">First Appended block 2</div>
77
+ <div class="append2 bg-primary hide">Second Appended block 2</div>
78
+
79
+ </div>
80
+
81
+ </div>
82
+
83
+ </div>
84
+ <div class="after1 bg-success hide">
85
+ First After for item 2
86
+ </div>
87
+ <div class="after2 bg-success hide">
88
+ Second After for item 2
89
+ </div>
90
+
91
+ </div>
92
+
93
+ </div>
94
+
95
+ </div>
96
+
97
+ </div>
98
+
99
+ </div>
100
+
101
+ </div>
102
+ <div class="after_all1 bg-danger hide">
103
+ First After All
104
+ </div>
105
+ <div class="after_all2 bg-danger hide">
106
+ Second After All
107
+ </div>
108
+
109
+ </div>
@@ -0,0 +1,1156 @@
1
+ # Hooking Blocks
2
+
3
+ ```
4
+ "before_all" hooks
5
+ "around_all" hooks
6
+ "around" hooks
7
+ "before" hooks
8
+ "surround" hook
9
+ "prepend" hooks
10
+ block
11
+ "append" hooks
12
+ "after" hooks
13
+ "after_all" hooks
14
+ ```
15
+
16
+ Hooks may be registered for a specific block that render additional code in relation to the block when the block is rendered.
17
+
18
+ There is no limit to the number of hooks that may be registered for a block, and multiple hooks may be registered of the same hook type for a block.
19
+
20
+ <aside class="notice">
21
+ Hooks will still render even if there is no associated block to be rendered.
22
+ </aside>
23
+
24
+ Hooks fall into three categories:
25
+
26
+ ## Before Hooks
27
+
28
+ Before hooks render code before their corresponding block renders.
29
+
30
+ <aside class="warning">
31
+ All Before hooks of a given type will render in reverse order from the order in which they are registered.
32
+ </aside>
33
+
34
+ There are three levels of "before" hooks:
35
+
36
+ ### "prepend" Hooks
37
+
38
+ ```erb
39
+ <% blocks.prepend :my_block do %>
40
+ "prepend" call 1
41
+ <br>
42
+ <% end %>
43
+
44
+ <% blocks.surround :my_block do |b| %>
45
+ "surround" call before
46
+ <br>
47
+ <%= b.call %>
48
+ "surround" call after
49
+ <br>
50
+ <% end %>
51
+
52
+ <% blocks.prepend :my_block do %>
53
+ "prepend" call 2
54
+ <br>
55
+ <% end %>
56
+
57
+ <%= blocks.render :my_block do %>
58
+ "my_block" content
59
+ <br>
60
+ <% end %>
61
+ ```
62
+
63
+ ```haml
64
+ - blocks.prepend :my_block do
65
+ "prepend" call 1
66
+ %br
67
+
68
+ - blocks.surround :my_block do |b|
69
+ "surround" call before
70
+ %br
71
+ = b.call
72
+ "surround" call after
73
+ %br
74
+
75
+ - blocks.prepend :my_block do
76
+ "prepend" call 2
77
+ %br
78
+
79
+ = blocks.render :my_block do
80
+ "my_block" content
81
+ %br
82
+ ```
83
+
84
+ ```ruby
85
+ # where builder is an instance
86
+ # of Blocks::Builder
87
+ builder.prepend :my_block do
88
+ '"prepend" call 1' +
89
+ builder.content_tag(:br)
90
+ end
91
+
92
+ builder.surround :my_block do |b|
93
+ '"surround" call before' +
94
+ builder.content_tag(:br) +
95
+ b.call +
96
+ '"surround" call after' +
97
+ builder.content_tag(:br)
98
+ end
99
+
100
+ builder.prepend :my_block do
101
+ '"prepend" call 2' +
102
+ builder.content_tag(:br)
103
+ end
104
+
105
+ builder.render :my_block do
106
+ '"my_block" content' +
107
+ builder.content_tag(:br)
108
+ end
109
+ ```
110
+
111
+ > The output will be:
112
+
113
+ ```html
114
+ "surround" call before
115
+ "prepend" call 2
116
+ "prepend" call 1
117
+ "my_block" content
118
+ "surround" call after
119
+ ```
120
+
121
+ "prepend" hooks render content that immediately precedes the block content itself.
122
+
123
+ They render in closest proximity to the block along with the their sibling "append" hooks.
124
+
125
+ Together with the block content itself and the sibling "append" hooks, they can be surrounded with "surround" calls.
126
+
127
+ <aside class="notice">
128
+ Take note that the second "prepend" call content rendered first and that the "surround" call surrounded all the prepended content as well as the content block itself.
129
+ </aside>
130
+
131
+ ### "before" Hooks
132
+
133
+ ```erb
134
+ <% blocks.before :my_block do %>
135
+ "before" call 1
136
+ <br>
137
+ <% end %>
138
+
139
+ <% blocks.surround :my_block do |b| %>
140
+ "surround" call before
141
+ <br>
142
+ <%= b.call %>
143
+ "surround" call after
144
+ <br>
145
+ <% end %>
146
+
147
+ <% blocks.around :my_block do |b| %>
148
+ "Around" call before
149
+ <br>
150
+ <%= b.call %>
151
+ "Around" call after
152
+ <br>
153
+ <% end %>
154
+
155
+ <% blocks.before :my_block do %>
156
+ "before" call 2
157
+ <br>
158
+ <% end %>
159
+
160
+ <%= blocks.render :my_block do %>
161
+ "my_block" content
162
+ <br>
163
+ <% end %>
164
+ ```
165
+
166
+ ```haml
167
+ - blocks.before :my_block do
168
+ "before" call 1
169
+ %br
170
+
171
+ - blocks.surround :my_block do |b|
172
+ "surround" call before
173
+ %br
174
+ = b.call
175
+ "surround" call after
176
+ %br
177
+
178
+ - blocks.around :my_block do |b|
179
+ "around" call before
180
+ %br
181
+ = b.call
182
+ "around" call after
183
+ %br
184
+
185
+ - blocks.before :my_block do
186
+ "before" call 2
187
+ %br
188
+
189
+ = blocks.render :my_block do
190
+ "my_block" content
191
+ %br
192
+ ```
193
+
194
+ ```ruby
195
+ # where builder is an instance
196
+ # of Blocks::Builder
197
+ builder.before :my_block do
198
+ '"before" call 1' +
199
+ builder.content_tag(:br)
200
+ end
201
+
202
+ builder.surround :my_block do |b|
203
+ '"surround" call before' +
204
+ builder.content_tag(:br) +
205
+ b.call +
206
+ '"surround" call after' +
207
+ builder.content_tag(:br)
208
+ end
209
+
210
+ builder.around :my_block do |b|
211
+ '"around" call before' +
212
+ builder.content_tag(:br) +
213
+ b.call +
214
+ '"around" call after' +
215
+ builder.content_tag(:br)
216
+ end
217
+
218
+ builder.before :my_block do
219
+ '"before" call 2' +
220
+ builder.content_tag(:br)
221
+ end
222
+
223
+ builder.render :my_block do
224
+ '"my_block" content' +
225
+ builder.content_tag(:br)
226
+ end
227
+ ```
228
+
229
+ > The output will be:
230
+
231
+ ```html
232
+ "around" call before
233
+ "before" call 2
234
+ "before" call 1
235
+ "surround" call before
236
+ "my_block" content
237
+ "surround" call after
238
+ "around" call after
239
+ ```
240
+
241
+ "before" hooks render content before "surround" hooks.
242
+
243
+ Together with the all "surround" content and the sibling "after" hooks, they can be surrounded with "around" calls.
244
+
245
+ <aside class="notice">
246
+ Take note that the second "before" call content rendered first and that the "around" call surrounded all the before content as well as the surrounded content.
247
+ </aside>
248
+
249
+ ### "before_all" Hooks
250
+
251
+ ```erb
252
+ <% blocks.before_all :my_block do %>
253
+ "before" call 1
254
+ <br>
255
+ <% end %>
256
+
257
+ <% blocks.around_all :my_block do |b| %>
258
+ "around_all" call before
259
+ <br>
260
+ <%= b.call %>
261
+ "around_all" call after
262
+ <br>
263
+ <% end %>
264
+
265
+ <% blocks.before_all :my_block do %>
266
+ "before_all" call 2
267
+ <br>
268
+ <% end %>
269
+
270
+ <%= blocks.render :my_block do %>
271
+ "my_block" content
272
+ <br>
273
+ <% end %>
274
+ ```
275
+
276
+ ```haml
277
+ - blocks.before_all :my_block do
278
+ "before_all" call 1
279
+ %br
280
+
281
+ - blocks.around_all :my_block do |b|
282
+ "around_all" call before
283
+ %br
284
+ = b.call
285
+ "around_all" call after
286
+ %br
287
+
288
+ - blocks.before_all :my_block do
289
+ "before_all" call 2
290
+ %br
291
+
292
+ = blocks.render :my_block do
293
+ "my_block" content
294
+ %br
295
+ ```
296
+
297
+ ```ruby
298
+ # where builder is an instance
299
+ # of Blocks::Builder
300
+ builder.before :my_block do
301
+ '"before" call 1' +
302
+ builder.content_tag(:br)
303
+ end
304
+
305
+ builder.surround :my_block do |b|
306
+ '"surround" call before' +
307
+ builder.content_tag(:br) +
308
+ b.call +
309
+ '"surround" call after' +
310
+ builder.content_tag(:br)
311
+ end
312
+
313
+ builder.around :my_block do |b|
314
+ '"around" call before' +
315
+ builder.content_tag(:br) +
316
+ b.call +
317
+ '"around" call after' +
318
+ builder.content_tag(:br)
319
+ end
320
+
321
+ builder.before :my_block do
322
+ '"before" call 2' +
323
+ builder.content_tag(:br)
324
+ end
325
+
326
+ builder.render :my_block do
327
+ '"my_block" content' +
328
+ builder.content_tag(:br)
329
+ end
330
+ ```
331
+
332
+ > The output will be:
333
+
334
+ ```html
335
+ "before_all" call 2
336
+ "before_all" call 1
337
+ "around_all" call before
338
+ "my_block" content
339
+ "around_all" call after
340
+ ```
341
+
342
+ "before_all" hooks render content before anything else, including any "around_all" hooks.
343
+
344
+ <aside class="notice">
345
+ Take note that the second "before_all" call content rendered first before anything else including the "around_all" hook.
346
+ </aside>
347
+
348
+ ## After Hooks
349
+
350
+ After hooks render code before their corresponding block renders.
351
+
352
+ <aside class="warning">
353
+ Unlike "Before" and "Around" hooks, "After" hooks of a given type will render in the order in which they are registered.
354
+ </aside>
355
+
356
+ There are three levels of "after" hooks:
357
+
358
+ ### "append" Hooks
359
+
360
+ ```erb
361
+ <% blocks.append :my_block do %>
362
+ "append" call 1
363
+ <br>
364
+ <% end %>
365
+
366
+ <% blocks.surround :my_block do |b| %>
367
+ "surround" call before
368
+ <br>
369
+ <%= b.call %>
370
+ "surround" call after
371
+ <br>
372
+ <% end %>
373
+
374
+ <% blocks.append :my_block do %>
375
+ "append" call 2
376
+ <br>
377
+ <% end %>
378
+
379
+ <%= blocks.render :my_block do %>
380
+ "my_block" content
381
+ <br>
382
+ <% end %>
383
+ ```
384
+
385
+ ```haml
386
+ - blocks.append :my_block do
387
+ "append" call 1
388
+ %br
389
+
390
+ - blocks.surround :my_block do |b|
391
+ "surround" call before
392
+ %br
393
+ = b.call
394
+ "surround" call after
395
+ %br
396
+
397
+ - blocks.append :my_block do
398
+ "append" call 2
399
+ %br
400
+
401
+ = blocks.render :my_block do
402
+ "my_block" content
403
+ %br
404
+ ```
405
+
406
+ ```ruby
407
+ # where builder is an instance
408
+ # of Blocks::Builder
409
+ builder.append :my_block do
410
+ '"prepend" call 1' +
411
+ builder.content_tag(:br)
412
+ end
413
+
414
+ builder.surround :my_block do |b|
415
+ '"surround" call before' +
416
+ builder.content_tag(:br) +
417
+ b.call +
418
+ '"surround" call after' +
419
+ builder.content_tag(:br)
420
+ end
421
+
422
+ builder.append :my_block do
423
+ '"prepend" call 2' +
424
+ builder.content_tag(:br)
425
+ end
426
+
427
+ builder.render :my_block do
428
+ '"my_block" content' +
429
+ builder.content_tag(:br)
430
+ end
431
+ ```
432
+
433
+ > The output will be:
434
+
435
+ ```html
436
+ "surround" call before
437
+ "my_block" content
438
+ "append" call 1
439
+ "append" call 2
440
+ "surround" call after
441
+ ```
442
+
443
+ "append" hooks render content that immediately follows the block content itself.
444
+
445
+ They render in closest proximity to the block along with the their sibling "prepend" hooks.
446
+
447
+ Together with the block content itself and the sibling "prepend" hooks, they can be surrounded with "surround" calls.
448
+
449
+ <aside class="notice">
450
+ Take note that the second "append" call content rendered after the first and that the "surround" call surrounded all the appended content as well as the content block itself.
451
+ </aside>
452
+
453
+ ### "after" Hooks
454
+
455
+ ```erb
456
+ <% blocks.after :my_block do %>
457
+ "after" call 1
458
+ <br>
459
+ <% end %>
460
+
461
+ <% blocks.surround :my_block do |b| %>
462
+ "surround" call before
463
+ <br>
464
+ <%= b.call %>
465
+ "surround" call after
466
+ <br>
467
+ <% end %>
468
+
469
+ <% blocks.around :my_block do |b| %>
470
+ "Around" call before
471
+ <br>
472
+ <%= b.call %>
473
+ "Around" call after
474
+ <br>
475
+ <% end %>
476
+
477
+ <% blocks.after :my_block do %>
478
+ "after" call 2
479
+ <br>
480
+ <% end %>
481
+
482
+ <%= blocks.render :my_block do %>
483
+ "my_block" content
484
+ <br>
485
+ <% end %>
486
+ ```
487
+
488
+ ```haml
489
+ - blocks.after :my_block do
490
+ "after" call 1
491
+ %br
492
+
493
+ - blocks.surround :my_block do |b|
494
+ "surround" call before
495
+ %br
496
+ = b.call
497
+ "surround" call after
498
+ %br
499
+
500
+ - blocks.around :my_block do |b|
501
+ "around" call before
502
+ %br
503
+ = b.call
504
+ "around" call after
505
+ %br
506
+
507
+ - blocks.after :my_block do
508
+ "after" call 2
509
+ %br
510
+
511
+ = blocks.render :my_block do
512
+ "my_block" content
513
+ %br
514
+ ```
515
+
516
+ ```ruby
517
+ # where builder is an instance
518
+ # of Blocks::Builder
519
+ builder.after :my_block do
520
+ '"after" call 1' +
521
+ builder.content_tag(:br)
522
+ end
523
+
524
+ builder.surround :my_block do |b|
525
+ '"surround" call before' +
526
+ builder.content_tag(:br) +
527
+ b.call +
528
+ '"surround" call after' +
529
+ builder.content_tag(:br)
530
+ end
531
+
532
+ builder.around :my_block do |b|
533
+ '"around" call before' +
534
+ builder.content_tag(:br) +
535
+ b.call +
536
+ '"around" call after' +
537
+ builder.content_tag(:br)
538
+ end
539
+
540
+ builder.after :my_block do
541
+ '"after" call 2' +
542
+ builder.content_tag(:br)
543
+ end
544
+
545
+ builder.render :my_block do
546
+ '"my_block" content' +
547
+ builder.content_tag(:br)
548
+ end
549
+ ```
550
+
551
+ > The output will be:
552
+
553
+ ```html
554
+ "around" call before
555
+ "surround" call before
556
+ "my_block" content
557
+ "surround" call after
558
+ "after" call 1
559
+ "after" call 2
560
+ "around" call after
561
+ ```
562
+
563
+ "after" hooks render content after "surround" hooks.
564
+
565
+ Together with the all "surround" content and the sibling "before" hooks, they can be surrounded with "around" calls.
566
+
567
+ <aside class="notice">
568
+ Take note that the second "after" call content rendered after the first and that the "around" call surrounded all the after content as well as the surrounded content.
569
+ </aside>
570
+
571
+ ### "after_all" Hooks
572
+
573
+ ```erb
574
+ <% blocks.after_all :my_block do %>
575
+ "after_all" call 1
576
+ <br>
577
+ <% end %>
578
+
579
+ <% blocks.around_all :my_block do |b| %>
580
+ "around_all" call before
581
+ <br>
582
+ <%= b.call %>
583
+ "around_all" call after
584
+ <br>
585
+ <% end %>
586
+
587
+ <% blocks.after_all :my_block do %>
588
+ "after_all" call 2
589
+ <br>
590
+ <% end %>
591
+
592
+ <%= blocks.render :my_block do %>
593
+ "my_block" content
594
+ <br>
595
+ <% end %>
596
+ ```
597
+
598
+ ```haml
599
+ - blocks.after_all :my_block do
600
+ "after_all" call 1
601
+ %br
602
+
603
+ - blocks.around_all :my_block do |b|
604
+ "around_all" call before
605
+ %br
606
+ = b.call
607
+ "around_all" call after
608
+ %br
609
+
610
+ - blocks.after_all :my_block do
611
+ "after_all" call 2
612
+ %br
613
+
614
+ = blocks.render :my_block do
615
+ "my_block" content
616
+ %br
617
+ ```
618
+
619
+ ```ruby
620
+ # where builder is an instance
621
+ # of Blocks::Builder
622
+ builder.after_all :my_block do
623
+ '"after_all" call 1' +
624
+ builder.content_tag(:br)
625
+ end
626
+
627
+ builder.surround :my_block do |b|
628
+ '"surround" call before' +
629
+ builder.content_tag(:br) +
630
+ b.call +
631
+ '"surround" call after' +
632
+ builder.content_tag(:br)
633
+ end
634
+
635
+ builder.around :my_block do |b|
636
+ '"around" call before' +
637
+ builder.content_tag(:br) +
638
+ b.call +
639
+ '"around" call after' +
640
+ builder.content_tag(:br)
641
+ end
642
+
643
+ builder.after_all :my_block do
644
+ '"after_all" call 2' +
645
+ builder.content_tag(:br)
646
+ end
647
+
648
+ builder.render :my_block do
649
+ '"my_block" content' +
650
+ builder.content_tag(:br)
651
+ end
652
+ ```
653
+
654
+ > The output will be:
655
+
656
+ ```html
657
+ "around_all" call before
658
+ "my_block" content
659
+ "around_all" call after
660
+ "after_all" call 1
661
+ "after_all" call 2
662
+ ```
663
+
664
+ "after_all" hooks render content after anything else, including any "around_all" hooks.
665
+
666
+ <aside class="notice">
667
+ Take note that the second "after_all" call content rendered after everything else.
668
+ </aside>
669
+
670
+ ## Around Hooks
671
+
672
+ Around hooks render code around their corresponding block, allowing the hook to render code before the block renders, pass control over to the rendering block, and then regain control once the block has rendered.
673
+
674
+ <aside class="warning">
675
+ Around hooks are expected to be provided a block which takes a block as its first argument. They should "call" that block when they are ready to pass control to the content they are surrounding.
676
+ </aside>
677
+
678
+ <aside class="warning">
679
+ All around hooks of a given type will render in reverse order from the order in which they are registered.
680
+ </aside>
681
+
682
+ There are three levels of around hooks:
683
+
684
+ ### "surround" Hooks
685
+
686
+ ```erb
687
+ <% blocks.prepend :my_block do %>
688
+ "prepend" call
689
+ <br>
690
+ <% end %>
691
+
692
+ <% blocks.before :my_block do %>
693
+ "before" call
694
+ <br>
695
+ <% end %>
696
+
697
+ <% blocks.append :my_block do %>
698
+ "append" call
699
+ <br>
700
+ <% end %>
701
+
702
+ <% blocks.after :my_block do %>
703
+ "after" call
704
+ <br>
705
+ <% end %>
706
+
707
+ <% blocks.surround :my_block do |b| %>
708
+ "surround" call 1 before
709
+ <br>
710
+ <%= b.call %>
711
+ "surround" call 1 after
712
+ <br>
713
+ <% end %>
714
+
715
+ <% blocks.surround :my_block do |b| %>
716
+ "surround" call 2 before
717
+ <br>
718
+ <%= b.call %>
719
+ "surround" call 2 after
720
+ <br>
721
+ <% end %>
722
+
723
+ <%= blocks.render :my_block do %>
724
+ "my_block" content
725
+ <br>
726
+ <% end %>
727
+ ```
728
+
729
+ ```haml
730
+ - blocks.prepend :my_block do
731
+ "prepend" call
732
+ %br
733
+
734
+ - blocks.before :my_block do
735
+ "before" call
736
+ %br
737
+
738
+ - blocks.append :my_block do
739
+ "append" call
740
+ %br
741
+
742
+ - blocks.after :my_block do
743
+ "after" call
744
+ %br
745
+
746
+ - blocks.surround :my_block do |b|
747
+ "surround" call 1 before
748
+ %br
749
+ = b.call
750
+ "surround" call 1 after
751
+ %br
752
+
753
+ - blocks.surround :my_block do |b|
754
+ "surround" call 2 before
755
+ %br
756
+ = b.call
757
+ "surround" call 2 after
758
+ %br
759
+
760
+ = blocks.render :my_block do
761
+ "my_block" content
762
+ %br
763
+ ```
764
+
765
+ ```ruby
766
+ # where builder is an instance
767
+ # of Blocks::Builder
768
+ builder.prepend :my_block do
769
+ '"prepend" call' +
770
+ builder.content_tag(:br)
771
+ end
772
+
773
+ builder.before :my_block do
774
+ '"before" call' +
775
+ builder.content_tag(:br)
776
+ end
777
+
778
+ builder.append :my_block do
779
+ '"append" call' +
780
+ builder.content_tag(:br)
781
+ end
782
+
783
+ builder.after :my_block do
784
+ '"after" call' +
785
+ builder.content_tag(:br)
786
+ end
787
+
788
+ builder.surround :my_block do |b|
789
+ '"surround" call 1 before' +
790
+ builder.content_tag(:br) +
791
+ b.call +
792
+ '"surround" call 1 after' +
793
+ builder.content_tag(:br)
794
+ end
795
+
796
+ builder.surround :my_block do |b|
797
+ '"surround" call 2 before' +
798
+ builder.content_tag(:br) +
799
+ b.call +
800
+ '"surround" call 2 after' +
801
+ builder.content_tag(:br)
802
+ end
803
+
804
+ builder.render :my_block do
805
+ '"my_block" content' +
806
+ builder.content_tag(:br)
807
+ end
808
+ ```
809
+
810
+ > The output will be:
811
+
812
+ ```html
813
+ "before" call
814
+ "surround" call 2 before
815
+ "surround" call 1 before
816
+ "prepend" call
817
+ "my_block" content
818
+ "append" call
819
+ "surround" call 1 after
820
+ "surround" call 2 after
821
+ "after" call
822
+ ```
823
+
824
+ "surround" hooks render content that surround the combination of "prepend" hooks, the block content, and "append" hooks. The can be preceded by "before" hooks and followed by "after" hooks.
825
+
826
+ <aside class="notice">
827
+ Take note that the second "surround" call content rendered around the first.
828
+ </aside>
829
+
830
+ ### "around" Hooks
831
+
832
+ ```erb
833
+ <% blocks.before :my_block do %>
834
+ "before" call
835
+ <br>
836
+ <% end %>
837
+
838
+ <% blocks.after :my_block do %>
839
+ "after" call
840
+ <br>
841
+ <% end %>
842
+
843
+ <% blocks.around :my_block do |b| %>
844
+ "around" call 1 before
845
+ <br>
846
+ <%= b.call %>
847
+ "around" call 1 after
848
+ <br>
849
+ <% end %>
850
+
851
+ <% blocks.around_all :my_block do |b| %>
852
+ "around_all" call before
853
+ <br>
854
+ <%= b.call %>
855
+ "around_all" call after
856
+ <br>
857
+ <% end %>
858
+
859
+ <% blocks.around :my_block do |b| %>
860
+ "around" call 2 before
861
+ <br>
862
+ <%= b.call %>
863
+ "around" call 2 after
864
+ <br>
865
+ <% end %>
866
+
867
+ <%= blocks.render :my_block do %>
868
+ "my_block" content
869
+ <br>
870
+ <% end %>
871
+ ```
872
+
873
+ ```haml
874
+ - blocks.before :my_block do
875
+ "before" call
876
+ %br
877
+
878
+ - blocks.after :my_block do
879
+ "after" call
880
+ %br
881
+
882
+ - blocks.around :my_block do |b|
883
+ "around" call 1 before
884
+ %br
885
+ = b.call
886
+ "around" call 1 after
887
+ %br
888
+
889
+ - blocks.around_all :my_block do |b|
890
+ "around_all" call before
891
+ %br
892
+ = b.call
893
+ "around_all" call after
894
+ %br
895
+
896
+ - blocks.around :my_block do |b|
897
+ "around" call 2 before
898
+ %br
899
+ = b.call
900
+ "around" call 2 after
901
+ %br
902
+
903
+ = blocks.render :my_block do
904
+ "my_block" content
905
+ %br
906
+ ```
907
+
908
+ ```ruby
909
+ # where builder is an instance
910
+ # of Blocks::Builder
911
+ builder.before :my_block do
912
+ '"before" call' +
913
+ builder.content_tag(:br)
914
+ end
915
+
916
+ builder.after :my_block do
917
+ '"after" call' +
918
+ builder.content_tag(:br)
919
+ end
920
+
921
+ builder.around :my_block do |b|
922
+ '"around" call 1 before' +
923
+ builder.content_tag(:br) +
924
+ b.call +
925
+ '"around" call 1 after' +
926
+ builder.content_tag(:br)
927
+ end
928
+
929
+ builder.around_all :my_block do |b|
930
+ '"around_all" call before' +
931
+ builder.content_tag(:br) +
932
+ b.call +
933
+ '"around_all" call after' +
934
+ builder.content_tag(:br)
935
+ end
936
+
937
+ builder.around :my_block do |b|
938
+ '"around" call 2 before' +
939
+ builder.content_tag(:br) +
940
+ b.call +
941
+ '"around" call 2 after' +
942
+ builder.content_tag(:br)
943
+ end
944
+
945
+ builder.render :my_block do
946
+ '"my_block" content' +
947
+ builder.content_tag(:br)
948
+ end
949
+ ```
950
+
951
+ > The output will be:
952
+
953
+ ```html
954
+ "around_all" call before
955
+ "around" call 2 before
956
+ "around" call 1 before
957
+ "before" call
958
+ "my_block" content
959
+ "after" call
960
+ "around" call 1 after
961
+ "around" call 2 after
962
+ "around_all" call after
963
+ ```
964
+
965
+ "around" hooks render content that surrounds the combination of "before" hooks, "surround" content, and "after" hooks. They can be surround by "around_all" hooks.
966
+
967
+ <aside class="notice">
968
+ Take note that the second "around" call content rendered around the first.
969
+ </aside>
970
+
971
+ ### "around_all" Hooks
972
+
973
+ ```erb
974
+ <% blocks.before :my_block do %>
975
+ "before" call
976
+ <br>
977
+ <% end %>
978
+
979
+ <% blocks.after :my_block do %>
980
+ "after" call
981
+ <br>
982
+ <% end %>
983
+
984
+ <% blocks.around :my_block do |b| %>
985
+ "around" call 1 before
986
+ <br>
987
+ <%= b.call %>
988
+ "around" call 1 after
989
+ <br>
990
+ <% end %>
991
+
992
+ <% blocks.around_all :my_block do |b| %>
993
+ "around_all" call before
994
+ <br>
995
+ <%= b.call %>
996
+ "around_all" call after
997
+ <br>
998
+ <% end %>
999
+
1000
+ <% blocks.around :my_block do |b| %>
1001
+ "around" call 2 before
1002
+ <br>
1003
+ <%= b.call %>
1004
+ "around" call 2 after
1005
+ <br>
1006
+ <% end %>
1007
+
1008
+ <%= blocks.render :my_block do %>
1009
+ "my_block" content
1010
+ <br>
1011
+ <% end %>
1012
+ ```
1013
+
1014
+ ```haml
1015
+ - blocks.before_all :my_block do
1016
+ "before_all" call
1017
+ %br
1018
+
1019
+ - blocks.after_all :my_block do
1020
+ "after_all" call
1021
+ %br
1022
+
1023
+ - blocks.around_all :my_block do |b|
1024
+ "around_all" call 1 before
1025
+ %br
1026
+ = b.call
1027
+ "around_all" call 1 after
1028
+ %br
1029
+
1030
+ - blocks.around :my_block do |b|
1031
+ "around" call before
1032
+ %br
1033
+ = b.call
1034
+ "around" call after
1035
+ %br
1036
+
1037
+ - blocks.around_all :my_block do |b|
1038
+ "around_all" call 2 before
1039
+ %br
1040
+ = b.call
1041
+ "around_all" call 2 after
1042
+ %br
1043
+
1044
+ = blocks.render :my_block do
1045
+ "my_block" content
1046
+ %br
1047
+ ```
1048
+
1049
+ ```ruby
1050
+ # where builder is an instance
1051
+ # of Blocks::Builder
1052
+ builder.before_all :my_block do
1053
+ '"before_all" call' +
1054
+ builder.content_tag(:br)
1055
+ end
1056
+
1057
+ builder.after_all :my_block do
1058
+ '"after_all" call' +
1059
+ builder.content_tag(:br)
1060
+ end
1061
+
1062
+ builder.around_all :my_block do |b|
1063
+ '"around_all" call 1 before' +
1064
+ builder.content_tag(:br) +
1065
+ b.call +
1066
+ '"around_all" call 1 after' +
1067
+ builder.content_tag(:br)
1068
+ end
1069
+
1070
+ builder.around :my_block do |b|
1071
+ '"around" call before' +
1072
+ builder.content_tag(:br) +
1073
+ b.call +
1074
+ '"around" call after' +
1075
+ builder.content_tag(:br)
1076
+ end
1077
+
1078
+ builder.around_all :my_block do |b|
1079
+ '"around_all" call 2 before' +
1080
+ builder.content_tag(:br) +
1081
+ b.call +
1082
+ '"around_all" call 2 after' +
1083
+ builder.content_tag(:br)
1084
+ end
1085
+
1086
+ builder.render :my_block do
1087
+ '"my_block" content' +
1088
+ builder.content_tag(:br)
1089
+ end
1090
+ ```
1091
+
1092
+ > The output will be:
1093
+
1094
+ ```html
1095
+ "before_all" call
1096
+ "around_all" call 2 before
1097
+ "around_all" call 1 before
1098
+ "around" call before
1099
+ "my_block" content
1100
+ "around" call after
1101
+ "around_all" call 1 after
1102
+ "around_all" call 2 after
1103
+ "after_all" call
1104
+ ```
1105
+
1106
+ "around_all" hooks render content that surrounds "around" hooks. They can be preceded by "before_all" hooks and followed by "after_all" hooks.
1107
+
1108
+ <aside class="notice">
1109
+ Take note that the second "around_all" call content rendered around the first.
1110
+ </aside>
1111
+
1112
+ ## With Options
1113
+
1114
+ TODO
1115
+
1116
+ ## With a Partial
1117
+
1118
+ ```erb
1119
+ <% blocks.before :my_block,
1120
+ partial: "some_partial" %>
1121
+ ```
1122
+
1123
+ ```haml
1124
+ - blocks.before :my_block,
1125
+ partial: "some_partial"
1126
+ ```
1127
+
1128
+ ```ruby
1129
+ # where builder is an instance
1130
+ # of Blocks::Builder
1131
+ builder.before :my_block,
1132
+ partial: "some_partial"
1133
+ ```
1134
+
1135
+ Hooks may also be defined with Rails partials using the "partial" keyword.
1136
+
1137
+ ## With a Proxy to Another Block
1138
+
1139
+ ```erb
1140
+ <% blocks.before :my_block,
1141
+ with: :some_proxy_block %>
1142
+ ```
1143
+
1144
+ ```haml
1145
+ - blocks.before :my_block,
1146
+ with: :some_proxy_block
1147
+ ```
1148
+
1149
+ ```ruby
1150
+ # where builder is an instance
1151
+ # of Blocks::Builder
1152
+ builder.after :my_block,
1153
+ with: :some_proxy_block
1154
+ ```
1155
+
1156
+ Hooks may also be defined with a proxy to another block using the "with" keyword.