blocks 3.0.0.rc7 → 3.0.0.rc8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b2c9902373a222d24d5785b7485b9fada199f43d
4
- data.tar.gz: 701646e71d0644b84e3380fe2d7120165e055c21
3
+ metadata.gz: 1981e0556f4728292d6fc55314cd8674c9f83429
4
+ data.tar.gz: edb4a53aae3a6ab5aa73535f571400486b55b91b
5
5
  SHA512:
6
- metadata.gz: 9c747b34bcbdc47dd542fded6ac3794a36375dc34fa4ab9301557c7cf622a241d6be4fac2df10470024efc42e948db8ba58e4e22e4be75abf8e5c1f979f244bd
7
- data.tar.gz: 10b5a023ae6ce04e9f32b22f0c9c58bcc3544d6c7fd404af618c2df542f7f6cada78433d1dd4dd19793b339c69e5d400e0af0130a64f4688a46c3ff933f38db1
6
+ metadata.gz: 925dc6a46ada68430d4066cf8d132b428e3a28e6c5f3eb1a733b9ab78444cca28a753112f8e46fd909cb84f9087d3d5d50e2c865ba11e972654ca9c88d8a269e
7
+ data.tar.gz: a89b434fe46a3222c2a57c8d511b649a979702d9188db5c658fe62f8abb0490ea42d025ab1081667012c4a7322fa1d7dbfb2cea950bd791cdedcabcf4bc538f9
@@ -34,3 +34,94 @@ If #initialize is overridden in the subclass, it must, at a minimum call super w
34
34
 
35
35
  ## Custom Builders with Helper Methods
36
36
 
