jbuilder-jpartial 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/jbuilder/jpartial.rb +1 -0
- data/lib/jbuilder/jpartial/version.rb +7 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4f538f73814c66cb307f2c2cdba5b3962b64252
|
4
|
+
data.tar.gz: 36141cbfa5ca65b536ec50d7f8a191aa36731e63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34b6dc9be02b7839d03e88e6f64b188cf83681dff973d6a0fb2c6cfdc65c172704bf31bc8b17a690c5a5c7929b0c5f20dbf1a75f76e33e92c7f5019e3cdd77d3
|
7
|
+
data.tar.gz: 1159057018c7fd64b9ea7e58d462ecad2a610bdb9e8c3ccfd513c6cd528f03dcfce0fd7428bdcb1e56bc33ba90baf3a9ae07725762a86f0c3d6c353f2166393b
|
data/README.md
CHANGED
@@ -74,7 +74,7 @@ When partials are used with `Jbuilder` render times and memory usage can skyrock
|
|
74
74
|
|
75
75
|
Using a simple DSL, `Jbuilder::Jpartial` lets you define your partials in a familiar way while dramatically reducing overhead.
|
76
76
|
|
77
|
-
The result is faster rendering and lower memory usage, while still being able to leverage the advantages of Jbuilder. In the above example, if we had used standard Jbuilder partials those templates would have to be rendered once for each `post` and/or `comment`. If you have 50 posts, each with 50 comments, that's 2,550 templates rendered! Using `Jbuilder::Jpartial`, the partial files are each only called when the partial is initialized. After that, all of the partial rendering is taken care of in the abstract from the original file. In our example, we hit `json.partial! 'post'` once and `json.partial! 'comments/comment' only once for each `post`, cutting 2,550 template renders down to 51.
|
77
|
+
The result is faster rendering and lower memory usage, while still being able to leverage the advantages of Jbuilder. In the above example, if we had used standard Jbuilder partials those templates would have to be rendered once for each `post` and/or `comment`. If you have 50 posts, each with 50 comments, that's 2,550 templates rendered! Using `Jbuilder::Jpartial`, the partial files are each only called when the partial is initialized. After that, all of the partial rendering is taken care of in the abstract from the original file. In our example, we hit `json.partial! 'post'` once and `json.partial! 'comments/comment'` only once for each `post`, cutting 2,550 template renders down to 51.
|
78
78
|
|
79
79
|
Alternatively you can define all partials in one initializer file and call them wherever you need them: from within other partial definitions or anywhere you use `Jbuilder` in your views. The big advantage here is since they're initialized at start up, you don't need to call any additional view templates to render the partials. Using the same example as above:
|
80
80
|
|
@@ -123,7 +123,7 @@ Now in your `.jbuilder` templates you can call `json._post @post`.
|
|
123
123
|
|
124
124
|
You can specify multiple arguments and even use keyword options if you need to pass more than one local variable to the partial. You can also call partial methods from within other partial methods.
|
125
125
|
|
126
|
-
The rule of thumb when defining your partials in
|
126
|
+
The rule of thumb when defining your partials in view templates is you need to make sure the partial is initialized by making a call to the template, outside of your render logic and/or any loops/iteration.
|
127
127
|
|
128
128
|
e.g.
|
129
129
|
|
@@ -162,7 +162,7 @@ end
|
|
162
162
|
|
163
163
|
However unlikely, if you try to name a partial with the same name as a method already defined by Jbuilder it will throw an error at start up. Just pick a different name, like `#whatever_partial` instead of `#whatever`.
|
164
164
|
|
165
|
-
Methods taken by this library are `Jbuilder#json` and any route helpers e.g. `Jbuilder#post_url`. If you have or need any fields with keys like `"json"` or `"post_url"` use `Jbuilder#set!`, e.g.
|
165
|
+
Methods taken by this library are `Jbuilder#json` and any valid route helpers defined by your app e.g. `Jbuilder#post_url`. If you have or need any fields with keys like `"json"` or `"post_url"` use `Jbuilder#set!`, e.g.
|
166
166
|
```ruby
|
167
167
|
json.set! 'json', 'some value'
|
168
168
|
json.set! 'post_url', 'some url'
|
data/lib/jbuilder/jpartial.rb
CHANGED