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