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