Chris@154: # Redmine - project management software Chris@154: # Copyright (C) 2008 Jean-Philippe Lang Chris@154: # Chris@154: # This program is free software; you can redistribute it and/or Chris@154: # modify it under the terms of the GNU General Public License Chris@154: # as published by the Free Software Foundation; either version 2 Chris@154: # of the License, or (at your option) any later version. Chris@154: # Chris@154: # This program is distributed in the hope that it will be useful, Chris@154: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@154: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@154: # GNU General Public License for more details. Chris@154: # Chris@154: # You should have received a copy of the GNU General Public License Chris@154: # along with this program; if not, write to the Free Software Chris@154: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@154: Chris@154: module Redmine Chris@154: module Plugins Chris@154: module Embedded Chris@154: class << self Chris@154: Chris@154: # Returns an Array of available templates Chris@154: def available_templates Chris@154: assets_by_template.keys.sort Chris@154: end Chris@154: Chris@154: # Returns the assets for a given template Chris@154: def assets(template) Chris@154: assets_by_template.has_key?(template) ? assets_by_template[template] : [] Chris@154: end Chris@154: Chris@154: def detect_template_from_path(path) Chris@154: t = path.to_s.split(%r{[/\\]}) & available_templates Chris@154: t.empty? ? Setting.plugin_embedded['template'].to_s : t.first Chris@154: end Chris@154: Chris@154: def valid_extension?(path) Chris@154: extensions = Setting.plugin_embedded['extensions'].to_s.split.each(&:downcase) Chris@154: extensions.include?(File.extname(path).downcase[1..-1]) Chris@154: end Chris@154: Chris@154: private Chris@154: Chris@154: # A Hash of available assets by template Chris@154: def assets_by_template Chris@154: @@assets_by_template ||= scan_assets Chris@154: end Chris@154: Chris@154: # Scans assets directory for templates Chris@154: # and returns a Hash of available assets by template Chris@154: def scan_assets Chris@154: a = Hash.new {|h,k| h[k] = [] } Chris@154: Dir.glob(File.join(File.dirname(__FILE__), '../assets/*/*.{css,js}')).each do |asset| Chris@154: asset = File.basename(asset) Chris@154: template = asset.gsub(%r{\.(js|css)$}, '') Chris@154: a[template] << asset Chris@154: end Chris@154: a Chris@154: end Chris@154: end Chris@154: end Chris@154: end Chris@154: end