37
+ {% highlight ruby %}
38
+ class MyCustomBuilder < Blocks.builder_class
39
+ def tag(*args, &block)
40
+ options = args.extract_options!
41
+
42
+ wrapper_html = if options.is_a?(Blocks::RuntimeContext)
43
+ wrapper_option =
44
+ options[:wrapper_option] || :wrapper_html
45
+ options[wrapper_option] || {}
46
+ else
47
+ options
48
+ end
49
+
50
+ wrapper_tag = options[:wrapper_tag]
51
+ if !wrapper_tag
52
+ first_arg = args.first
53
+ wrapper_tag = if first_arg.is_a?(String) || first_arg.is_a?(Symbol)
54
+ first_arg
55
+ else
56
+ :div
57
+ end
58
+ end
59
+
60
+ content_tag wrapper_tag, wrapper_html, &block
61
+ end
62
+ end
63
+ {% endhighlight %}
64
+
65
+ ```erb
66
+ <% builder = MyCustomBuilder.new(self) %>
67
+ <%= builder.render :my_block,
68
+ wrapper: :tag,
69
+ wrapper_tag: :h2,
70
+ wrapper_html: { class: 'text-muted' } do %>
71
+ Hello
72
+ <% end %>
73
+
74
+ <!-- OR -->
75
+
76
+ <%= builder.tag :h2, class: 'text-muted' do %>
77
+ Hello
78
+ <% end %>
79
+ ```
80
+
81
+ ```haml
82
+ - builder = MyCustomBuilder.new(self)
83
+ = builder.render :my_block,
84
+ wrapper: :tag,
85
+ wrapper_tag: :h2,
86
+ wrapper_html: { class: 'text-muted' } do
87
+ Hello
88
+
89
+ #- OR
90
+
91
+ = builder.tag :h2, class: 'text-muted' do
92
+ Hello
93
+ ```
94
+
95
+ ```ruby
96
+ builder = MyCustomBuilder.new(self)
97
+ builder.render :my_block,
98
+ wrapper: :block_wrapper,
99
+ wrapper_tag: :h2,
100
+ wrapper_html: { class: 'text-muted' } do
101
+ "Hello"
102
+ end
103
+
104
+ # OR
105
+
106
+ builder.tag :h2, class: 'text-muted' do
107
+ "Hello"
108
+ end
109
+ ```
110
+
111
+ > This will produce the following output:
112
+
113
+ ```html
114
+ <h2 class='text-muted'>Hello</h2>
115
+ ```
116
+
117
+ One of the primary reasons one might want to create a custom builder is to provide helper methods that are isolated within the builder. These helper methods may be invoked directly on the builder object, or indirectly by using a proxy or hook or wrapper.
118
+
119
+ In the example to the right, tag is declared as a method (which is almost a direct port over of the "block_wrapper" block defined in the [Templating Example for Bootstrap Cards](#extracting-out-the-wrappers) it was defined as a Block). The code has been slightly modified to allow the method to be called directly from the builder, or indirectly as a wrapper or hook for a Block.
120
+
121
+ <aside class="notice">
122
+ At this time, it is not possible to proxy to a builder method (by using the "with" keyword) that expects / allows a block as an argument (i.e. this wouldn't be possible: 'builder.render with: :tag do "Hello" end'. This will likely change in future versions).
123
+ </aside>
124
+
125
+ <aside class="notice">
126
+ If the method is called indirectly, either because it is registered as a hook or wrapper for a block, the options hash that is sent in to the method will be an instance of a Blocks::RuntimeContext. If the method is called directly on the builder, the options hash will be whatever is directly passed in or default to an empty hash.
127
+ </aside>
@@ -582,7 +582,7 @@ end
582
582
  My options are { a: 1 }
583
583
  ```
584
584
 
585
- Every block that are defined with a Ruby block or a proxy to a Block that is defined with a Ruby block (or a proxy to a proxy to ... to a block that is defined with a Ruby block) can optionally receive the merged options as a parameter.
585
+ Every block that is defined with a Ruby block - or a proxy to a Block that is defined with a Ruby block, etc. - can optionally receive the merged options as a parameter.
586
586
 
587
587
  ## Without a Name
588
588
 
@@ -612,4 +612,4 @@ Blocks may be defined without a name. When no block name is provided, an anonymo
612
612
 
613
613
  <aside class="notice">
614
614
  This is really only useful directly within the Ruby code or when extending the Blocks::Builder class.
615
- </aside>
615
+ </aside>
@@ -962,7 +962,7 @@ end
962
962
  "around_all" call after
963
963
  ```
964
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.
965
+ "around" hooks render content that surrounds the combination of "before" hooks, "surround" content, and "after" hooks. They can be surrounded by "around_all" hooks.
966
966
 
967
967
  <aside class="notice">
968
968
  Take note that the second "around" call content rendered around the first.
@@ -1209,4 +1209,4 @@ builder.after :my_block,
1209
1209
  with: :some_proxy_block
1210
1210
  ```
1211
1211
 
1212
- Hooks may also be defined with a proxy to another block using the "with" keyword.
1212
+ Hooks may also be defined with a proxy to another block using the "with" keyword.
@@ -198,13 +198,13 @@ end
198
198
  }
199
199
  ```
200
200
 
201
- Just as options can be set for a block when the block is defined, they can also be applied at render time.
201
+ Just as options can be set for a block when the block is defined, they can also be applied at render.
202
202
 
203
203
  Options provided to the render call can be either runtime options or default options (unlike defining blocks, there is no concept for render standard options).
204
204
 
205
205
  Default options are specified within a nested hash under the key "defaults".
206
206
 
207
- All other options are considered to be runtime options. Runtime options provided to the render call will take precedence over all other options included runtime options set on the block definition.
207
+ All other options are considered to be runtime options. Runtime options provided to the render call will take precedence over all other options, including runtime options set on the block definition.
208
208
 
209
209
  ### Indifferent Access
210
210
 
@@ -418,7 +418,7 @@ Though this concept is still relatively limited in its potential uses at this ti
418
418
 
419
419
  At this time, this will not do anything meaningful if the Block is defined to render a partial. However, if the Block is defined to be a Ruby block or a Proxy to a Block defined with a Ruby block, Blocks will attempt to match up the number of arguments the block expects with the number of arguments that could be sent to it from the render call.
420
420
 
421
- Remember, options will always be the last argument, and if rendering a collection, item will be the first. Any additional params passed to the render call will then be sent as the second argument onward, followed by the options hash. However, if less arguments are expected by the block than are to be sent, Blocks will send the less number of arguments.
421
+ Remember, options will always be the last argument, and if rendering a collection, item will be the first. Any additional params passed to the render call will then be sent as the second argument onward, followed by the options hash. However, if fewer arguments are expected by the block than are sent, Blocks will send the lesser number of arguments.
422
422
 
423
423
  See the example to the right to make better sense out of what is being explained here.
424
424
 
@@ -674,12 +674,12 @@ If the block being rendered is not a partial, it will store "object" as a key in
674
674
  <%= blocks.render a: 1, b: 2,
675
675
  partial: "a_partial" %>
676
676
 
677
- -# and a collection
677
+ <!-- and a collection -->
678
678
  <%= blocks.render a: 1, b: 2,
679
679
  partial: "a_partial",
680
680
  collection: [1, 2, 3] %>
681
681
 
682
- -# rendering with a proxy
682
+ <!-- rendering with a proxy -->
683
683
  <%= blocks.render with:
684
684
  :some_proxy %>
685
685
  ```
@@ -723,4 +723,4 @@ Blocks may be rendered without a block name.
723
723
 
724
724
  This is usually done in combination with a wrapper, a proxy, or a partial.
725
725
 
726
- Use this when you don't need corresponding hooks for the block to be rendered or when wanting to render a partial or a proxy block.
726
+ Use this when you don't need corresponding hooks for the block to be rendered or when wanting to render a partial or a proxy block.
@@ -180,7 +180,7 @@ end
180
180
  Blocks may be skipped from rendering, such that whenever a render call occurs, no content will be rendered.
181
181
 
182
182
  <aside class="notice">
183
- The code to the right is prerequistive code to the "Skipping Blocks" examples that follow
183
+ The code to the right is prerequesite code to the "Skipping Blocks" examples that follow
184
184
  </aside>
185
185
 
186
186
  Skips come in two forms: skipping a block only, and skipping a block with all of its hooks and wrappers.
@@ -400,4 +400,4 @@ end
400
400
 
401
401
  > There will be no output from the above command
402
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.
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.
@@ -124,9 +124,9 @@ If you look at the sample markup for a card, hopefully you notice a pattern. It'
124
124
 
125
125
  While not every Bootstrap 4 card will follow this exact pattern, it is a good starting point for beginning to break down a card into pieces.
126
126
 
127
- The code to the right breaks down the main :card block into pieces. Now, the :card block defines the card element and renders its two components: :card_image and :card_card.
127
+ The code to the right defines the card element and breaks the main :card block into its two components: :card_image and :card_content.
128
128
 
129
- The :card_image block renders the hardcoded image tag and the :card_content block sets itself up to proxy to the :card_block block. This is done in anticipation (based on having read ahead in the Bootstrap 4 Card documentation) of using something of than a card-block for the content of the card (more on this shortly).
129
+ The :card_image block renders the hardcoded image tag and the :card_content block sets itself up to proxy to the :card_block block. This is done in anticipation (based on having read ahead in the Bootstrap 4 Card documentation) of using something other than a card-block for the content of the card (more on this shortly).
130
130
 
131
131
  ### Extracting out the Wrappers
132
132
 
@@ -750,4 +750,4 @@ In the example to the right, a team-specific version of card is created as a tem
750
750
 
751
751
  <aside class="warning">
752
752
  Take note that with the team_card template, builder.render_with_overrides is used instead of just render_with_overrides. This is forcing the two templates to render using the same Blocks::Builder instance, i.e. to share a Blocks namespace. This is what allows the overrides block for the team_card template to affect the defaults in card template.
753
- </aside>
753
+ </aside>
@@ -354,7 +354,6 @@ builder.render(:my_block,
354
354
 
355
355
  ```
356
356
  With Collection:
357
- With Collection:
358
357
  Wrap All Start
359
358
  Wrap Each Start a
360
359
  Around Start
@@ -626,4 +625,4 @@ end
626
625
 
627
626
  ```html
628
627
  <div>Hello</div>
629
- ```
628
+ ```
@@ -13,6 +13,7 @@ module Blocks
13
13
  else
14
14
  locals.symbolize_keys
15
15
  end
16
+ partial = partial.to_partial_path if partial.respond_to?(:to_partial_path)
16
17
  locals[:options] = options
17
18
  view.render(layout: partial, locals: locals) do |*args|
18
19
  if overrides_and_provided_content
@@ -1,3 +1,3 @@
1
1
  module Blocks
2
- VERSION = "3.0.0.rc7"
2
+ VERSION = "3.0.0.rc8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blocks
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.rc7
4
+ version: 3.0.0.rc8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Hunter
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-20 00:00:00.000000000 Z
11
+ date: 2017-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: call_with_params