From 844718cd0053f0ce4e39d5c393b1403d1c0d7392 Mon Sep 17 00:00:00 2001 From: jho406 Date: Thu, 21 Nov 2024 04:53:14 -0500 Subject: [PATCH] Update docs for partials (#39) --- README.md | 26 ++++++++++++++++++++++++-- spec/props_template_spec.rb | 1 + 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 745575c..2f90c1c 100644 --- a/README.md +++ b/README.md @@ -337,10 +337,32 @@ json.posts do end ``` -Usage for rendering partial without assigning it to some key: +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. + +Do: + +```ruby +json.partial! partial: "header", locals: {user: @user} do +end +``` + +or ```ruby -json.partial! partial: "posts/blog_post", locals: {post: @post} do +json.posts do + json.array! @posts, partial: ["posts/blog_post", locals: {post: @post}] do + end +end +``` + +Do NOT: + +``` +@post.each do |post| + json.partial! partial: "post", locals: {post: @post} do + end end ``` diff --git a/spec/props_template_spec.rb b/spec/props_template_spec.rb index b9fd6f6..9c3b88e 100644 --- a/spec/props_template_spec.rb +++ b/spec/props_template_spec.rb @@ -1,4 +1,5 @@ require_relative "support/helper" +require_relative "support/rails_helper" RSpec.describe "Props::Base" do it "initializes" do