Commit 98b5c3647bae81fcc010a6f95dc557b7ea6135f6
1 parent
26deb7e0
Exists in
master
and in
4 other branches
use monkey patch to trancoding content
Showing
1 changed file
with
18 additions
and
0 deletions
Show diff stats
config/initializers/gitlabhq/20_grit_ext.rb
... | ... | @@ -7,5 +7,23 @@ Grit::Blob.class_eval do |
7 | 7 | include Utils::Colorize |
8 | 8 | end |
9 | 9 | |
10 | +#monkey patch raw_object from string | |
11 | +Grit::GitRuby::Internal::RawObject.class_eval do | |
12 | + def content | |
13 | + transcoding(@content) | |
14 | + end | |
15 | + | |
16 | + private | |
17 | + def transcoding(content) | |
18 | + content ||= "" | |
19 | + detection = CharlockHolmes::EncodingDetector.detect(content) | |
20 | + if hash = detection | |
21 | + content = CharlockHolmes::Converter.convert(content, hash[:encoding], 'UTF-8') if hash[:encoding] | |
22 | + end | |
23 | + content | |
24 | + end | |
25 | +end | |
26 | + | |
27 | + | |
10 | 28 | Grit::Git.git_timeout = GIT_OPTS["git_timeout"] |
11 | 29 | Grit::Git.git_max_size = GIT_OPTS["git_max_size"] | ... | ... |