Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
akiko-pusu committed Nov 6, 2011
0 parents commit 72a2669
Show file tree
Hide file tree
Showing 17 changed files with 192 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
= Redmine Banner Plugin

Plugin to show site-wide message, such as maintenacne informations or notifications.

=== Plugin installation

1. Copy the plugin directory into the vendor/plugins directory.
2. Go to plugin's page and click "Settings" link of Redmine Banner Plugin.
You can edit banner message.

11 changes: 11 additions & 0 deletions app/controllers/banner_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class BannerController < ApplicationController
unloadable

def preview
@text = params[:settings][:banner_description]
render :partial => 'common/preview'
end

def show
end
end
5 changes: 5 additions & 0 deletions app/helpers/banner_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module BannerHelper
def escape_single_quote(data)
return data.gsub("'","&rsquo;")
end
end
26 changes: 26 additions & 0 deletions app/views/settings/_redmine_banner.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<p>
<%=content_tag(:label, "プラグインを有効にする")%>
<%=check_box_tag 'settings[enable]', true, @settings['enable'] == "true" %>
</p>

<p>
<%=content_tag(:label, "メッセージのタイプ")%>
<%= radio_button_tag 'settings[type]', "info", @settings['type'] == "info" %> <span class="banner_info">Info</span><br>
<%= radio_button_tag 'settings[type]', "warn", @settings['type'] == "warn" %> <span class="banner_warn">Warn</span><br>
<%= radio_button_tag 'settings[type]', "alert", @settings['type'] == "alert" %> <span class="banner_alert">Alert </span>
</p>

<p>
<%=content_tag(:label, "バナーメッセージ") %>
<%=text_area_tag 'settings[banner_description]', @settings['banner_description'], :size =>"40x3",
:class => 'wiki-edit' ,:required => true %><br/>
<%= wikitoolbar_for "settings_banner_description" %>
<%= link_to_remote l(:label_preview),
{ :url => { :controller => 'banner', :action => 'preview'},
:method => 'post',
:id => 'banner_preview',
:update => 'banner_description_preview',
:with => "Form.serialize('plugin')",
:complete => "Element.scrollTo('banner_description_preview')"
}, :accesskey => accesskey(:preview) %>
<div id="banner_description_preview" class="wiki"></div>
10 changes: 10 additions & 0 deletions app/views/settings/plugin.rhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<h2><%= l(:label_settings) %>: <%=h @plugin.name %></h2>

<div id="settings">
<% form_tag({:action => 'plugin'},{:id => :plugin }) do %>
<div class="box tabular">
<%= render :partial => @partial, :locals => {:settings => @settings}%>
</div>
<%= submit_tag l(:button_apply) %>
<% end %>
</div>
Binary file added assets/images/Info.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/alert.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/info.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/warn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions assets/stylesheets/banner.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
.banner {
border-style: solid;
border-width: 1px;
/*
background-image: url(/plugin_assets/redmine_banner/images/info.png);
background-repeat: no-repeat;
background-position: left;
*/
margin: 5px 10px;
padding-left: 34px;
padding: 5px 20px;
}

div.banner_info {
border-color: #b0c4de;
background: #f0f8ff url(/plugin_assets/redmine_banner/images/info.png) no-repeat left center;
}

div.banner_warn {
border-color: #f3d51a;
background: #f9f99e url(/plugin_assets/redmine_banner/images/warn.png) no-repeat left center;
}

div.banner_alert {
background-color: #ffe3e3;
border-color: #dd0000;
background: #ffe3e3 url(/plugin_assets/redmine_banner/images/alert.png) no-repeat left center;
}

span.banner_info {
background-image: url(/plugin_assets/redmine_banner/images/info.png);
background-repeat: no-repeat;
background-position: left center;
padding-left: 26px;
}

span.banner_warn {
background-image: url(/plugin_assets/redmine_banner/images/warn.png);
background-repeat: no-repeat;
background-position: left center;
padding-left: 26px;
}

span.banner_alert {
background-image: url(/plugin_assets/redmine_banner/images/alert.png);
background-repeat: no-repeat;
background-position: left center;
padding-left: 26px;
}

3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# English strings go here for Rails i18n
en:
banner: "Banner"
3 changes: 3 additions & 0 deletions config/locales/ja.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# English strings go here for Rails i18n
ja:
banner: "バナー"
18 changes: 18 additions & 0 deletions init.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'redmine'
require 'banner_application_hooks'

Redmine::Plugin.register :redmine_banner do
name 'Redmine Banner plugin'
author 'Akiko Takano'
description 'Plugin to show site-wide message, such as maintenacne informations or notifications.'
version '0.0.1'
requires_redmine :version_or_higher => '1.2.0'

settings :partial => 'settings/redmine_banner',
:default => {
'enable' => 'false',
'banner_description' => 'exp. Information about upcoming Service Interruption.',
'type' => 'info'
}

end
2 changes: 2 additions & 0 deletions lang/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# English strings go here
banner: "Banner"
41 changes: 41 additions & 0 deletions lib/banner_application_hooks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class BannerApplicationHooks < Redmine::Hook::ViewListener
def view_layouts_base_html_head(context = {})
return '' unless Setting.plugin_redmine_banner['enable'] == "true"
o = ''
o << stylesheet_link_tag('banner', :plugin => 'redmine_banner')
o << '<script type="text/javascript">'
o << 'Event.observe(window, \'load\', window_onload);'
o << ' function window_onload(evt){'
o << " $( \'top-menu\' ).insert({after:\'"
o << textilize_banner(Setting.plugin_redmine_banner['banner_description'])
o << '\'});'
o << '}'
o << '</script>'

return o
end

def view_layouts_base_body_bottom(context = {})
return '' unless Setting.plugin_redmine_banner['enable'] == "true"
o = ''
o << textilize_banner(Setting.plugin_redmine_banner['banner_description'])
return o
end

private
def escape_single_quote(data)
return data.gsub("'","&rsquo;")
end

def textilize_banner(data)
o = ''
o << '<div class="banner banner_'
o << Setting.plugin_redmine_banner['type']
o << '">'
o << escape_single_quote(textilizable(data))
o << '</div>'
return o
end

end

8 changes: 8 additions & 0 deletions test/functional/banner_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require File.dirname(__FILE__) + '/../test_helper'

class BannerControllerTest < ActionController::TestCase
# Replace this with your real tests.
def test_truth
assert true
end
end
5 changes: 5 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Load the normal Rails helper
require File.expand_path(File.dirname(__FILE__) + '/../../../../test/test_helper')

# Ensure that we are using the temporary fixture path
Engines::Testing.set_fixture_path

0 comments on commit 72a2669

Please sign in to comment.