ActivePath:

View injection and path hints for Rails 5.

Installation

Add to your Gemfile:

gem 'active_path'

Add the initializer config/initializers/active_path.rb and enable ActivePath:


ActivePath.configure do |config|

  config.enabled = true

end

Configuration

View injection:


ActivePath.configure do |config|

  ...

  config.partials.prepend('pages/content').with('example/test')

end

The above example assumes your application renders a partial called 'pages/content' and you want to prepend a partial called 'example/test'.

Your partial will have the same local parameters access as the prepended partial. You can also use append:


config.partials.append('pages/content').with('example/test')

The above renders 'example/test' after 'pages/content'.

--

Conditions:

The when method allows you to conditionally inject your view. Consider this partial:

render partial: 'pages/content', locals: { page_id: 9 }

You can pass in a hash which must match the local variables.


config.partials.append('pages/content').with('example/test').when(page_id: 9)

Or pass in a block for more flexibility with your conditions:


config.partials.append('pages/content').with('example/test').when do |locals|
  locals[:page_id] == 9
end

--

Path hints: (use in development only)


config.path_hints = true

HTML comments are added before and after each partial. Here is the output from our above examples:

<!-- start pages/content -->
<p>page content</p>
<!-- end pages/content -->
<!-- start example/test -->
<p>example content</p>
<!-- end example/test -->

Feel free to submit issues or help make it better.