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