Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dnamsons/haken
Load hooks in views
https://github.com/dnamsons/haken
actionview rails
Last synced: 11 days ago
JSON representation
Load hooks in views
- Host: GitHub
- URL: https://github.com/dnamsons/haken
- Owner: dnamsons
- License: mit
- Created: 2022-10-10T20:18:10.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2023-09-04T08:29:32.000Z (about 1 year ago)
- Last Synced: 2024-09-23T01:59:59.164Z (about 2 months ago)
- Topics: actionview, rails
- Language: Ruby
- Homepage:
- Size: 3.91 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Haken
A very simple gem for extending views by injecting additional content.
When building applications that use the [bounded context](https://martinfowler.com/bliki/BoundedContext.html) pattern, there can be situations when a context A influences the presentation logic of context B. This library is an experiment of introducing a pseudo PubSub architecture for injecting front-end views to solve these types of problems.
## Installation
Add this line to your Gemfile and then execute bundle install:
```rb
gem 'haken'
```## Usage
Define a place where additional content can be injected:
`views/layouts/_navbar.html.erb`
```erb<%= load_view_hooks_for :navbar %>
```
Then you can define a partial elsewhere(for example in a different Rails engine) and inject it into the navbar via an initializer like this:
```rb
module MyEngine
class Engine < Rails::Engine
initializer 'my_engine.view_hooks' do
Haken.on_load(:navbar) { render 'layouts/my_engine/navbar_extension' }
end
end
end
```## Roadmap
We currently only support simple injections without any control over priority (if there are two *subscriptions* for a view hook, the priority they will be rendered in depends on the initialization sequence of the Rails engines they are defined in).
Next step for improving this library is to introduce a priority system.