[issue #274] Added some MIME types. Changed MIME ordering.

This commit is contained in:
George Vinogradov 2012-03-07 17:36:39 +04:00
parent d6d8410b0f
commit 464de82c68
3 changed files with 24 additions and 4 deletions

View File

@ -36,7 +36,7 @@
:javascript :javascript
$(function() { $(function() {
var editor = CodeMirror.fromTextArea(document.getElementById('code'), {lineNumbers: true, mode: '#{@blob.mime_type}', theme: 'eclipse'}); var editor = CodeMirror.fromTextArea(document.getElementById('code'), {lineNumbers: true, mode: '#{@blob.raw_mime_type.content_type}', theme: 'eclipse'});
}); });
/ - content_for :javascripts do / - content_for :javascripts do

View File

@ -15,4 +15,12 @@ Rosa::Application.config.middleware.insert_before ::Grack::Handler, ::Grack::Aut
Dir[Rails.root.join("lib/ext/**/*.rb")].each {|f| require f} Dir[Rails.root.join("lib/ext/**/*.rb")].each {|f| require f}
# add rpm spec as mime type for *.spec files # add rpm spec as mime type for *.spec files
MIME::Types.add(MIME::Type.from_array(["text/x-rpm-spec", ['spec'], '8bit'])) types = [
["text/x-python", ['py'], '8bit'],
["text/x-rpm-spec", ['spec'], '8bit'],
["text/x-csrc", ['h', 'c'], '8bit'],
["text/x-c++src", ['cpp'], '8bit']
]
types.each do |type|
MIME::Types.add MIME::Type.from_array(type)
end

View File

@ -28,10 +28,22 @@ module Grit
# store all associated MIME::Types inside class # store all associated MIME::Types inside class
def set_associated_mimes def set_associated_mimes
@associated_mimes ||= MIME::Types.type_for(self.name) rescue [DEFAULT_RAW_MIME_TYPE] @associated_mimes ||= []
@associated_mimes = [DEFAULT_RAW_MIME_TYPE] if @associated_mimes.empty? if @associated_mimes.empty?
guesses = MIME::Types.type_for(self.name) rescue [DEFAULT_RAW_MIME_TYPE]
guesses = [DEFAULT_RAW_MIME_TYPE] if guesses.empty?
@associated_mimes = guesses.sort{|a,b| mime_sort(a, b)}
end
@associated_mimes @associated_mimes
end end
# TODO make more clever function
def mime_sort(a,b)
return 0 if a.media_type == b.media_type and a.registered? == b.registered?
return -1 if a.media_type == 'text' and !a.registered?
return 1
end
end end
end end