comparison plugins/redmine_embedded/lib/redmine_embedded.rb @ 1119:22d81bd0b62c redmine-2.2-integration

Deleted existing the embedded plugin and replaced it witgh redmine_embedded (same functionality, but upgraded to be compatible with Redmine 2.x).
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Tue, 08 Jan 2013 14:43:04 +0000
parents
children
comparison
equal deleted inserted replaced
1118:35686c1667de 1119:22d81bd0b62c
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 RedmineEmbedded
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_redmine_embedded['template'].to_s : t.first
36 end
37
38 def valid_extension?(path)
39 extensions = Setting.plugin_redmine_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
65
66 class << RedmineApp::Application;self;end.class_eval do
67 define_method :clear!, lambda {}
68 end
69