@@ -1,104 +1,105 | |||
|
1 | 1 | source 'https://rubygems.org' |
|
2 | 2 | |
|
3 | 3 | gem "rails", "3.2.16" |
|
4 | 4 | gem "jquery-rails", "~> 2.0.2" |
|
5 | 5 | gem "coderay", "~> 1.1.0" |
|
6 | 6 | gem "fastercsv", "~> 1.5.0", :platforms => [:mri_18, :mingw_18, :jruby] |
|
7 | 7 | gem "builder", "3.0.0" |
|
8 | gem "mime-types" | |
|
8 | 9 | |
|
9 | 10 | # Optional gem for LDAP authentication |
|
10 | 11 | group :ldap do |
|
11 | 12 | gem "net-ldap", "~> 0.3.1" |
|
12 | 13 | end |
|
13 | 14 | |
|
14 | 15 | # Optional gem for OpenID authentication |
|
15 | 16 | group :openid do |
|
16 | 17 | gem "ruby-openid", "~> 2.3.0", :require => "openid" |
|
17 | 18 | gem "rack-openid" |
|
18 | 19 | end |
|
19 | 20 | |
|
20 | 21 | platforms :mri, :mingw do |
|
21 | 22 | # Optional gem for exporting the gantt to a PNG file, not supported with jruby |
|
22 | 23 | group :rmagick do |
|
23 | 24 | # RMagick 2 supports ruby 1.9 |
|
24 | 25 | # RMagick 1 would be fine for ruby 1.8 but Bundler does not support |
|
25 | 26 | # different requirements for the same gem on different platforms |
|
26 | 27 | gem "rmagick", ">= 2.0.0" |
|
27 | 28 | end |
|
28 | 29 | |
|
29 | 30 | # Optional Markdown support, not for JRuby |
|
30 | 31 | group :markdown do |
|
31 | 32 | # TODO: upgrade to redcarpet 3.x when ruby1.8 support is dropped |
|
32 | 33 | gem "redcarpet", "~> 2.3.0" |
|
33 | 34 | end |
|
34 | 35 | end |
|
35 | 36 | |
|
36 | 37 | platforms :jruby do |
|
37 | 38 | # jruby-openssl is bundled with JRuby 1.7.0 |
|
38 | 39 | gem "jruby-openssl" if Object.const_defined?(:JRUBY_VERSION) && JRUBY_VERSION < '1.7.0' |
|
39 | 40 | gem "activerecord-jdbc-adapter", "~> 1.3.2" |
|
40 | 41 | end |
|
41 | 42 | |
|
42 | 43 | # Include database gems for the adapters found in the database |
|
43 | 44 | # configuration file |
|
44 | 45 | require 'erb' |
|
45 | 46 | require 'yaml' |
|
46 | 47 | database_file = File.join(File.dirname(__FILE__), "config/database.yml") |
|
47 | 48 | if File.exist?(database_file) |
|
48 | 49 | database_config = YAML::load(ERB.new(IO.read(database_file)).result) |
|
49 | 50 | adapters = database_config.values.map {|c| c['adapter']}.compact.uniq |
|
50 | 51 | if adapters.any? |
|
51 | 52 | adapters.each do |adapter| |
|
52 | 53 | case adapter |
|
53 | 54 | when 'mysql2' |
|
54 | 55 | gem "mysql2", "~> 0.3.11", :platforms => [:mri, :mingw] |
|
55 | 56 | gem "activerecord-jdbcmysql-adapter", :platforms => :jruby |
|
56 | 57 | when 'mysql' |
|
57 | 58 | gem "mysql", "~> 2.8.1", :platforms => [:mri, :mingw] |
|
58 | 59 | gem "activerecord-jdbcmysql-adapter", :platforms => :jruby |
|
59 | 60 | when /postgresql/ |
|
60 | 61 | gem "pg", ">= 0.11.0", :platforms => [:mri, :mingw] |
|
61 | 62 | gem "activerecord-jdbcpostgresql-adapter", :platforms => :jruby |
|
62 | 63 | when /sqlite3/ |
|
63 | 64 | gem "sqlite3", :platforms => [:mri, :mingw] |
|
64 | 65 | gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby |
|
65 | 66 | when /sqlserver/ |
|
66 | 67 | gem "tiny_tds", "~> 0.5.1", :platforms => [:mri, :mingw] |
|
67 | 68 | gem "activerecord-sqlserver-adapter", :platforms => [:mri, :mingw] |
|
68 | 69 | else |
|
69 | 70 | warn("Unknown database adapter `#{adapter}` found in config/database.yml, use Gemfile.local to load your own database gems") |
|
70 | 71 | end |
|
71 | 72 | end |
|
72 | 73 | else |
|
73 | 74 | warn("No adapter found in config/database.yml, please configure it first") |
|
74 | 75 | end |
|
75 | 76 | else |
|
76 | 77 | warn("Please configure your config/database.yml first") |
|
77 | 78 | end |
|
78 | 79 | |
|
79 | 80 | group :development do |
|
80 | 81 | gem "rdoc", ">= 2.4.2" |
|
81 | 82 | gem "yard" |
|
82 | 83 | end |
|
83 | 84 | |
|
84 | 85 | group :test do |
|
85 | 86 | gem "shoulda", "~> 3.3.2" |
|
86 | 87 | gem "mocha", ">= 0.14", :require => 'mocha/api' |
|
87 | 88 | if RUBY_VERSION >= '1.9.3' |
|
88 | 89 | gem "capybara", "~> 2.1.0" |
|
89 | 90 | gem "selenium-webdriver" |
|
90 | 91 | end |
|
91 | 92 | end |
|
92 | 93 | |
|
93 | 94 | local_gemfile = File.join(File.dirname(__FILE__), "Gemfile.local") |
|
94 | 95 | if File.exists?(local_gemfile) |
|
95 | 96 | puts "Loading Gemfile.local ..." if $DEBUG # `ruby -d` or `bundle -v` |
|
96 | 97 | instance_eval File.read(local_gemfile) |
|
97 | 98 | end |
|
98 | 99 | |
|
99 | 100 | # Load plugins' Gemfiles |
|
100 | 101 | Dir.glob File.expand_path("../plugins/*/Gemfile", __FILE__) do |file| |
|
101 | 102 | puts "Loading #{file} ..." if $DEBUG # `ruby -d` or `bundle -v` |
|
102 | 103 | #TODO: switch to "eval_gemfile file" when bundler >= 1.2.0 will be required (rails 4) |
|
103 | 104 | instance_eval File.read(file), file |
|
104 | 105 | end |
@@ -1,98 +1,86 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2013 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | require 'mime/types' | |
|
19 | ||
|
18 | 20 | module Redmine |
|
19 | 21 | module MimeType |
|
20 | 22 | |
|
21 | 23 | MIME_TYPES = { |
|
22 | 24 | 'text/plain' => 'txt,tpl,properties,patch,diff,ini,readme,install,upgrade', |
|
23 | 25 | 'text/css' => 'css', |
|
24 | 26 | 'text/html' => 'html,htm,xhtml', |
|
25 | 27 | 'text/jsp' => 'jsp', |
|
26 | 28 | 'text/x-c' => 'c,cpp,cc,h,hh', |
|
27 | 29 | 'text/x-csharp' => 'cs', |
|
28 | 30 | 'text/x-java' => 'java', |
|
29 | 31 | 'text/x-html-template' => 'rhtml', |
|
30 | 32 | 'text/x-perl' => 'pl,pm', |
|
31 | 33 | 'text/x-php' => 'php,php3,php4,php5', |
|
32 | 34 | 'text/x-python' => 'py', |
|
33 | 35 | 'text/x-ruby' => 'rb,rbw,ruby,rake,erb', |
|
34 | 36 | 'text/x-csh' => 'csh', |
|
35 | 37 | 'text/x-sh' => 'sh', |
|
36 | 38 | 'text/xml' => 'xml,xsd,mxml', |
|
37 | 39 | 'text/yaml' => 'yml,yaml', |
|
38 | 40 | 'text/csv' => 'csv', |
|
39 | 41 | 'text/x-po' => 'po', |
|
40 | 42 | 'image/gif' => 'gif', |
|
41 | 43 | 'image/jpeg' => 'jpg,jpeg,jpe', |
|
42 | 44 | 'image/png' => 'png', |
|
43 | 45 | 'image/tiff' => 'tiff,tif', |
|
44 | 46 | 'image/x-ms-bmp' => 'bmp', |
|
45 | 'image/x-xpixmap' => 'xpm', | |
|
46 | 'image/svg+xml'=> 'svg', | |
|
47 | 47 | 'application/javascript' => 'js', |
|
48 | 48 | 'application/pdf' => 'pdf', |
|
49 | 'application/rtf' => 'rtf', | |
|
50 | 'application/msword' => 'doc', | |
|
51 | 'application/vnd.ms-excel' => 'xls', | |
|
52 | 'application/vnd.ms-powerpoint' => 'ppt,pps', | |
|
53 | 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx', | |
|
54 | 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx', | |
|
55 | 'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'pptx', | |
|
56 | 'application/vnd.openxmlformats-officedocument.presentationml.slideshow' => 'ppsx', | |
|
57 | 'application/vnd.oasis.opendocument.spreadsheet' => 'ods', | |
|
58 | 'application/vnd.oasis.opendocument.text' => 'odt', | |
|
59 | 'application/vnd.oasis.opendocument.presentation' => 'odp', | |
|
60 | 'application/x-7z-compressed' => '7z', | |
|
61 | 'application/x-rar-compressed' => 'rar', | |
|
62 | 'application/x-tar' => 'tar', | |
|
63 | 'application/zip' => 'zip', | |
|
64 | 'application/x-gzip' => 'gz', | |
|
65 | 49 | }.freeze |
|
66 | 50 | |
|
67 | 51 | EXTENSIONS = MIME_TYPES.inject({}) do |map, (type, exts)| |
|
68 | 52 | exts.split(',').each {|ext| map[ext.strip] = type} |
|
69 | 53 | map |
|
70 | 54 | end |
|
71 | 55 | |
|
72 | 56 | # returns mime type for name or nil if unknown |
|
73 | 57 | def self.of(name) |
|
74 | 58 | return nil unless name |
|
75 | 59 | m = name.to_s.match(/(^|\.)([^\.]+)$/) |
|
76 |
|
|
|
60 | ext = m[2].downcase | |
|
61 | type = nil | |
|
62 | type = EXTENSIONS[ext] if m | |
|
63 | type ||= MIME::Types.find {|type| type.extensions.include?(ext)}.to_s.presence | |
|
64 | type | |
|
77 | 65 | end |
|
78 | 66 | |
|
79 | 67 | # Returns the css class associated to |
|
80 | 68 | # the mime type of name |
|
81 | 69 | def self.css_class_of(name) |
|
82 | 70 | mime = of(name) |
|
83 | 71 | mime && mime.gsub('/', '-') |
|
84 | 72 | end |
|
85 | 73 | |
|
86 | 74 | def self.main_mimetype_of(name) |
|
87 | 75 | mimetype = of(name) |
|
88 | 76 | mimetype.split('/').first if mimetype |
|
89 | 77 | end |
|
90 | 78 | |
|
91 | 79 | # return true if mime-type for name is type/* |
|
92 | 80 | # otherwise false |
|
93 | 81 | def self.is_type?(type, name) |
|
94 | 82 | main_mimetype = main_mimetype_of(name) |
|
95 | 83 | type.to_s == main_mimetype |
|
96 | 84 | end |
|
97 | 85 | end |
|
98 | 86 | end |
@@ -1,61 +1,66 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2013 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class Redmine::MimeTypeTest < ActiveSupport::TestCase |
|
21 | 21 | |
|
22 | 22 | def test_of |
|
23 | 23 | to_test = {'test.unk' => nil, |
|
24 | 24 | 'test.txt' => 'text/plain', |
|
25 | 25 | 'test.c' => 'text/x-c', |
|
26 | 26 | } |
|
27 | 27 | to_test.each do |name, expected| |
|
28 | 28 | assert_equal expected, Redmine::MimeType.of(name) |
|
29 | 29 | end |
|
30 | 30 | end |
|
31 | 31 | |
|
32 | 32 | def test_css_class_of |
|
33 | 33 | to_test = {'test.unk' => nil, |
|
34 | 34 | 'test.txt' => 'text-plain', |
|
35 | 35 | 'test.c' => 'text-x-c', |
|
36 | 36 | } |
|
37 | 37 | to_test.each do |name, expected| |
|
38 | 38 | assert_equal expected, Redmine::MimeType.css_class_of(name) |
|
39 | 39 | end |
|
40 | 40 | end |
|
41 | 41 | |
|
42 | 42 | def test_main_mimetype_of |
|
43 | 43 | to_test = {'test.unk' => nil, |
|
44 | 44 | 'test.txt' => 'text', |
|
45 | 45 | 'test.c' => 'text', |
|
46 | 46 | } |
|
47 | 47 | to_test.each do |name, expected| |
|
48 | 48 | assert_equal expected, Redmine::MimeType.main_mimetype_of(name) |
|
49 | 49 | end |
|
50 | 50 | end |
|
51 | 51 | |
|
52 | 52 | def test_is_type |
|
53 | 53 | to_test = {['text', 'test.unk'] => false, |
|
54 | 54 | ['text', 'test.txt'] => true, |
|
55 | 55 | ['text', 'test.c'] => true, |
|
56 | 56 | } |
|
57 | 57 | to_test.each do |args, expected| |
|
58 | 58 | assert_equal expected, Redmine::MimeType.is_type?(*args) |
|
59 | 59 | end |
|
60 | 60 | end |
|
61 | ||
|
62 | def test_should_default_to_mime_type_gem | |
|
63 | assert !Redmine::MimeType::EXTENSIONS.keys.include?("zip") | |
|
64 | assert_equal "application/zip", Redmine::MimeType.of("file.zip") | |
|
65 | end | |
|
61 | 66 | end |
General Comments 0
You need to be logged in to leave comments.
Login now