annotate .svn/pristine/73/731c118e47d43ceb764284116d22261ebd1e6947.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

Fix failure to interpret Javascript when autocompleting members for project
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 11 Sep 2014 10:24:38 +0100
parents dffacf8a6908
children
rev   line source
Chris@1517 1 # Redmine - project management software
Chris@1517 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1517 3 #
Chris@1517 4 # This program is free software; you can redistribute it and/or
Chris@1517 5 # modify it under the terms of the GNU General Public License
Chris@1517 6 # as published by the Free Software Foundation; either version 2
Chris@1517 7 # of the License, or (at your option) any later version.
Chris@1517 8 #
Chris@1517 9 # This program is distributed in the hope that it will be useful,
Chris@1517 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1517 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1517 12 # GNU General Public License for more details.
Chris@1517 13 #
Chris@1517 14 # You should have received a copy of the GNU General Public License
Chris@1517 15 # along with this program; if not, write to the Free Software
Chris@1517 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1517 17
Chris@1517 18 module Redmine
Chris@1517 19 module Themes
Chris@1517 20
Chris@1517 21 # Return an array of installed themes
Chris@1517 22 def self.themes
Chris@1517 23 @@installed_themes ||= scan_themes
Chris@1517 24 end
Chris@1517 25
Chris@1517 26 # Rescan themes directory
Chris@1517 27 def self.rescan
Chris@1517 28 @@installed_themes = scan_themes
Chris@1517 29 end
Chris@1517 30
Chris@1517 31 # Return theme for given id, or nil if it's not found
Chris@1517 32 def self.theme(id, options={})
Chris@1517 33 return nil if id.blank?
Chris@1517 34
Chris@1517 35 found = themes.find {|t| t.id == id}
Chris@1517 36 if found.nil? && options[:rescan] != false
Chris@1517 37 rescan
Chris@1517 38 found = theme(id, :rescan => false)
Chris@1517 39 end
Chris@1517 40 found
Chris@1517 41 end
Chris@1517 42
Chris@1517 43 # Class used to represent a theme
Chris@1517 44 class Theme
Chris@1517 45 attr_reader :path, :name, :dir
Chris@1517 46
Chris@1517 47 def initialize(path)
Chris@1517 48 @path = path
Chris@1517 49 @dir = File.basename(path)
Chris@1517 50 @name = @dir.humanize
Chris@1517 51 @stylesheets = nil
Chris@1517 52 @javascripts = nil
Chris@1517 53 end
Chris@1517 54
Chris@1517 55 # Directory name used as the theme id
Chris@1517 56 def id; dir end
Chris@1517 57
Chris@1517 58 def ==(theme)
Chris@1517 59 theme.is_a?(Theme) && theme.dir == dir
Chris@1517 60 end
Chris@1517 61
Chris@1517 62 def <=>(theme)
Chris@1517 63 name <=> theme.name
Chris@1517 64 end
Chris@1517 65
Chris@1517 66 def stylesheets
Chris@1517 67 @stylesheets ||= assets("stylesheets", "css")
Chris@1517 68 end
Chris@1517 69
Chris@1517 70 def images
Chris@1517 71 @images ||= assets("images")
Chris@1517 72 end
Chris@1517 73
Chris@1517 74 def javascripts
Chris@1517 75 @javascripts ||= assets("javascripts", "js")
Chris@1517 76 end
Chris@1517 77
Chris@1517 78 def favicons
Chris@1517 79 @favicons ||= assets("favicon")
Chris@1517 80 end
Chris@1517 81
Chris@1517 82 def favicon
Chris@1517 83 favicons.first
Chris@1517 84 end
Chris@1517 85
Chris@1517 86 def favicon?
Chris@1517 87 favicon.present?
Chris@1517 88 end
Chris@1517 89
Chris@1517 90 def stylesheet_path(source)
Chris@1517 91 "/themes/#{dir}/stylesheets/#{source}"
Chris@1517 92 end
Chris@1517 93
Chris@1517 94 def image_path(source)
Chris@1517 95 "/themes/#{dir}/images/#{source}"
Chris@1517 96 end
Chris@1517 97
Chris@1517 98 def javascript_path(source)
Chris@1517 99 "/themes/#{dir}/javascripts/#{source}"
Chris@1517 100 end
Chris@1517 101
Chris@1517 102 def favicon_path
Chris@1517 103 "/themes/#{dir}/favicon/#{favicon}"
Chris@1517 104 end
Chris@1517 105
Chris@1517 106 private
Chris@1517 107
Chris@1517 108 def assets(dir, ext=nil)
Chris@1517 109 if ext
Chris@1517 110 Dir.glob("#{path}/#{dir}/*.#{ext}").collect {|f| File.basename(f).gsub(/\.#{ext}$/, '')}
Chris@1517 111 else
Chris@1517 112 Dir.glob("#{path}/#{dir}/*").collect {|f| File.basename(f)}
Chris@1517 113 end
Chris@1517 114 end
Chris@1517 115 end
Chris@1517 116
Chris@1517 117 private
Chris@1517 118
Chris@1517 119 def self.scan_themes
Chris@1517 120 dirs = Dir.glob("#{Rails.public_path}/themes/*").select do |f|
Chris@1517 121 # A theme should at least override application.css
Chris@1517 122 File.directory?(f) && File.exist?("#{f}/stylesheets/application.css")
Chris@1517 123 end
Chris@1517 124 dirs.collect {|dir| Theme.new(dir)}.sort
Chris@1517 125 end
Chris@1517 126 end
Chris@1517 127 end
Chris@1517 128
Chris@1517 129 module ApplicationHelper
Chris@1517 130 def current_theme
Chris@1517 131 unless instance_variable_defined?(:@current_theme)
Chris@1517 132 @current_theme = Redmine::Themes.theme(Setting.ui_theme)
Chris@1517 133 end
Chris@1517 134 @current_theme
Chris@1517 135 end
Chris@1517 136
Chris@1517 137 # Returns the header tags for the current theme
Chris@1517 138 def heads_for_theme
Chris@1517 139 if current_theme && current_theme.javascripts.include?('theme')
Chris@1517 140 javascript_include_tag current_theme.javascript_path('theme')
Chris@1517 141 end
Chris@1517 142 end
Chris@1517 143 end