Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alexander-senko/active_model-inherited_partials
Rails Engine to let models inherit partials until overridden.
https://github.com/alexander-senko/active_model-inherited_partials
Last synced: 3 months ago
JSON representation
Rails Engine to let models inherit partials until overridden.
- Host: GitHub
- URL: https://github.com/alexander-senko/active_model-inherited_partials
- Owner: Alexander-Senko
- License: mit
- Created: 2024-01-23T15:09:07.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-06-28T23:32:01.000Z (8 months ago)
- Last Synced: 2024-11-10T09:06:20.403Z (3 months ago)
- Language: Ruby
- Homepage:
- Size: 28.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: MIT-LICENSE
Awesome Lists containing this project
README
## Rails partials
Rails partials are great when it comes to rendering a model. But they still seem to have inconsistencies and a room for further improvements.
Consider the following example: we have a model inheritance chain like `Message` → `Message::Text` → `Message::HTML`.
### Issue #1: your code gets WET
To render both text and HTML messages we need to define both `message/texts/text` & `message/htmls/html` partials — even when they are identical and just rendering `message.title` and `message.body`.### Issue #2: inconsistent variable naming
In the above case we get `text` & `html` variables inside the partials, while it's just `message` for the basic `messages/message` one. You can't even copy the identical code from one partial into another!### Issue #3: inconsistent paths
Both texts & HTML end up in `views/message`, while the basic message goes to `views/messages`. Thus we get two directories instead of one.So, meet
# Inherited PartialsThis Rails Engine brings you:
1. **Nesting** directories to respect model namespaces.
2. Consistent variable **naming** in namespaced partials.
3. **Inheritance** when a partial is missing.It provides the above example case with the following partial paths:
```
messages/message
messages/text/message
messages/html/message
```When a model's partial is missing, the parent's one is looked up, upto the basic one.
## Usage
No explicit code nor configuration needed, just install it!
## Installation
Add this line to your application's Gemfile:```ruby
gem "active_model-inherited_partials"
```And then execute:
```bash
$ bundle
```Or install it yourself as:
```bash
$ gem install active_model-inherited_partials
```## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).