diff --git a/app/views/git/blobs/_editor.html.haml b/app/views/git/blobs/_editor.html.haml
index abe5f88e9..61263d9e3 100644
--- a/app/views/git/blobs/_editor.html.haml
+++ b/app/views/git/blobs/_editor.html.haml
@@ -36,7 +36,7 @@
:javascript
$(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
diff --git a/config/initializers/load_config.rb b/config/initializers/load_config.rb
index 24ff52a08..11203b486 100644
--- a/config/initializers/load_config.rb
+++ b/config/initializers/load_config.rb
@@ -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}
# 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
diff --git a/lib/grit/blob.rb b/lib/grit/blob.rb
index 24c9c46d1..043553435 100644
--- a/lib/grit/blob.rb
+++ b/lib/grit/blob.rb
@@ -28,10 +28,22 @@ module Grit
# store all associated MIME::Types inside class
def set_associated_mimes
- @associated_mimes ||= MIME::Types.type_for(self.name) rescue [DEFAULT_RAW_MIME_TYPE]
- @associated_mimes = [DEFAULT_RAW_MIME_TYPE] if @associated_mimes.empty?
+ @associated_mimes ||= []
+ 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
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