## CHANGELOG ### 0.9.3 * Fixed: section predicates not respecting `local_assigns` content Previously, when doing something like this: ```erb <%= render "card", title: "Hello there" %> ``` If the inner card partial had this, ```erb <% if partial.title? %> <%= partial.title %> <% end %> ``` The `title?` predicate would fail, because it didn't look up content from the passed `local_assigns`. Now it does. ### 0.9.2 * Changed: view methods don't clobber section names Previously, we'd eagerly delegate to the view context so if the view had a `label` method, `partial.label` would call the view's `label` instead of making a `label` section. This was to support `partial.helpers` but we've changed the implementation to support the above. `partial.helpers` still works the same too. * Changed: `partial.helpers` no longer automatically calls `partial` methods Previously, if a user defined a partial helper like this: ```ruby partial.helpers do def some_helper some_section end end ``` If `some_section` wasn't a view method, it would automatically call `partial.some_section` thereby adding a new content section to the partial. Now `partial.helpers` behaves exactly like view helpers — making it easier to copy code directly when migrating — so users would have to explicitly call `partial.some_section`. ### 0.9.1 * Fix Ruby 2.7 compatibility ### 0.9.0 * Fix rendering with special characters in a view path. Ref: https://github.com/bullet-train-co/nice_partials/pull/70 * Seed Nice Partials content from `local_assigns` Previously, the only way to assign content to a Nice Partial was through passing a block: ```erb # app/views/posts/show.html.erb <%= render "posts/post", byline: "Some guy" %> # app/views/posts/_post.html.erb <%= render "card" do |partial| %> <% partial.title "Hello there" %> <% partial.byline byline %> <%# `byline` comes from the outer `render` call above. %> <% end %> Now, Nice Partials will automatically use Rails' `local_assigns`, which contain any `locals:` passed to `render`, as the seed for content. So this works: ```erb <%= render "card", title: "Hello there", byline: byline %> ``` And the `card` partial is now oblivious to whether its `title` or `byline` were passed as render `locals:` or through the usual assignments in a block. ```erb # app/views/_card.html.erb <%= partial.title %> written by <%= partial.byline %> ``` Previously to get this behavior you'd need to write: ```erb # app/views/_card.html.erb <%= partial.title.presence || local_assigns[:title] %> written by <%= partial.byline.presence || local_assigns[:byline] %> ``` Passing extra content via a block appends: ```erb <%= render "card", title: "Hello there" do |partial| %> <% partial.title ", and welcome!" %> # Calling `partial.title` outputs `"Hello there, and welcome!"` <% end %> ``` * Add `NicePartials::Partial#slice` Returns a Hash of the passed keys with their contents, useful for passing to other render calls: ```erb <%= render "card", partial.slice(:title, :byline) %> ``` * Fix `partial.helpers` accidentally adding methods to `ActionView::Base` When using `partial.helpers {}`, internally `class_eval` would be called on the Partial instance, and through `delegate_missing_to` passed on to the view context and thus we'd effectively have a global method, exactly as if we'd just used regular Rails view helpers. * Let partials respond to named content sections ```erb <% partial.content_for :title, "Title content" %> # Before <% partial.title "Title content" %> # After # Which can then be output <% partial.title %> # => "Title content" <% partial.title? %> # => true ``` Note, `title` responds to `present?` so rendering could also be made conditional with: ```erb <% partial.title if partial.title? %> # Instead of this… <% partial.title.presence %> # …you can do this ``` #### Passing procs or components Procs and objects that implement `render_in`, like ViewComponents, can also be appended as content: ```erb <% partial.title { "some content" } %> <% partial.title TitleComponent.new(Current.user) %> ``` #### Capturing `options` Options can also be captured and output: ```erb <% partial.title class: "text-m4" %> # partial.title.options # => { class: "text-m4" } # When output `to_s` is called and options automatically pipe through `tag.attributes`: