Skip to content

Commit

Permalink
Use prepend for Rails 5 compatibility
Browse files Browse the repository at this point in the history
added standard themes locally for testing
  • Loading branch information
RosselloAzcom committed Jan 12, 2020
1 parent 678c306 commit 6e252b4
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 58 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Redmine Pluggable Themes

Tested with Redmine 3.4.6, 3.4.7.
Supports Redmine 4.0.x.

Allows Redmine plugins to provide themes just like other assets.

Expand Down
4 changes: 2 additions & 2 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
name 'Redmine Pluggable Themes plugin'
author 'Massimo Rossello'
description 'Allows plugins to export themes in assets'
version '1.0.0'
version '4.0.0'
url 'https://github.com/maxrossello/redmine_pluggable_themes.git'
author_url 'https://github.com/maxrossello'
requires_redmine :version_or_higher => '3.4.0'
requires_redmine :version_or_higher => '4.0.0'

end

Expand Down
83 changes: 29 additions & 54 deletions lib/themes_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,70 +21,45 @@
# SOFTWARE.

module ThemesPatch
def self.included(base) # :nodoc:
base.extend(ClassMethods)

base.class_eval do
unloadable
class << self
alias_method_chain :scan_themes, :plugins
end
end
end

module ClassMethods
def scan_themes_with_plugins
dirs = Dir.glob("#{Rails.public_path}/plugin_assets/*/themes/*").select do |f|
# A theme should at least override application.css
File.directory?(f) && File.exist?("#{f}/stylesheets/application.css")
end
dirs.collect! {|dir| Redmine::Themes::Theme.new(dir)}
dirs = scan_themes_without_plugins + dirs
dirs.sort { |x,y| x <=> y }
end
end
def scan_themes
dirs = Dir.glob("#{Rails.public_path}/plugin_assets/*/themes/*").select do |f|
# A theme should at least override application.css
File.directory?(f) && File.exist?("#{f}/stylesheets/application.css")
end
dirs.collect! {|dir| Redmine::Themes::Theme.new(dir)}
dirs = super + dirs
dirs.sort { |x,y| x <=> y }
end
end

module ThemePatch
def self.included(base) # :nodoc:
base.send(:include, InstanceMethods)
base.class_eval do
unloadable
alias_method_chain :stylesheet_path, :plugins
alias_method_chain :image_path, :plugins
alias_method_chain :javascript_path, :plugins
alias_method_chain :favicon_path, :plugins
end
end

module InstanceMethods
def theme_path
@path.match('^.*public(/.*)')[1]
end
def theme_path
@path.match('^.*public(/.*)')[1]
end

def stylesheet_path_with_plugins(source)
"#{theme_path}/stylesheets/#{source}"
end
def stylesheet_path(source)
"#{theme_path}/stylesheets/#{source}"
end

def image_path_with_plugins(source)
"#{theme_path}/images/#{source}"
end
def image_path(source)
"#{theme_path}/images/#{source}"
end

def javascript_path_with_plugins(source)
"#{theme_path}/javascripts/#{source}"
end
def javascript_path(source)
"#{theme_path}/javascripts/#{source}"
end

def favicon_path_with_plugins
"#{theme_path}/favicon/#{favicon}"
end
end
def favicon_path
"#{theme_path}/favicon/#{favicon}"
end
end

unless Redmine::Themes.included_modules.include?(ThemesPatch)
Redmine::Themes.send(:include, ThemesPatch)
unless Redmine::Themes::Theme.included_modules.include?(ThemePatch)
Redmine::Themes::Theme.send(:prepend, ThemePatch)
end

unless Redmine::Themes::Theme.included_modules.include?(ThemePatch)
Redmine::Themes::Theme.send(:include, ThemePatch)
unless Redmine::Themes.singleton_class.included_modules.include?(ThemesPatch)
Redmine::Themes.singleton_class.send(:prepend, ThemesPatch)
#Redmine::Themes.rescan
end

79 changes: 79 additions & 0 deletions test/fixtures/public/themes/foo/stylesheets/application.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
@import url(/stylesheets/application.css);

body, #wrapper { background-color:#EEEEEE; }
#header, #top-menu { margin: 0px 10px 0px 11px; }
#main { background: #EEEEEE; margin: 8px 10px 0px 10px; }
#content, #main.nosidebar #content { background: #fff; border-right: 1px solid #bbb; border-bottom: 1px solid #bbb; border-left: 1px solid #d7d7d7; border-top: 1px solid #d7d7d7; }
#footer { background-color:#EEEEEE; border: 0px; }

/* Headers */
h2, h3, h4, .wiki h1, .wiki h2, .wiki h3 {border-bottom: 0px;}

