Makes it easy to name and render multiple content areas in a partial,
instead of being limited to just the one yield
.
Install the gem and add to the Rails application's Gemfile by executing:
$ bundle add render_with_areas
Include it in ApplicationHelper
in your Rails app:
module ApplicationHelper
include RenderWithAreas
end
Example:
<!-- app/views/ui/_modal.html.erb -->
<div class="modal">
<header class="modal__header">
<%= header %>
</header>
<main>
<%= content %>
</main>
<footer class="modal__footer">
<%= footer %>
</footer>
</div>
<!-- app/views/posts/show.html.erb -->
<%= render_with_areas do |layout| %>
<% layout.with :header do %>
<h1>Modal Title</h1>
<% end %>
This will show up as "content"
<% layout.with :footer do %>
This will show up in the modal footer.
<% end %>
<% end %>
<!-- also supports locals, strings -->
<%= render_with_areas, title: "Modal Title" do |layout| %>
This will show up as "content"
<% layout.with :footer, "Footer" %>
<% end %>
After checking out the repo, run bin/setup
to install dependencies. Then, run rake test
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and the created tag, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/render_with_areas. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the RenderWithAreas project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.