1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
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
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 # Return an array of installed themes
23 @@installed_themes ||= scan_themes
26 # Rescan themes directory
28 @@installed_themes = scan_themes
31 # Return theme for given id, or nil if it's not found
33 themes.find {|t| t.id == id}
36 # Class used to represent a theme
38 attr_reader :name, :dir, :stylesheets
41 @dir = File.basename(path)
43 @stylesheets = Dir.glob("#{path}/stylesheets/*.css").collect {|f| File.basename(f).gsub(/\.css$/, '')}
46 # Directory name used as the theme id
57 dirs = Dir.glob("#{RAILS_ROOT}/public/themes/*").select do |f|
58 # A theme should at least override application.css
59 File.directory?(f) && File.exist?("#{f}/stylesheets/application.css")
61 dirs.collect {|dir| Theme.new(dir)}.sort
66 module ApplicationHelper
67 def stylesheet_path(source)
68 @current_theme ||= Redmine::Themes.theme(Setting.ui_theme)
69 super((@current_theme && @current_theme.stylesheets.include?(source)) ?
70 "/themes/#{@current_theme.dir}/stylesheets/#{source}" : source)
73 def path_to_stylesheet(source)
74 stylesheet_path source