/* Menu */
#main-menu li a { background-color: #507AAA; font-weight: bold;}
#main-menu li a:hover { background: #507AAA; text-decoration: underline; }
#main-menu li a.selected, #main-menu li a.selected:hover { background-color:#EEEEEE; }
#main-menu li a.new-object { background-color:#507AAA; text-decoration: none; }

#main-menu .menu-children {
border-right: 1px solid #507AAA;
border-bottom: 1px solid #507AAA;
border-left: 1px solid #507AAA;
}
#main-menu .menu-children li a:hover { background-color: #507AAA;}


/* Tables */
table.list tbody td, table.list tbody tr:hover td { border: solid 1px #d7d7d7; }
table.list thead th {
border-width: 1px;
border-style: solid;
border-top-color: #d7d7d7;
border-right-color: #d7d7d7;
border-left-color: #d7d7d7;
border-bottom-color: #999999;
}

/* Issues grid styles by priorities (provided by Wynn Netherland) */
table.list tr.issue a { color: #666; }

tr.odd.priority-highest, table.list tbody tr.odd.priority-highest:hover { color: #900; font-weight: bold; }
tr.odd.priority-highest { background: #ffc4c4; }
tr.even.priority-highest, table.list tbody tr.even.priority-highest:hover { color: #900; font-weight: bold; }
tr.even.priority-highest { background: #ffd4d4; }
tr.priority-highest a, tr.priority-5:hover a { color: #900; }
tr.odd.priority-highest td, tr.even.priority-highest td { border-color: #ffb4b4; }

tr.odd.priority-high2, table.list tbody tr.odd.priority-high4:hover { color: #900; }
tr.odd.priority-high2 { background: #ffc4c4; }
tr.even.priority-high2, table.list tbody tr.even.priority-high4:hover { color: #900; }
tr.even.priority-high2 { background: #ffd4d4; }
tr.priority-high2 a { color: #900; }
tr.odd.priority-high2 td, tr.even.priority-high4 td { border-color: #ffb4b4; }

tr.odd.priority-high3, table.list tbody tr.odd.priority-high3:hover { color: #900; }
tr.odd.priority-high3 { background: #fee; }
tr.even.priority-high3, table.list tbody tr.even.priority-high3:hover { color: #900; }
tr.even.priority-high3 { background: #fff2f2; }
tr.priority-high3 a { color: #900; }
tr.odd.priority-high3 td, tr.even.priority-high3 td { border-color: #fcc; }

tr.odd.priority-lowest, table.list tbody tr.odd.priority-lowest:hover { color: #559; }
tr.odd.priority-lowest { background: #eaf7ff; }
tr.even.priority-lowest, table.list tbody tr.even.priority-lowest:hover { color: #559; }
tr.even.priority-lowest { background: #f2faff; }
tr.priority-lowest a { color: #559; }
tr.odd.priority-lowest td, tr.even.priority-lowest td { border-color: #add7f3; }

/* Buttons */
input[type="button"], input[type="submit"], input[type="reset"] { background-color: #f2f2f2; color: #222222; border: 1px outset #cccccc; }
input[type="button"]:hover, input[type="submit"]:hover, input[type="reset"]:hover { background-color: #ccccbb; }

/* Fields */
input[type="text"], input[type="password"], textarea, select { padding: 2px; border: 1px solid #d7d7d7; }
input[type="text"], input[type="password"] { padding: 3px; }
input[type="text"]:focus, input[type="password"]:focus, textarea:focus, select:focus { border: 1px solid #888866; }
option { border-bottom: 1px dotted #d7d7d7; }

/* Misc */
.box { background-color: #fcfcfc; }
5 changes: 4 additions & 1 deletion test/integration/themes_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@

class ThemesTest < Redmine::IntegrationTest

include CommonPluggableThemesTestHelper

def setup
Redmine::Themes.rescan
default_setup
@theme = Redmine::Themes.themes.last
Setting.ui_theme = @theme.id
@path = @theme.path.split('public')[1]
end

def teardown
default_teardown
Setting.ui_theme = ''
end

Expand Down
12 changes: 12 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,15 @@

# Load the Redmine helper
require File.expand_path('../../../../test/test_helper', __FILE__)

module CommonPluggableThemesTestHelper
def default_setup
Redmine::Themes.stubs(:scan_themes).returns([Redmine::Themes::Theme.new(File.dirname(__FILE__) + "/fixtures/public/themes/foo")])
Redmine::Themes.rescan
end

def default_teardown
Redmine::Themes.unstub(:scan_themes)
Redmine::Themes.rescan
end
end
6 changes: 6 additions & 0 deletions test/unit/application_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@
class ApplicationHelperTest < Redmine::HelperTest
#include ERB::Util
include Rails.application.routes.url_helpers
include CommonPluggableThemesTestHelper

def setup
super
default_setup
end

def teardown
default_teardown
end

def test_image_tag_should_pick_the_theme_image_if_it_exists
Expand Down

0 comments on commit 6e252b4

Please sign in to comment.