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,59 @@
1
+ # Reserved Keywords
2
+
3
+ Whether defining a block, defining options for a block, rendering a block, registering hooks for a block, configuring global options for Blocks, or initializing an instance of a Blocks::Builder, there are certain keywords which are reserved for specific purposes:
4
+
5
+ ## "collection" and "as" and "object" and "current_index"
6
+
7
+ "collection" is used to designate a collection for a block. When the block is rendered, it will be rendered for each item in the collection, and the "collection" option will be extracted from the options hash.
8
+
9
+ "as" is used to give each item in the collection an alias as it is being iterated over. "as" will default to "object", meaning that "object" becomes a reserved keyword by default. If "as" is set to some other value, whatever that value is will become a reserved keyword for that block.
10
+
11
+ "current_index" will be a zero-based index of the current item's position within the collection.
12
+
13
+ ## "with"
14
+
15
+ "with" is used to specify the proxy render strategy, where its value is name of the other block to be rendered in its place.
16
+
17
+ ## "partial"
18
+
19
+ "partial" is used to specify the Rails partial render strategy, where its value is the Rails partial to render.
20
+
21
+ ### Other Reserved Keywords when using a partial
22
+
23
+ http://www.rubymagic.org/posts/ruby-and-rails-reserved-words
24
+
25
+ ## "block"
26
+
27
+ "block" can be used to specify the Ruby block render strategy, where its value is the Ruby block to render. This is an alternative to specifying the block using the "do ... end" syntax.
28
+
29
+ ## "defaults"
30
+
31
+ "defaults", if specified, must have its value be a hash. These represent default options, which are given a lower precedence than standard options when merging options.
32
+
33
+ ## "runtime"
34
+
35
+ "runtime", if specified, must have its value be a hash. These represent runtime options, which are given a higher precedence than standard options when merging options.
36
+
37
+ ## "builder" and "builder_variable"
38
+
39
+ "builder" will be the default variable name given to the instance of the Blocks::Builder passed to a partial that triggered the call to render to the possible. The "builder" can be used to invoke Blocks functionality within the partial on a shared instance of a Blocks::Builder.
40
+
41
+ The name "builder" can be overridden by specifying a value in "builder_variable".
42
+
43
+ ## Wrappers
44
+
45
+ ### "wrap_all"
46
+
47
+ Indicates that a wrapper will wrap around any wrap_each wrappers.
48
+
49
+ ### "wrap_each" / "outer_wrapper"
50
+
51
+ Indicates that a wrapper will wrap around a block and any around, before, after, surround, prepend, and append hooks for that block.
52
+
53
+ ### "wrap_with" / "wrap" / "wrapper" / "inner_wrapper"
54
+
55
+ Indicates that a wrapper will wrap around a block and any surround, prepend, and append hooks for that block.
56
+
57
+ ## "parent_runtime_context"
58
+
59
+ Passed internally within the Blocks gem as a parent Blocks::RuntimeContext when calculating the Blocks::RuntimeContext for a hook or wrapper for a block.
@@ -0,0 +1,403 @@
1
+ # Skipping Blocks
2
+
3
+ > Prerequisite code for below examples:
4
+
5
+ ```erb
6
+ <% blocks.define :my_block,
7
+ wrap_all: :wrap_all_wrapper,
8
+ wrap_each: :wrap_each_wrapper,
9
+ wrap_with: :wrap_with_wrapper do %>
10
+ My Block
11
+ <br>
12
+ <% end %>
13
+
14
+ <% blocks.define :proxy_block do |*args| %>
15
+ <% options = args.extract_options! %>
16
+ <% item = args.shift %>
17
+ <%= options[:name] %>
18
+ <br>
19
+ <% end %>
20
+
21
+ <% blocks.define :wrapper do |b, *args| %>
22
+ <% options = args.extract_options! %>
23
+ <% item = args.shift %>
24
+ <%= options[:name] %> Before
25
+ <br>
26
+ <%= b.call %>
27
+ <%= options[:name] %> After
28
+ <br>
29
+ <% end %>
30
+
31
+ <% blocks.define :wrap_all_wrapper,
32
+ name: "wrap_all Wrapper",
33
+ with: :wrapper %>
34
+
35
+ <% blocks.define :wrap_each_wrapper,
36
+ name: "wrap_each Wrapper",
37
+ with: :wrapper %>
38
+
39
+ <% blocks.define :wrap_with_wrapper,
40
+ name: "wrap_with Wrapper",
41
+ with: :wrapper %>
42
+
43
+ <% [:before_all,
44
+ :before,
45
+ :prepend,
46
+ :append,
47
+ :after,
48
+ :after_all].each do |hook| %>
49
+ <% blocks.send(hook,
50
+ :my_block,
51
+ with: :proxy_block,
52
+ name: "\"#{hook}\" Hook") %>
53
+ <% end %>
54
+
55
+ <% [:around_all,
56
+ :around,
57
+ :surround].each do |hook| %>
58
+ <% blocks.send(hook,
59
+ :my_block,
60
+ with: :wrapper,
61
+ name: "\"#{hook}\" Hook") %>
62
+ <% end %>
63
+ ```
64
+
65
+ ```haml
66
+ - blocks.define :my_block,
67
+ wrap_all: :wrap_all_wrapper,
68
+ wrap_each: :wrap_each_wrapper,
69
+ wrap_with: :wrap_with_wrapper do
70
+ My Block
71
+ %br
72
+
73
+ - blocks.define :proxy_block do |*args|
74
+ - options = args.extract_options!
75
+ - item = args.shift
76
+ = options[:name]
77
+ %br
78
+
79
+ - blocks.define :wrapper do |b, *args|
80
+ - options = args.extract_options!
81
+ - item = args.shift
82
+ = options[:name]
83
+ Before
84
+ %br
85
+ = b.call
86
+ = options[:name]
87
+ After
88
+ %br
89
+
90
+ - blocks.define :wrap_all_wrapper,
91
+ name: "wrap_all Wrapper",
92
+ with: :wrapper
93
+
94
+ - blocks.define :wrap_each_wrapper,
95
+ name: "wrap_each Wrapper",
96
+ with: :wrapper
97
+
98
+ - blocks.define :wrap_with_wrapper,
99
+ name: "wrap_with Wrapper",
100
+ with: :wrapper
101
+
102
+ - [:before_all,
103
+ :before,
104
+ :prepend,
105
+ :append,
106
+ :after,
107
+ :after_all].each do |hook|
108
+ - blocks.send(hook,
109
+ :my_block,
110
+ with: :proxy_block,
111
+ name: "\"#{hook}\" Hook")
112
+
113
+ - [:around_all,
114
+ :around,
115
+ :surround].each do |hook|
116
+ - blocks.send(hook,
117
+ :my_block,
118
+ with: :wrapper,
119
+ name: "\"#{hook}\" Hook")
120
+ ```
121
+
122
+ ```ruby
123
+ # where builder is an instance
124
+ # of Blocks::Builder
125
+ builder.define :my_block,
126
+ wrap_all: :wrap_all_wrapper,
127
+ wrap_each: :wrap_each_wrapper,
128
+ wrap_with: :wrap_with_wrapper do
129
+ "My Block<br>".html_safe
130
+ end
131
+
132
+ builder.define :proxy_block do |*args|
133
+ options = args.extract_options!
134
+ item = args.shift
135
+ "#{options[:name]}<br>".html_safe +
136
+ end
137
+
138
+ builder.define :wrapper do |b, *args|
139
+ options = args.extract_options!
140
+ item = args.shift
141
+ "#{options[:name]} Before<br>".html_safe +
142
+ b.call +
143
+ "#{options[:name]} After<br>".html_safe +
144
+ end
145
+
146
+ builder.define :wrap_all_wrapper,
147
+ name: "wrap_all Wrapper",
148
+ with: :wrapper
149
+
150
+ builder.define :wrap_each_wrapper,
151
+ name: "wrap_each Wrapper",
152
+ with: :wrapper
153
+
154
+ builder.define :wrap_with_wrapper,
155
+ name: "wrap_with Wrapper",
156
+ with: :wrapper
157
+
158
+ [:before_all,
159
+ :before,
160
+ :prepend,
161
+ :append,
162
+ :after,
163
+ :after_all].each do |hook|
164
+ builder.send(hook,
165
+ :my_block,
166
+ with: :proxy_block,
167
+ name: "\"#{hook}\" Hook")
168
+ end
169
+
170
+ [:around_all,
171
+ :around,
172
+ :surround].each do |hook|
173
+ builder.send(hook,
174
+ :my_block,
175
+ with: :wrapper,
176
+ name: "\"#{hook}\" Hook")
177
+ end
178
+ ```
179
+
180
+ Blocks may be skipped from rendering, such that whenever a render call occurs, no content will be rendered.
181
+
182
+ <aside class="notice">
183
+ The code to the right is prerequistive code to the "Skipping Blocks" examples that follow
184
+ </aside>
185
+
186
+ Skips come in two forms: skipping a block only, and skipping a block with all of its hooks and wrappers.
187
+
188
+ ## Skipping the Block Only
189
+
190
+ ```erb
191
+ <h2>Render Before Skip:</h2>
192
+ <%= blocks.render :my_block %>
193
+
194
+ <% blocks.skip :my_block %>
195
+ <h2>Render After Skip:</h2>
196
+ <%= blocks.render :my_block %>
197
+ ```
198
+
199
+ ```haml
200
+ %h2 Render Before Skip:
201
+ = blocks.render :my_block
202
+
203
+ - blocks.skip :my_block
204
+ %h2 Render After Skip:
205
+ = blocks.render :my_block
206
+ ```
207
+
208
+ ```ruby
209
+ output =
210
+ "<h2>Render Before Skip:</h2>".
211
+ html_safe +
212
+ builder.render :my_block
213
+
214
+ builder.skip :my_block
215
+ output +=
216
+ "<h2>Render After Skip:</h2>".
217
+ html_safe +
218
+ builder.render :my_block
219
+ output
220
+ ```
221
+
222
+ > The above code will output the following:
223
+
224
+ ```
225
+ Render Before Skip:
226
+
227
+ "before_all" Hook
228
+ "around_all" Hook Before
229
+ wrap_all Wrapper Before
230
+ wrap_each Wrapper Before
231
+ "around" Hook Before
232
+ "before" Hook
233
+ wrap_with Wrapper Before
234
+ "surround" Hook Before
235
+ "prepend" Hook
236
+ My Block
237
+ "append" Hook
238
+ "surround" Hook After
239
+ wrap_with Wrapper After
240
+ "after" Hook
241
+ "around" Hook After
242
+ wrap_each Wrapper After
243
+ wrap_all Wrapper After
244
+ "around_all" Hook After
245
+ "after_all" Hook
246
+
247
+ Render After Skip:
248
+
249
+ "before_all" Hook
250
+ "around_all" Hook Before
251
+ wrap_all Wrapper Before
252
+ wrap_each Wrapper Before
253
+ "around" Hook Before
254
+ "before" Hook
255
+ "after" Hook
256
+ "around" Hook After
257
+ wrap_each Wrapper After
258
+ wrap_all Wrapper After
259
+ "around_all" Hook After
260
+ "after_all" Hook
261
+ ```
262
+
263
+ A block may be skipped using the #skip method.
264
+
265
+ Calling #skip has the effect of skipping rendering of the block itself, and any "prepend" hooks, "append" hooks, "surround" hooks, and the "wrap_with" wrapper that might have been associated with the block being skipped.
266
+
267
+ Any "before" hooks, "before_all" hooks, "after" hooks, "after_all" hooks, "around" hooks, "around_all" hooks, the "wrap_all" wrapper, and the "wrap_each" wrapper will continue to be rendered when the block is skipped. See [Skipping the Block and its Hooks](#Skipping the Block and its Hooks) for skipping everything.
268
+
269
+ ### With a Collection
270
+
271
+ ```erb
272
+ <% blocks.define :my_block,
273
+ collection: ["a", "b"] %>
274
+
275
+ <h2>Render Before Skip:</h2>
276
+ <%= blocks.render :my_block %>
277
+
278
+ <% blocks.skip :my_block %>
279
+ <h2>Render After Skip:</h2>
280
+ <%= blocks.render :my_block %>
281
+ ```
282
+
283
+ ```haml
284
+ - blocks.define :my_block,
285
+ collection: ["a", "b"]
286
+
287
+ %h2 Render Before Skip:
288
+ = blocks.render :my_block
289
+
290
+ - blocks.skip :my_block
291
+ %h2 Render After Skip:
292
+ = blocks.render :my_block
293
+ ```
294
+
295
+ ```ruby
296
+ output =
297
+ "<h2>Render Before Skip:</h2>".
298
+ html_safe +
299
+ builder.render :my_block
300
+
301
+ builder.skip :my_block
302
+ output +=
303
+ "<h2>Render After Skip:</h2>".
304
+ html_safe +
305
+ builder.render :my_block
306
+ output
307
+ ```
308
+
309
+ > The above code will output the following:
310
+
311
+ ```
312
+ Render Before Skip:
313
+
314
+ "before_all" Hook
315
+ "around_all" Hook Before
316
+ wrap_all Wrapper Before
317
+ wrap_each Wrapper Before for item "a"
318
+ "around" Hook Before for item "a"
319
+ "before" Hook for item "a"
320
+ wrap_with Wrapper Before for item "a"
321
+ "surround" Hook Before for item "a"
322
+ "prepend" Hook for item "a"
323
+ My Block
324
+ "append" Hook for item "a"
325
+ "surround" Hook After for item "a"
326
+ wrap_with Wrapper After for item "a"
327
+ "after" Hook for item "a"
328
+ "around" Hook After for item "a"
329
+ wrap_each Wrapper After for item "a"
330
+ wrap_each Wrapper Before for item "b"
331
+ "around" Hook Before for item "b"
332
+ "before" Hook for item "b"
333
+ wrap_with Wrapper Before for item "b"
334
+ "surround" Hook Before for item "b"
335
+ "prepend" Hook for item "b"
336
+ My Block
337
+ "append" Hook for item "b"
338
+ "surround" Hook After for item "b"
339
+ wrap_with Wrapper After for item "b"
340
+ "after" Hook for item "b"
341
+ "around" Hook After for item "b"
342
+ wrap_each Wrapper After for item "b"
343
+ wrap_all Wrapper After
344
+ "around_all" Hook After
345
+ "after_all" Hook
346
+
347
+ Render After Skip:
348
+
349
+ "before_all" Hook
350
+ "around_all" Hook Before
351
+ wrap_all Wrapper Before
352
+ wrap_each Wrapper Before for item "a"
353
+ "around" Hook Before for item "a"
354
+ "before" Hook for item "a"
355
+ "after" Hook for item "a"
356
+ "around" Hook After for item "a"
357
+ wrap_each Wrapper After for item "a"
358
+ wrap_each Wrapper Before for item "b"
359
+ "around" Hook Before for item "b"
360
+ "before" Hook for item "b"
361
+ "after" Hook for item "b"
362
+ "around" Hook After for item "b"
363
+ wrap_each Wrapper After for item "b"
364
+ wrap_all Wrapper After
365
+ "around_all" Hook After
366
+ "after_all" Hook
367
+ ```
368
+
369
+ A block with a collection can also be skipped, though the resulting output may not be desired.
370
+
371
+ Calling #skip on a block with a collection has the effect of skipping rendering of the block itself, and any "prepend" hooks, "append" hooks, "surround" hooks, and the "wrap_with" wrapper that might have been associated with the block being skipped.
372
+
373
+ Any "before" hooks, "before_all" hooks, "after" hooks, "after_all" hooks, "around" hooks, "around_all" hooks, the "wrap_all" wrapper, and the "wrap_each" wrapper will continue to be rendered when the block is skipped. All the hooks and wrappers, with the exception of the "around_all", "wrap_all", "before_all", and "after_all" ones, will be rendered for each item in the collection (this behavior will likely change in a future release of Blocks).
374
+
375
+ See [Skipping the Block and its Hooks](#Skipping the Block and its Hooks) for skipping everything.
376
+
377
+ ## Skipping the Block and its Hooks
378
+
379
+ ```erb
380
+ <% blocks.skip_completely :my_block %>
381
+ <%= blocks.render :my_block do %>
382
+ Hello
383
+ <% end %>
384
+ ```
385
+
386
+ ```haml
387
+ - blocks.skip_completely :my_block
388
+ = blocks.render :my_block do
389
+ Hello
390
+ ```
391
+
392
+ ```ruby
393
+ # where builder is an instance
394
+ # of Blocks::Builder
395
+ builder.skip_completely :my_block
396
+ builder.render :my_block do
397
+ "Hello"
398
+ end
399
+ ```
400
+
401
+ > There will be no output from the above command
402
+
403
+ Because calling #skip can still have the effect of rendering some of the hooks and wrappers for a particular block (before, after, around, before_all, after_all, wrap_all, wrap_each will still be rendered), there is the need for a second type of skip, called #skip_completely, which will skip the block and all associated hooks and wrappers.