summaryrefslogtreecommitdiffstats
path: root/lib/redmine
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2007-05-08 15:49:20 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2007-05-08 15:49:20 +0000
commit8614c00c8a3e34e6b081ba2dc1be7985acc4bd4b (patch)
tree983e866e4ec21a84783a9063059957728f4d0d43 /lib/redmine
parentdf0a49ff14474dd2230a823f57e95aa9d3b1cd71 (diff)
downloadredmine-8614c00c8a3e34e6b081ba2dc1be7985acc4bd4b.tar.gz
redmine-8614c00c8a3e34e6b081ba2dc1be7985acc4bd4b.zip
Text files can now be viewed online when browsing the repository.
git-svn-id: http://redmine.rubyforge.org/svn/trunk@521 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/redmine')
-rw-r--r--lib/redmine/mime_type.rb58
1 files changed, 58 insertions, 0 deletions
diff --git a/lib/redmine/mime_type.rb b/lib/redmine/mime_type.rb
new file mode 100644
index 000000000..1177372a7
--- /dev/null
+++ b/lib/redmine/mime_type.rb
@@ -0,0 +1,58 @@
+# redMine - project management software
+# Copyright (C) 2006-2007 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+module Redmine
+ module MimeType
+
+ MIME_TYPES = {
+ 'text/plain' => 'txt',
+ 'text/css' => 'css',
+ 'text/html' => 'html,htm,xhtml',
+ 'text/x-javascript' => 'js',
+ 'text/x-html-template' => 'rhtml',
+ 'text/x-ruby' => 'rb,ruby',
+ 'image/gif' => 'gif',
+ 'image/jpeg' => 'jpg,jpeg,jpe',
+ 'image/png' => 'png',
+ 'image/tiff' => 'tiff,tif'
+ }.freeze
+
+ EXTENSIONS = MIME_TYPES.inject({}) do |map, (type, exts)|
+ exts.split(',').each {|ext| map[ext] = type}
+ map
+ end
+
+ # returns mime type for name or nil if unknown
+ def self.of(name)
+ return nil unless name
+ m = name.to_s.match(/\.([^\.]+)$/)
+ EXTENSIONS[m[1]] if m
+ end
+
+ def self.main_mimetype_of(name)
+ mimetype = of(name)
+ mimetype.split('/').first if mimetype
+ end
+
+ # return true if mime-type for name is type/*
+ # otherwise false
+ def self.is_type?(type, name)
+ main_mimetype = main_mimetype_of(name)
+ type.to_s == main_mimetype
+ end
+ end
+end