20_grit_ext.rb 646 Bytes
Newer Older
gitlabhq's avatar
gitlabhq committed
1
require 'grit'
gitlabhq's avatar
gitlabhq committed
2
require 'pygments'
gitlabhq's avatar
gitlabhq committed
3 4 5 6 7 8
require "utils"

Grit::Blob.class_eval do
  include Utils::FileHelper
  include Utils::Colorize
end
gitlabhq's avatar
gitlabhq committed
9

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#monkey patch raw_object from string
Grit::GitRuby::Internal::RawObject.class_eval do
  def content
    transcoding(@content)
  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


28 29
Grit::Git.git_timeout = GIT_OPTS["git_timeout"]
Grit::Git.git_max_size = GIT_OPTS["git_max_size"]