Sha256: c1189c6ac7e64a322fb42f771c8c69b4d2ff711c1d756cb5aed4a8f575f4f572

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

# Add a new view hook into Redmine's template
MoreViewHooks.add(
  :layout_base_logged_as_before,
  virtual_path:  "layouts/base",
  insert_before: "#top-menu erb[loud]:contains('if User.current.logged?')" \
                 ":contains('content_tag')"
)

module PersonalWikiPage
  class Hooks < Redmine::Hook::ViewListener
    def view_layouts_base_html_head(_context)
      stylesheet_link_tag "personal_wiki_page", plugin: "personal_wiki_page"
    end

    def layout_base_logged_as_before(context)
      return "" if user.anonymous?
      view_context = context[:controller].view_context

      view_context.content_tag :ul, class: "personal-wiki-page" do
        view_context.content_tag :li do
          link_to_wiki_page
        end
      end
    end

    private

    def link_to_wiki_page
      link_to l(:personal_wiki_page_link), personal_wiki_path
    end

    def personal_wiki_path
      project_wiki_page_path(project_id: project, id: page)
    end

    def settings
      Setting.plugin_personal_wiki_page
    end

    def project
      settings["project"]
    end

    def prefix
      settings["prefix"]
    end

    def user
      User.current
    end

    def page
      "#{prefix}#{user.login}"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
redmine-personal_wiki_page-0.0.1 lib/personal_wiki_page/hooks.rb