Skip to content

Commit

Permalink
Merge pull request sidekiq#2270 from davydovanton/overall-css
Browse files Browse the repository at this point in the history
Added helper which provide ability to add your html to <head> tag
  • Loading branch information
mperham committed Mar 30, 2015
2 parents 2c3b24c + fc144dd commit 71e5237
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<head>` tag [#2270]
- Web UI polling now uses Ajax to avoid page reload [#2266]
- Add Sidekiq::Process#dump\_threads API to trigger TTIN output [#2247]

Expand Down
25 changes: 25 additions & 0 deletions lib/sidekiq/web_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,31 @@ def strings
def filtering(*)
end

# This view helper provide ability display you html code in
# to head of page. Example:
#
# <% add_to_head do %>
# <link rel="stylesheet" .../>
# <meta .../>
# <% 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'
Expand Down
1 change: 1 addition & 0 deletions web/views/layout.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<script type="text/javascript" src="<%= root_path %>javascripts/application.js"></script>
<script type="text/javascript" src="<%= root_path %>javascripts/locales/jquery.timeago.<%= locale %>.js"></script>
<meta name="google" content="notranslate" />
<%= display_custom_head %>
</head>
<body class="admin">
<%= erb :_nav %>
Expand Down

0 comments on commit 71e5237

Please sign in to comment.