luis@1119
|
1 # Redmine - project management software
|
luis@1119
|
2 # Copyright (C) 2008 Jean-Philippe Lang
|
luis@1119
|
3 #
|
luis@1119
|
4 # This program is free software; you can redistribute it and/or
|
luis@1119
|
5 # modify it under the terms of the GNU General Public License
|
luis@1119
|
6 # as published by the Free Software Foundation; either version 2
|
luis@1119
|
7 # of the License, or (at your option) any later version.
|
luis@1119
|
8 #
|
luis@1119
|
9 # This program is distributed in the hope that it will be useful,
|
luis@1119
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
luis@1119
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
luis@1119
|
12 # GNU General Public License for more details.
|
luis@1119
|
13 #
|
luis@1119
|
14 # You should have received a copy of the GNU General Public License
|
luis@1119
|
15 # along with this program; if not, write to the Free Software
|
luis@1119
|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
luis@1119
|
17
|
luis@1119
|
18 module Redmine
|
luis@1119
|
19 module Plugins
|
luis@1119
|
20 module RedmineEmbedded
|
luis@1119
|
21 class << self
|
luis@1119
|
22
|
luis@1119
|
23 # Returns an Array of available templates
|
luis@1119
|
24 def available_templates
|
luis@1119
|
25 assets_by_template.keys.sort
|
luis@1119
|
26 end
|
luis@1119
|
27
|
luis@1119
|
28 # Returns the assets for a given template
|
luis@1119
|
29 def assets(template)
|
luis@1119
|
30 assets_by_template.has_key?(template) ? assets_by_template[template] : []
|
luis@1119
|
31 end
|
luis@1119
|
32
|
luis@1119
|
33 def detect_template_from_path(path)
|
luis@1119
|
34 t = path.to_s.split(%r{[/\\]}) & available_templates
|
luis@1119
|
35 t.empty? ? Setting.plugin_redmine_embedded['template'].to_s : t.first
|
luis@1119
|
36 end
|
luis@1119
|
37
|
luis@1119
|
38 def valid_extension?(path)
|
luis@1119
|
39 extensions = Setting.plugin_redmine_embedded['extensions'].to_s.split.each(&:downcase)
|
luis@1119
|
40 extensions.include?(File.extname(path).downcase[1..-1])
|
luis@1119
|
41 end
|
luis@1119
|
42
|
luis@1119
|
43 private
|
luis@1119
|
44
|
luis@1119
|
45 # A Hash of available assets by template
|
luis@1119
|
46 def assets_by_template
|
luis@1119
|
47 @@assets_by_template ||= scan_assets
|
luis@1119
|
48 end
|
luis@1119
|
49
|
luis@1119
|
50 # Scans assets directory for templates
|
luis@1119
|
51 # and returns a Hash of available assets by template
|
luis@1119
|
52 def scan_assets
|
luis@1119
|
53 a = Hash.new {|h,k| h[k] = [] }
|
luis@1119
|
54 Dir.glob(File.join(File.dirname(__FILE__), '../assets/*/*.{css,js}')).each do |asset|
|
luis@1119
|
55 asset = File.basename(asset)
|
luis@1119
|
56 template = asset.gsub(%r{\.(js|css)$}, '')
|
luis@1119
|
57 a[template] << asset
|
luis@1119
|
58 end
|
luis@1119
|
59 a
|
luis@1119
|
60 end
|
luis@1119
|
61 end
|
luis@1119
|
62 end
|
luis@1119
|
63 end
|
luis@1119
|
64 end
|
luis@1119
|
65
|
luis@1119
|
66 class << RedmineApp::Application;self;end.class_eval do
|
luis@1119
|
67 define_method :clear!, lambda {}
|
luis@1119
|
68 end
|
luis@1119
|
69
|