##// END OF EJS Templates
Fixed: Themes are not applied with Rails 2.0...
Jean-Philippe Lang -
r1034:b2b56adbfa66
parent child
Show More
@@ -1,72 +1,76
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 module Redmine
18 module Redmine
19 module Themes
19 module Themes
20
20
21 # Return an array of installed themes
21 # Return an array of installed themes
22 def self.themes
22 def self.themes
23 @@installed_themes ||= scan_themes
23 @@installed_themes ||= scan_themes
24 end
24 end
25
25
26 # Rescan themes directory
26 # Rescan themes directory
27 def self.rescan
27 def self.rescan
28 @@installed_themes = scan_themes
28 @@installed_themes = scan_themes
29 end
29 end
30
30
31 # Return theme for given id, or nil if it's not found
31 # Return theme for given id, or nil if it's not found
32 def self.theme(id)
32 def self.theme(id)
33 themes.find {|t| t.id == id}
33 themes.find {|t| t.id == id}
34 end
34 end
35
35
36 # Class used to represent a theme
36 # Class used to represent a theme
37 class Theme
37 class Theme
38 attr_reader :name, :dir, :stylesheets
38 attr_reader :name, :dir, :stylesheets
39
39
40 def initialize(path)
40 def initialize(path)
41 @dir = File.basename(path)
41 @dir = File.basename(path)
42 @name = @dir.humanize
42 @name = @dir.humanize
43 @stylesheets = Dir.glob("#{path}/stylesheets/*.css").collect {|f| File.basename(f).gsub(/\.css$/, '')}
43 @stylesheets = Dir.glob("#{path}/stylesheets/*.css").collect {|f| File.basename(f).gsub(/\.css$/, '')}
44 end
44 end
45
45
46 # Directory name used as the theme id
46 # Directory name used as the theme id
47 def id; dir end
47 def id; dir end
48
48
49 def <=>(theme)
49 def <=>(theme)
50 name <=> theme.name
50 name <=> theme.name
51 end
51 end
52 end
52 end
53
53
54 private
54 private
55
55
56 def self.scan_themes
56 def self.scan_themes
57 dirs = Dir.glob("#{RAILS_ROOT}/public/themes/*").select do |f|
57 dirs = Dir.glob("#{RAILS_ROOT}/public/themes/*").select do |f|
58 # A theme should at least override application.css
58 # A theme should at least override application.css
59 File.directory?(f) && File.exist?("#{f}/stylesheets/application.css")
59 File.directory?(f) && File.exist?("#{f}/stylesheets/application.css")
60 end
60 end
61 dirs.collect {|dir| Theme.new(dir)}.sort
61 dirs.collect {|dir| Theme.new(dir)}.sort
62 end
62 end
63 end
63 end
64 end
64 end
65
65
66 module ApplicationHelper
66 module ApplicationHelper
67 def stylesheet_path(source)
67 def stylesheet_path(source)
68 @current_theme ||= Redmine::Themes.theme(Setting.ui_theme)
68 @current_theme ||= Redmine::Themes.theme(Setting.ui_theme)
69 super((@current_theme && @current_theme.stylesheets.include?(source)) ?
69 super((@current_theme && @current_theme.stylesheets.include?(source)) ?
70 "/themes/#{@current_theme.dir}/stylesheets/#{source}" : source)
70 "/themes/#{@current_theme.dir}/stylesheets/#{source}" : source)
71 end
71 end
72
73 def path_to_stylesheet(source)
74 stylesheet_path source
75 end
72 end
76 end
General Comments 0
You need to be logged in to leave comments. Login now