2011-10-20 22:00:00 +03:00
|
|
|
require 'grit'
|
2011-10-21 15:35:42 +03:00
|
|
|
require 'pygments'
|
2011-10-20 22:00:00 +03:00
|
|
|
require "utils"
|
|
|
|
|
|
|
|
Grit::Blob.class_eval do
|
|
|
|
include Utils::FileHelper
|
|
|
|
include Utils::Colorize
|
|
|
|
end
|
2011-10-24 22:38:03 +03:00
|
|
|
|
2011-12-30 22:26:13 +08:00
|
|
|
#monkey patch raw_object from string
|
|
|
|
Grit::GitRuby::Internal::RawObject.class_eval do
|
|
|
|
def content
|
|
|
|
transcoding(@content)
|
2012-03-02 19:42:28 +03:00
|
|
|
rescue Exception => ex
|
|
|
|
Rails.logger.error ex.message
|
|
|
|
@content
|
2011-12-30 22:26:13 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def transcoding(content)
|
|
|
|
content ||= ""
|
|
|
|
detection = CharlockHolmes::EncodingDetector.detect(content)
|
|
|
|
if hash = detection
|
|
|
|
content = CharlockHolmes::Converter.convert(content, hash[:encoding], 'UTF-8') if hash[:encoding]
|
|
|
|
end
|
|
|
|
content
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2011-11-25 22:18:36 +02:00
|
|
|
Grit::Git.git_timeout = GIT_OPTS["git_timeout"]
|
|
|
|
Grit::Git.git_max_size = GIT_OPTS["git_max_size"]
|