]> source.dussan.org Git - redmine.git/commitdiff
Adds mime type specific css classes to the SCM browser.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 19 Apr 2009 08:25:25 +0000 (08:25 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 19 Apr 2009 08:25:25 +0000 (08:25 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2672 e93f8b46-1217-0410-a6f0-8f06a7374b81

17 files changed:
app/views/repositories/_dir_list_content.rhtml
lib/redmine/mime_type.rb
public/images/file.png [deleted file]
public/images/files/c.png [new file with mode: 0644]
public/images/files/csharp.png [new file with mode: 0644]
public/images/files/default.png [new file with mode: 0644]
public/images/files/image.png [new file with mode: 0644]
public/images/files/pdf.png [new file with mode: 0644]
public/images/files/php.png [new file with mode: 0644]
public/images/files/ruby.png [new file with mode: 0644]
public/images/files/text.png [new file with mode: 0644]
public/images/files/xml.png [new file with mode: 0644]
public/images/files/zip.png [new file with mode: 0644]
public/images/pdf.png [deleted file]
public/stylesheets/application.css
test/functional/repositories_subversion_controller_test.rb
test/unit/lib/redmine/mime_type_test.rb [new file with mode: 0644]

index 799318134e484d707c983e6670bc9976118a914d..bcffed4a55110c6cb609db31350c9357133f43a4 100644 (file)
@@ -13,7 +13,7 @@
 <% end %>
 <%=  link_to h(entry.name),
           {:action => (entry.is_dir? ? 'browse' : 'changes'), :id => @project, :path => to_path_param(entry.path), :rev => @rev},
-          :class => (entry.is_dir? ? 'icon icon-folder' : 'icon icon-file')%>
+          :class => (entry.is_dir? ? 'icon icon-folder' : "icon icon-file #{Redmine::MimeType.css_class_of(entry.name)}")%>
 </td>
 <td class="size"><%= (entry.size ? number_to_human_size(entry.size) : "?") unless entry.is_dir? %></td>
 <% changeset = @project.repository.changesets.find_by_revision(entry.lastrev.identifier) if entry.lastrev && entry.lastrev.identifier %>
index dfdfff407516721ce3581c3413a7ad5cb816474e..f0e55cc92cde4eac360b79035e6d8b46c7dfbfbe 100644 (file)
@@ -24,6 +24,7 @@ module Redmine
       'text/html' => 'html,htm,xhtml',
       'text/jsp' => 'jsp',
       'text/x-c' => 'c,cpp,cc,h,hh',
+      'text/x-csharp' => 'cs',
       'text/x-java' => 'java',
       'text/x-javascript' => 'js',
       'text/x-html-template' => 'rhtml',
@@ -41,6 +42,9 @@ module Redmine
       'image/tiff' => 'tiff,tif',
       'image/x-ms-bmp' => 'bmp',
       'image/x-xpixmap' => 'xpm',
+      'application/pdf' => 'pdf',
+      'application/zip' => 'zip',
+      'application/x-gzip' => 'gz',
     }.freeze
     
     EXTENSIONS = MIME_TYPES.inject({}) do |map, (type, exts)|
@@ -55,6 +59,13 @@ module Redmine
       EXTENSIONS[m[2].downcase] if m
     end
     
+    # Returns the css class associated to
+    # the mime type of name
+    def self.css_class_of(name)
+      mime = of(name)
+      mime && mime.gsub('/', '-')
+    end
+    
     def self.main_mimetype_of(name)
       mimetype = of(name)
       mimetype.split('/').first if mimetype
diff --git a/public/images/file.png b/public/images/file.png
deleted file mode 100644 (file)
index f387dd3..0000000
Binary files a/public/images/file.png and /dev/null differ
diff --git a/public/images/files/c.png b/public/images/files/c.png
new file mode 100644 (file)
index 0000000..34a05cc
Binary files /dev/null and b/public/images/files/c.png differ
diff --git a/public/images/files/csharp.png b/public/images/files/csharp.png
new file mode 100644 (file)
index 0000000..ffb8fc9
Binary files /dev/null and b/public/images/files/csharp.png differ
diff --git a/public/images/files/default.png b/public/images/files/default.png
new file mode 100644 (file)
index 0000000..8b8b1ca
Binary files /dev/null and b/public/images/files/default.png differ
diff --git a/public/images/files/image.png b/public/images/files/image.png
new file mode 100644 (file)
index 0000000..134b669
Binary files /dev/null and b/public/images/files/image.png differ
diff --git a/public/images/files/pdf.png b/public/images/files/pdf.png
new file mode 100644 (file)
index 0000000..8f8095e
Binary files /dev/null and b/public/images/files/pdf.png differ
diff --git a/public/images/files/php.png b/public/images/files/php.png
new file mode 100644 (file)
index 0000000..7868a25
Binary files /dev/null and b/public/images/files/php.png differ
diff --git a/public/images/files/ruby.png b/public/images/files/ruby.png
new file mode 100644 (file)
index 0000000..f59b7c4
Binary files /dev/null and b/public/images/files/ruby.png differ
diff --git a/public/images/files/text.png b/public/images/files/text.png
new file mode 100644 (file)
index 0000000..813f712
Binary files /dev/null and b/public/images/files/text.png differ
diff --git a/public/images/files/xml.png b/public/images/files/xml.png
new file mode 100644 (file)
index 0000000..0c76bd1
Binary files /dev/null and b/public/images/files/xml.png differ
diff --git a/public/images/files/zip.png b/public/images/files/zip.png
new file mode 100644 (file)
index 0000000..8606ff0
Binary files /dev/null and b/public/images/files/zip.png differ
diff --git a/public/images/pdf.png b/public/images/pdf.png
deleted file mode 100644 (file)
index 68c9bad..0000000
Binary files a/public/images/pdf.png and /dev/null differ
index a8d8736fd246c4e51b75dcd02d176bd653c19d6d..f4bd102180932d8c3dd4d84e0767acc0660e842b 100644 (file)
@@ -665,7 +665,6 @@ vertical-align: middle;
 .icon-move { background-image: url(../images/move.png); }
 .icon-save { background-image: url(../images/save.png); }
 .icon-cancel { background-image: url(../images/cancel.png); }
-.icon-file { background-image: url(../images/file.png); }
 .icon-folder { background-image: url(../images/folder.png); }
 .open .icon-folder { background-image: url(../images/folder_open.png); }
 .icon-package { background-image: url(../images/package.png); }
@@ -692,6 +691,21 @@ vertical-align: middle;
 .icon-report  { background-image: url(../images/report.png); }
 .icon-comment  { background-image: url(../images/comment.png); }
 
+.icon-file { background-image: url(../images/files/default.png); }
+.icon-file.text-plain { background-image: url(../images/files/text.png); }
+.icon-file.text-x-c { background-image: url(../images/files/c.png); }
+.icon-file.text-x-csharp { background-image: url(../images/files/csharp.png); }
+.icon-file.text-x-php { background-image: url(../images/files/php.png); }
+.icon-file.text-x-ruby { background-image: url(../images/files/ruby.png); }
+.icon-file.text-xml { background-image: url(../images/files/xml.png); }
+.icon-file.image-gif { background-image: url(../images/files/image.png); }
+.icon-file.image-jpeg { background-image: url(../images/files/image.png); }
+.icon-file.image-png { background-image: url(../images/files/image.png); }
+.icon-file.image-tiff { background-image: url(../images/files/image.png); }
+.icon-file.application-pdf { background-image: url(../images/files/pdf.png); }
+.icon-file.application-zip { background-image: url(../images/files/zip.png); }
+.icon-file.application-x-gzip { background-image: url(../images/files/zip.png); }
+
 .icon22-projects { background-image: url(../images/22x22/projects.png); }
 .icon22-users { background-image: url(../images/22x22/users.png); }
 .icon22-tracker { background-image: url(../images/22x22/tracker.png); }
index c2bb40367785eb8a59b81d4aec97d35903d406fa..aef8c2ef2ece6883f82c1cb8122478ed8bc91cb6 100644 (file)
@@ -64,6 +64,7 @@ class RepositoriesSubversionControllerTest < Test::Unit::TestCase
       entry = assigns(:entries).detect {|e| e.name == 'helloworld.c'}
       assert_equal 'file', entry.kind
       assert_equal 'subversion_test/helloworld.c', entry.path
+      assert_tag :a, :content => 'helloworld.c', :attributes => { :class => /text\-x\-c/ }
     end
 
     def test_browse_at_given_revision
diff --git a/test/unit/lib/redmine/mime_type_test.rb b/test/unit/lib/redmine/mime_type_test.rb
new file mode 100644 (file)
index 0000000..79d0869
--- /dev/null
@@ -0,0 +1,61 @@
+# Redmine - project management software
+# Copyright (C) 2006-2009  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.
+
+require File.dirname(__FILE__) + '/../../../test_helper'
+
+class Redmine::MimeTypeTest < Test::Unit::TestCase
+  
+  def test_of
+    to_test = {'test.unk' => nil,
+               'test.txt' => 'text/plain',
+               'test.c' => 'text/x-c',
+               }
+    to_test.each do |name, expected|
+      assert_equal expected, Redmine::MimeType.of(name)
+    end
+  end
+  
+  def test_css_class_of
+    to_test = {'test.unk' => nil,
+               'test.txt' => 'text-plain',
+               'test.c' => 'text-x-c',
+               }
+    to_test.each do |name, expected|
+      assert_equal expected, Redmine::MimeType.css_class_of(name)
+    end
+  end
+  
+  def test_main_mimetype_of
+    to_test = {'test.unk' => nil,
+               'test.txt' => 'text',
+               'test.c' => 'text',
+               }
+    to_test.each do |name, expected|
+      assert_equal expected, Redmine::MimeType.main_mimetype_of(name)
+    end
+  end
+  
+  def test_is_type
+    to_test = {['text', 'test.unk'] => false,
+               ['text', 'test.txt'] => true,
+               ['text', 'test.c'] => true,
+               }
+    to_test.each do |args, expected|
+      assert_equal expected, Redmine::MimeType.is_type?(*args)
+    end
+  end
+end