Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typos and improve README.md #41

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ json.set! :authorDetails, {...options} do
json.set! :firstName, 'David'
end

or
# or
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In code snippets like this, if non-ruby code is not commented it will mess up the syntax highligting:
Screenshot 2025-01-02 at 10 23 31


json.authorDetails, {...options} do
json.firstName 'David'
Expand All @@ -121,7 +121,7 @@ The inline form defines key and value

json.set! :firstName, 'David'

or
# or

json.firstName 'David'

Expand All @@ -138,13 +138,13 @@ The block form defines key and structure

```ruby
json.set! :details do
...
...
end

or

json.details do
...
...
end
```

Expand Down Expand Up @@ -199,7 +199,7 @@ end

| Parameter | Notes |
| :--- | :--- |
| collection | A collection that responds to `member_at` and `member_by` |
| collection | A collection that optionally responds to `member_at` and `member_by` |
| options | Additional [options](#options)|

To support [digging](#digging), any list passed
Expand Down Expand Up @@ -230,7 +230,7 @@ data = ObjectCollection.new([
])

json.array! data do
...
...
end
```

Expand All @@ -252,7 +252,7 @@ Then in your template:

```ruby
json.array! Post.all do
...
...
end
```

Expand All @@ -270,7 +270,7 @@ data = [

json.posts
json.array! data do
...
# ...
end
end
```
Expand Down Expand Up @@ -306,7 +306,7 @@ option.
`application.json.props` when first running `rails superglue:install:web`

## Options
Options Functionality such as Partials, Deferements, and Caching can only be
Options Functionality such as Partials, Deferments, and Caching can only be
set on a block. It is normal to see empty blocks.

```ruby
Expand Down Expand Up @@ -339,7 +339,7 @@ end

Rendering partials without a key is also supported using `json.partial!`, but use
sparingly! `json.partial!` is not optimized for collection rendering and may
cause performance problems. Its best used for things like a shared header or footer.
cause performance problems. It's best used for things like a shared header or footer.

Do:

Expand All @@ -359,7 +359,7 @@ end

Do NOT:

```
```ruby
@post.each do |post|
json.partial! partial: "post", locals: {post: @post} do
end
Expand Down Expand Up @@ -406,12 +406,12 @@ json.author(cache: "some_cache_key") do
json.firstName "tommy"
end

#or
# or

json.profile(cache: "cachekey", partial: ["profile", locals: {foo: 1}]) do
end

#or nest it
# or nest it

json.author(cache: "some_cache_key") do
json.address(cache: "some_other_cache_key") do
Expand All @@ -431,7 +431,7 @@ json.array! [4,5], opts do |x|
json.top "hello" + x.to_s
end

#or on arrays with partials
# or on arrays with partials

opts = { cache: (->(d){ ['a', d.id] }), partial: ["blog_post", as: :blog_post] }

Expand All @@ -449,7 +449,7 @@ tabbed content that does not load until you click the tab.
When your client receives the payload, you may issue a second request to the
same endpoint to fetch any missing nodes. See [digging](#digging)

There is also an `defer: :auto` option that you can use with [SuperglueJS][1]. [SuperglueJS][1]
There is also a `defer: :auto` option that you can use with [SuperglueJS][1]. [SuperglueJS][1]
will use the metadata from `json.deferred!` to issue a `remote` dispatch to fetch
the missing node and immutably graft it at the appropriate keypath in your Redux
store.
Expand Down Expand Up @@ -489,10 +489,10 @@ json.defers json.deferred!
```

#### Working with arrays
The default behavior for deferements is to use the index of the collection to
The default behavior for deferments is to use the index of the collection to
identify an element.

**Note** If you are using this library with [SuperglueJS][1], the `:auto` options will
**Note** If you are using this library with [SuperglueJS][1], the `:auto` option will
generate `?props_at=a.b.c.0.title` for `json.deferred!`.

If you wish to use an attribute to identify the element. You must:
Expand Down Expand Up @@ -525,7 +525,7 @@ json.posts
end
```

If you are using [SuperglueJS][1], SuperglueJS will, it will automatically kick off
If you are using [SuperglueJS][1], it will automatically kick off
`remote(?props_at=posts.some_id=1.contact)` and `remote(?props_at=posts.some_id=2.contact)`.

## Digging
Expand All @@ -540,7 +540,7 @@ traversal_path = ['data', 'details', 'personal']
json.data(dig: traversal_path) do
json.details do
json.employment do
...more stuff
# ...more stuff
end

json.personal do
Expand All @@ -551,12 +551,12 @@ json.data(dig: traversal_path) do
end

json.footer do
...
# ...
end
```

PropsTemplate will walk depth first, walking only when it finds a matching key,
then executes the associated block, and repeats until it the node is found.
then executes the associated block, and repeats until the node is found.
The above will output:

```json
Expand All @@ -575,7 +575,7 @@ Digging only works with blocks, and will NOT work with Scalars
("leaf" values). For example:

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

json.data(dig: traversal_path) do
json.details do
Expand All @@ -602,7 +602,7 @@ json.data(dig: traversal_path) do
end

json.footer do
...
# ...
end
```

Expand Down Expand Up @@ -641,8 +641,8 @@ json.flash flash.to_h
will render Layout first, then the template when `yield json` is used.

## Change key format
By default, keys are not formatted. This is intentional. By being explicity with your keys,
it makes your views quicker and more easily diggable when working in Javascript land.
By default, keys are not formatted. This is intentional. By being explicit with your keys,
it makes your views quicker and more easily diggable when working in JavaScript land.

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

Expand Down
Loading