Mercurial > hg > soundsoftware-site
diff lib/redmine/.svn/text-base/themes.rb.svn-base @ 117:af80e5618e9b redmine-1.1
* Update to Redmine 1.1-stable branch (Redmine SVN rev 4707)
author | Chris Cannam |
---|---|
date | Thu, 13 Jan 2011 12:53:21 +0000 |
parents | 513646585e45 |
children |
line wrap: on
line diff
--- a/lib/redmine/.svn/text-base/themes.rb.svn-base Fri Nov 19 14:05:24 2010 +0000 +++ b/lib/redmine/.svn/text-base/themes.rb.svn-base Thu Jan 13 12:53:21 2011 +0000 @@ -29,30 +29,65 @@ end # Return theme for given id, or nil if it's not found - def self.theme(id) - themes.find {|t| t.id == id} + def self.theme(id, options={}) + return nil if id.blank? + + found = themes.find {|t| t.id == id} + if found.nil? && options[:rescan] != false + rescan + found = theme(id, :rescan => false) + end + found end # Class used to represent a theme class Theme - attr_reader :name, :dir, :stylesheets + attr_reader :path, :name, :dir def initialize(path) + @path = path @dir = File.basename(path) @name = @dir.humanize - @stylesheets = Dir.glob("#{path}/stylesheets/*.css").collect {|f| File.basename(f).gsub(/\.css$/, '')} + @stylesheets = nil + @javascripts = nil end # Directory name used as the theme id def id; dir end - + + def ==(theme) + theme.is_a?(Theme) && theme.dir == dir + end + def <=>(theme) name <=> theme.name end + + def stylesheets + @stylesheets ||= assets("stylesheets", "css") + end + + def javascripts + @javascripts ||= assets("javascripts", "js") + end + + def stylesheet_path(source) + "/themes/#{dir}/stylesheets/#{source}" + end + + def javascript_path(source) + "/themes/#{dir}/javascripts/#{source}" + end + + private + + def assets(dir, ext) + Dir.glob("#{path}/#{dir}/*.#{ext}").collect {|f| File.basename(f).gsub(/\.#{ext}$/, '')} + end end private - + def self.scan_themes dirs = Dir.glob("#{Rails.public_path}/themes/*").select do |f| # A theme should at least override application.css @@ -64,13 +99,29 @@ end module ApplicationHelper + def current_theme + unless instance_variable_defined?(:@current_theme) + @current_theme = Redmine::Themes.theme(Setting.ui_theme) + end + @current_theme + end + def stylesheet_path(source) - @current_theme ||= Redmine::Themes.theme(Setting.ui_theme) - super((@current_theme && @current_theme.stylesheets.include?(source)) ? - "/themes/#{@current_theme.dir}/stylesheets/#{source}" : source) + if current_theme && current_theme.stylesheets.include?(source) + super current_theme.stylesheet_path(source) + else + super + end end def path_to_stylesheet(source) stylesheet_path source end + + # Returns the header tags for the current theme + def heads_for_theme + if current_theme && current_theme.javascripts.include?('theme') + javascript_include_tag current_theme.javascript_path('theme') + end + end end