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