Skip to content

Commit c0cf4ca

Browse files
committed
Alias dig to search.
Search is a bit of a confusing way to describe what traversing is. Dig seems more appropriate and is consistent with how superglue describes it.
1 parent 0c75588 commit c0cf4ca

File tree

3 files changed

+70
-46
lines changed

3 files changed

+70
-46
lines changed

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ gem 'props_template'
7272
and run `bundle`.
7373

7474
Optionally add the [core ext](#array-core-extension) to an initializer if you
75-
want to [dig](#traversing) into your templates.
75+
want to [dig](#digging) into your templates.
7676

7777
```ruby
7878
require 'props_template/core_ext'
@@ -152,7 +152,7 @@ The difference between the block form and inline form is
152152
1. The block form is an internal node. Functionality such as Partials,
153153
Deferment and other [options](#options) are only available on the
154154
block form.
155-
2. The inline form is considered a leaf node, and you can only [search](#traversing)
155+
2. The inline form is considered a leaf node, and you can only [dig](#digging)
156156
for internal nodes.
157157

158158
### json.extract!
@@ -202,7 +202,7 @@ end
202202
| collection | A collection that responds to `member_at` and `member_by` |
203203
| options | Additional [options](#options)|
204204

205-
To support [traversing nodes](#traversing), any list passed
205+
To support [digging](#digging), any list passed
206206
to `array!` MUST implement `member_at(index)` and `member_by(attr, value)`.
207207

208208
For example, if you were using a delegate:
@@ -276,7 +276,7 @@ end
276276
```
277277

278278
PropsTemplate does not know what the elements are in your collection. The
279-
example above will be fine for [traversing](#traversing)
279+
example above will be fine for [digging](#digging)
280280
by index, but will raise a `NotImplementedError` if you query by attribute. You
281281
may still need to implement `member_by`.
282282

@@ -447,7 +447,7 @@ entirely and replace the value with a placeholder. A common use case would be
447447
tabbed content that does not load until you click the tab.
448448

449449
When your client receives the payload, you may issue a second request to the
450-
same endpoint to fetch any missing nodes. See [traversing nodes](#traversing)
450+
same endpoint to fetch any missing nodes. See [digging](#digging)
451451

452452
There is also an `defer: :auto` option that you can use with [SuperglueJS][1]. [SuperglueJS][1]
453453
will use the metadata from `json.deferred!` to issue a `remote` dispatch to fetch
@@ -502,7 +502,7 @@ your collection item, and is used for `defer: :auto` to generate a keypath for
502502
[SuperglueJS][1]. If you are NOT using SuperglueJS, you do not need to do this.
503503

504504
2. Implement `member_at`, on the [collection](#jsonarray). This will be called
505-
by PropsTemplate to when [searching nodes](#traversing)
505+
by PropsTemplate to when [digging](#digging)
506506

507507
For example:
508508

@@ -528,7 +528,7 @@ end
528528
If you are using [SuperglueJS][1], SuperglueJS will, it will automatically kick off
529529
`remote(?props_at=posts.some_id=1.contact)` and `remote(?props_at=posts.some_id=2.contact)`.
530530

531-
## Traversing
531+
## Digging
532532

533533
PropsTemplate has the ability to walk the tree you build, skipping execution of
534534
untargeted nodes. This feature is useful for selectively updating your frontend
@@ -537,7 +537,7 @@ state.
537537
```ruby
538538
traversal_path = ['data', 'details', 'personal']
539539

540-
json.data(search: traversal_path) do
540+
json.data(dig: traversal_path) do
541541
json.details do
542542
json.employment do
543543
...more stuff
@@ -571,13 +571,13 @@ The above will output:
571571
}
572572
```
573573

574-
Searching only works with blocks, and will NOT work with Scalars
574+
Digging only works with blocks, and will NOT work with Scalars
575575
("leaf" values). For example:
576576

577577
```ruby
578578
traversal_path = ['data', 'details', 'personal', 'name'] <- not found
579579

580-
json.data(search: traversal_path) do
580+
json.data(dig: traversal_path) do
581581
json.details do
582582
json.personal do
583583
json.name 'james'
@@ -588,12 +588,12 @@ end
588588

589589
## Nodes that do not exist
590590

591-
Nodes that are not found will remove the branch where search was enabled on.
591+
Nodes that are not found will remove the branch where digging was enabled on.
592592

593593
```ruby
594594
traversal_path = ['data', 'details', 'does_not_exist']
595595

596-
json.data(search: traversal_path) do
596+
json.data(dig: traversal_path) do
597597
json.details do
598598
json.personal do
599599
json.name 'james'
@@ -642,7 +642,7 @@ will render Layout first, then the template when `yield json` is used.
642642

643643
## Change key format
644644
By default, keys are not formatted. This is intentional. By being explicity with your keys,
645-
it makes your views quicker and more easily searchable when working in Javascript land.
645+
it makes your views quicker and more easily diggable when working in Javascript land.
646646

647647
If you must change this behavior, override it in an initializer and cache the value:
648648

lib/props_template.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,15 @@ def initialize(context = nil, options = {})
3636
end
3737

3838
def set!(key, options = {}, &block)
39-
if block && options[:search] && !@builder.is_a?(Searcher)
39+
if block && (options[:search] || options[:dig]) && !@builder.is_a?(Searcher)
40+
search = options[:search] || options[:dig]
4041

4142
prev_builder = @builder
42-
@builder = Searcher.new(self, options[:search], @context)
43+
@builder = Searcher.new(self, search, @context)
44+
4345
options.delete(:search)
46+
options.delete(:dig)
47+
4448
@builder.set!(key, options, &block)
4549
found_block, found_options = @builder.found!
4650
@builder = prev_builder

0 commit comments

Comments
 (0)