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