jbuilder-jpartial 0.2.3 → 0.2.4
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/version.rb +1 -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: '0678a8be58d6a3469f3d25214d69aacfea9b3e63'
|
4
|
+
data.tar.gz: 314f6cddd18c7c9140fa7aae548b385c43232858
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abd034de8322e17d784545c923dd9f84932491ec14f0a341951b06088dbfb683607c3a105c8d7d7c892da2ec348e7f2bf90b593012a1bfc9b00137879070d938
|
7
|
+
data.tar.gz: f235af7623dae7aca81358e37f5a3597909ce971623bdeadb5f3066bded9644eb6b3e903624fb2d29fa0381ce60d476e3cc8cb18c1c77ec6720688f8de12f7f2
|
data/README.md
CHANGED
@@ -74,9 +74,9 @@ 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,
|
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
|
-
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 advantage here is
|
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
|
|
81
81
|
#### In `app/config/initializers/jpartial.rb`
|
82
82
|
```ruby
|
@@ -106,7 +106,7 @@ end
|
|
106
106
|
|
107
107
|
Notice that when using this method, we don't make any calls like `json.partial! 'post'` at any point to define the partial before using it. All of the partials are already defined in the initializer file.
|
108
108
|
|
109
|
-
|
109
|
+
We've now cut our template renders down to only 1 from the original 2,550. The only real disadvantage is it bucks the regular Rails file structure conventions for partials. C'est la vie.
|
110
110
|
|
111
111
|
#### How?
|
112
112
|
Each method you call on `jpartial` defines a Jbuilder method of the same name. The objects you will pass to that method are yielded to the block. Inside the block you can use plain old Jbuilder syntax.
|