[issue #274] Fixed file detection.

TODO.

  1.  Change MIME in editor
  2.  Change MIME sorting
This commit is contained in:
George Vinogradov 2012-03-07 05:20:35 +04:00
parent 396540ffe3
commit d6d8410b0f
7 changed files with 50 additions and 7 deletions

View File

@ -305,6 +305,7 @@ table.tablesorter tbody td a .issue_title {
#output.formatted {
width: auto;
font-family: "Consolas","Bitstream Vera Sans Mono","Courier New",Courier,monospace;
color: #000000;
padding: 10px 5px 0px;
margin-left: 45px;
}

View File

@ -52,9 +52,11 @@ module GitHelper
end
def choose_render_way(blob)
return :image if blob.mime_type.match(/image/)
return :text if blob.mime_type.match(/text|xml|json/)
:binary
return :image if blob.mime_type.match(/image/)
return :binary if blob.binary?
:text
# return :text if blob.mime_type.match(/text|xml|json/)
# :binary
end
def force_encoding_to_site(string)

View File

@ -53,5 +53,5 @@
:javascript
$(document).ready(function() {
var text = $('#code').text().replace(/&/gi, '&');
CodeMirror.runMode(text, "#{File.extname(@blob.name) == '.spec' ? 'text/x-rpm-spec' : @blob.mime_type}", document.getElementById("output"));
CodeMirror.runMode(text, "#{@blob.raw_mime_type.content_type}", document.getElementById("output"));
});

View File

@ -13,3 +13,6 @@ Rosa::Application.config.middleware.insert_before ::Grack::Handler, ::Grack::Aut
# Grit::Git.git_timeout = 60
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']))

View File

@ -284,11 +284,11 @@ ActiveRecord::Schema.define(:version => 20120303171802) do
t.text "description"
t.string "ancestry"
t.boolean "has_issues", :default => true
t.boolean "has_wiki", :default => false
t.string "srpm_file_name"
t.string "srpm_content_type"
t.integer "srpm_file_size"
t.datetime "srpm_updated_at"
t.boolean "has_wiki", :default => false
t.string "default_branch", :default => "master"
t.boolean "is_rpm", :default => true
end
@ -309,7 +309,6 @@ ActiveRecord::Schema.define(:version => 20120303171802) do
end
add_index "register_requests", ["email"], :name => "index_register_requests_on_email", :unique => true, :case_sensitive => false
add_index "register_requests", ["token"], :name => "index_register_requests_on_token", :unique => true, :case_sensitive => false
create_table "relations", :force => true do |t|
t.integer "object_id"
@ -369,6 +368,7 @@ ActiveRecord::Schema.define(:version => 20120303171802) do
t.string "email", :default => "", :null => false
t.string "encrypted_password", :limit => 128, :default => "", :null => false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.datetime "created_at"
t.datetime "updated_at"
@ -376,7 +376,6 @@ ActiveRecord::Schema.define(:version => 20120303171802) do
t.string "uname"
t.string "role"
t.string "language", :default => "en"
t.datetime "reset_password_sent_at"
t.integer "own_projects_count", :default => 0, :null => false
t.text "professional_experience"
t.string "site"

37
lib/grit/blob.rb Normal file
View File

@ -0,0 +1,37 @@
# -*- ruby encoding: utf-8 -*-
module Grit
class Blob
DEFAULT_RAW_MIME_TYPE = MIME::Types[DEFAULT_MIME_TYPE].first
delegate :binary?, :ascii?, :encoding, :to => :raw_mime_type
def mime_type_with_class_store
set_associated_mimes
@associated_mimes.first.simplified
end
alias_method_chain :mime_type, :class_store
attr_accessor :raw_mime_type
def raw_mime_type
set_associated_mimes
@raw_mime_type = @associated_mimes.first || DEFAULT_RAW_MIME_TYPE
@raw_mime_type
end
def raw_mime_types
set_associated_mimes
end
protected
# 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
end
end
end

View File

@ -1,3 +1,4 @@
# -*- encoding : utf-8 -*-
require './lib/grit/repo.rb'
require './lib/grit/diff.rb'
require './lib/grit/blob.rb'