Project

haken

0.0
No release in over 3 years
Low commit activity in last 3 years
Haken allows you to define places in your views where additional content can be injected from elsewhere(for example, a seperate rails engine)
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

Haken

A very simple gem for extending views by injecting additional content.

When building applications that use the bounded context 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:

gem 'haken'

Usage

Define a place where additional content can be injected:

views/layouts/_navbar.html.erb

<nav>
  <%= load_view_hooks_for :navbar %>
</nav>

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:

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.