No commit activity in last 3 years
No release in over 3 years
Allows adding more view hooks into Redmine's templates
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.7
~> 10.0

Runtime

~> 1.0.0
~> 4.2.0
 Project Readme

redmine-more_view_hooks

Gem Version Inline docs

Gem | Source | Documentation

Allows adding more view hooks into Redmine's templates

Installation

Ensure you have a Gemfile.local file in your Redmine installation. Add to your Gemfile.local:

gem "redmine-more_view_hooks"

And then execute:

$ bundle

Restart the Redmine application

Usage

Redmine already includes a concept of "view hooks", but not every place already has such a hook. For example, a hook before the user login status in the top menu is missing.

Let's assume the needed view hook would already exists at the desired position and would be called layout_base_logged_as_before. In this case one can simple write a new view hook listener as natively supported from Redmine:

class Hooks < Redmine::Hook::ViewListener
  # Redmine runs this method whenever a <%= call_hook(:layout_base_logged_as_before) %>
  # is included into the templates.
  # Attention: This view hook doesn't exists in Redmine and must be realized using this gem
  def layout_base_logged_as_before(context)
    content_tag :span, "Some additional content"
  end
end

To bring this to live we need to add this new view hook into Redmine's base layout template. Using this gem you can inject every needed view hooks into every possible template. The needed hook can be achieved using the following statement:

MoreViewHooks.add(
  # first the name of the new view hook
  :layout_base_logged_as_before,
  # now some Deface options to determine the correct position of the hook
  virtual_path:  "layouts/base",
  insert_before: "#top-menu erb[loud]:contains('if User.current.logged?'):contains('content_tag')"
)

For more information about the Deface options please have a look at their documentation.

The correct place to register new view hooks would be when initializing your Redmine plugin.

Avoiding hook definitions with identical names

Redmine allows multiple hook definitions with identical names across separate hook listeners.

MoreViewHooks.add disallows hook definitions using the same name. So this won't work:

MoreViewHooks.add(:unique_name, ...)

# raises "A view hook 'unique_name' already exists (ArgumentError)"
MoreViewHooks.add(:unique_name, ...)

Note: Defining a hook via MoreViewHooks.add re-using an existing Redmine hook name should work without problems.

Here is an example how to avoid duplicate hook names:

unless Redmine::Hook.hook_listeners(:view_projects_show_left).any?
  MoreViewHooks.add(:view_projects_show_left,
    virtual_path: "projects/show",
    insert_top:   "div.contextual"
  )
end

Tested Redmine versions

  • Redmine 1.x
  • Redmine 2.x
  • Redmine 3.0 - 3.2

Contributing

  1. Fork it ( https://github.com/neopoly/redmine-more_view_hooks/fork )
  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 a new Pull Request