From fc144ddd88ddec6bc53cb258bd983b31911e8a06 Mon Sep 17 00:00:00 2001 From: Anton Davydov Date: Wed, 11 Mar 2015 12:38:52 +0300 Subject: [PATCH] Added helper which provide ability to add your html to tag --- Changes.md | 1 + lib/sidekiq/web_helpers.rb | 25 +++++++++++++++++++++++++ web/views/layout.erb | 1 + 3 files changed, 27 insertions(+) diff --git a/Changes.md b/Changes.md index 5fbcc77b..f48951f4 100644 --- a/Changes.md +++ b/Changes.md @@ -3,6 +3,7 @@ HEAD - **Improve ActiveJob integration** - Web UI now shows ActiveJobs in a nicer format and job logging shows the actual class name [#2248, #2259] +- Added helper which provide ability to add your html code to page `` tag [#2270] - Web UI polling now uses Ajax to avoid page reload [#2266] - Add Sidekiq::Process#dump\_threads API to trigger TTIN output [#2247] diff --git a/lib/sidekiq/web_helpers.rb b/lib/sidekiq/web_helpers.rb index 37deb771..e88d5114 100644 --- a/lib/sidekiq/web_helpers.rb +++ b/lib/sidekiq/web_helpers.rb @@ -20,6 +20,31 @@ module Sidekiq def filtering(*) end + # This view helper provide ability display you html code in + # to head of page. Example: + # + # <% add_to_head do %> + # + # + # <% end %> + # + def add_to_head(&block) + @head_html ||= [] + @head_html << block if block_given? + end + + def display_custom_head + return unless @head_html + @head_html.map { |block| capture(&block) }.join + end + + # Simple capture method for erb templates. The origin was + # capture method from sinatra-contrib library. + def capture(&block) + block.call + eval('', block.binding) + end + def locale lang = (request.env["HTTP_ACCEPT_LANGUAGE"] || 'en').split(',')[0].downcase strings[lang] ? lang : 'en' diff --git a/web/views/layout.erb b/web/views/layout.erb index b27ca1e5..80d73374 100644 --- a/web/views/layout.erb +++ b/web/views/layout.erb @@ -8,6 +8,7 @@ + <%= display_custom_head %> <%= erb :_nav %>