# nice_partials [![[version]](https://badge.fury.io/rb/nice_partials.svg)](https://badge.fury.io/rb/nice_partials) [![[travis]](https://travis-ci.org/andrewculver/nice_partials.svg)](https://travis-ci.org/andrewculver/nice_partials) Nice Partials provides a light layer of magic on top of traditional Rails view partials to try and make them an even better fit for extracting and reusing components in your views. Nice Partials is specifically designed to be a lightweight and more Rails-native alternative to [ViewComponent](http://viewcomponent.org) that hopefully provides many of the same benefits while requiring less ceremony. This specific approach originated with [Bullet Train](https://bullettrain.co)'s "Field Partials" and was later reimagined and reimplemented by Dom Christie. ## Benefits - They're just partials like you're used to, with a few extra features. - Less context switching. Your components are all just rendering in the standard view context. - You don't have to upgrade your existing partials. You can still nest them in a Nice Partials content area. - Less ceremony. You _can_ spin up a custom class to back your partial if you want to, but you don't have to by default, and we don't suggest it. - Instead, skip the component class entirely! You can define appropriately scoped helpers right inline with your partial. - It's still testable. There's no reason why these can't be as testable as ViewComponents. ## Setup Add to your `Gemfile`: ```ruby gem "nice_partials" ``` ## Usage ### Defining a Nice Partial We'll define an example Nice Partial in `app/views/partials/card`. We start by invoking Nice Partials like so: ``` <% yield p = np %> ``` We can explain what each thing is doing there later, but just trust us that it's the minimum viable invocation that we're aware of at the moment. After that, you can define your partial content and define your content areas: ```
<%= p.yield :body %>