Merge branch 'grit_ext'
This commit is contained in:
commit
d34904b86c
|
@ -1,3 +1,4 @@
|
||||||
|
before_install: sudo apt-get install libicu-dev -y
|
||||||
branches:
|
branches:
|
||||||
only:
|
only:
|
||||||
- 'master'
|
- 'master'
|
||||||
|
|
2
Gemfile
2
Gemfile
|
@ -22,9 +22,9 @@ gem "acts_as_list"
|
||||||
gem "rdiscount"
|
gem "rdiscount"
|
||||||
gem "acts-as-taggable-on", "~> 2.1.0"
|
gem "acts-as-taggable-on", "~> 2.1.0"
|
||||||
gem "drapper"
|
gem "drapper"
|
||||||
gem "rchardet19", "~> 1.3.5"
|
|
||||||
gem "resque"
|
gem "resque"
|
||||||
gem "httparty"
|
gem "httparty"
|
||||||
|
gem "charlock_holmes"
|
||||||
|
|
||||||
group :assets do
|
group :assets do
|
||||||
gem "sass-rails", "~> 3.1.0"
|
gem "sass-rails", "~> 3.1.0"
|
||||||
|
|
|
@ -77,6 +77,7 @@ GEM
|
||||||
xpath (~> 0.1.4)
|
xpath (~> 0.1.4)
|
||||||
carrierwave (0.5.8)
|
carrierwave (0.5.8)
|
||||||
activesupport (~> 3.0)
|
activesupport (~> 3.0)
|
||||||
|
charlock_holmes (0.6.8)
|
||||||
childprocess (0.2.2)
|
childprocess (0.2.2)
|
||||||
ffi (~> 1.0.6)
|
ffi (~> 1.0.6)
|
||||||
coffee-rails (3.1.1)
|
coffee-rails (3.1.1)
|
||||||
|
@ -172,7 +173,6 @@ GEM
|
||||||
rdoc (~> 3.4)
|
rdoc (~> 3.4)
|
||||||
thor (~> 0.14.6)
|
thor (~> 0.14.6)
|
||||||
rake (0.9.2.2)
|
rake (0.9.2.2)
|
||||||
rchardet19 (1.3.5)
|
|
||||||
rdiscount (1.6.8)
|
rdiscount (1.6.8)
|
||||||
rdoc (3.11)
|
rdoc (3.11)
|
||||||
json (~> 1.4)
|
json (~> 1.4)
|
||||||
|
@ -285,6 +285,7 @@ DEPENDENCIES
|
||||||
awesome_print
|
awesome_print
|
||||||
capybara
|
capybara
|
||||||
carrierwave
|
carrierwave
|
||||||
|
charlock_holmes
|
||||||
coffee-rails (~> 3.1.0)
|
coffee-rails (~> 3.1.0)
|
||||||
database_cleaner
|
database_cleaner
|
||||||
devise (= 1.5.0)
|
devise (= 1.5.0)
|
||||||
|
@ -302,7 +303,6 @@ DEPENDENCIES
|
||||||
pygments.rb (= 0.2.3)
|
pygments.rb (= 0.2.3)
|
||||||
rails (= 3.1.1)
|
rails (= 3.1.1)
|
||||||
rails-footnotes (~> 3.7.5)
|
rails-footnotes (~> 3.7.5)
|
||||||
rchardet19 (~> 1.3.5)
|
|
||||||
rdiscount
|
rdiscount
|
||||||
resque
|
resque
|
||||||
rspec-rails
|
rspec-rails
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
require 'digest/md5'
|
require 'digest/md5'
|
||||||
module ApplicationHelper
|
module ApplicationHelper
|
||||||
include Utils::CharEncode
|
|
||||||
|
|
||||||
def gravatar_icon(user_email, size = 40)
|
def gravatar_icon(user_email, size = 40)
|
||||||
gravatar_host = request.ssl? ? "https://secure.gravatar.com" : "http://www.gravatar.com"
|
gravatar_host = request.ssl? ? "https://secure.gravatar.com" : "http://www.gravatar.com"
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
class Commit
|
class Commit
|
||||||
include Utils::CharEncode
|
|
||||||
|
|
||||||
attr_accessor :commit
|
attr_accessor :commit
|
||||||
attr_accessor :head
|
attr_accessor :head
|
||||||
|
@ -22,7 +21,7 @@ class Commit
|
||||||
end
|
end
|
||||||
|
|
||||||
def safe_message
|
def safe_message
|
||||||
encode(message)
|
message
|
||||||
end
|
end
|
||||||
|
|
||||||
def created_at
|
def created_at
|
||||||
|
@ -30,11 +29,11 @@ class Commit
|
||||||
end
|
end
|
||||||
|
|
||||||
def author_email
|
def author_email
|
||||||
encode(author.email)
|
author.email
|
||||||
end
|
end
|
||||||
|
|
||||||
def author_name
|
def author_name
|
||||||
encode(author.name)
|
author.name
|
||||||
end
|
end
|
||||||
|
|
||||||
def prev_commit
|
def prev_commit
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
%table
|
%table
|
||||||
- line_old = 0
|
- line_old = 0
|
||||||
- line_new = 0
|
- line_new = 0
|
||||||
- diff_str = encode(diff.diff)
|
- diff_str = diff.diff
|
||||||
- lines_arr = diff_str.lines.to_a
|
- lines_arr = diff_str.lines.to_a
|
||||||
- lines_arr.each do |line|
|
- lines_arr.each do |line|
|
||||||
- next if line.match(/^--- \/dev\/null/)
|
- next if line.match(/^--- \/dev\/null/)
|
||||||
|
|
|
@ -40,9 +40,9 @@
|
||||||
%h3= content.name
|
%h3= content.name
|
||||||
.readme
|
.readme
|
||||||
- if content.name =~ /\.(md|markdown)$/i
|
- if content.name =~ /\.(md|markdown)$/i
|
||||||
= markdown(encode content.data)
|
= markdown(content.data)
|
||||||
- else
|
- else
|
||||||
= simple_format(encode content.data)
|
= simple_format(content.data)
|
||||||
|
|
||||||
:javascript
|
:javascript
|
||||||
$(function(){
|
$(function(){
|
||||||
|
|
|
@ -7,5 +7,23 @@ Grit::Blob.class_eval do
|
||||||
include Utils::Colorize
|
include Utils::Colorize
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#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
|
||||||
|
|
||||||
|
|
||||||
Grit::Git.git_timeout = GIT_OPTS["git_timeout"]
|
Grit::Git.git_timeout = GIT_OPTS["git_timeout"]
|
||||||
Grit::Git.git_max_size = GIT_OPTS["git_max_size"]
|
Grit::Git.git_max_size = GIT_OPTS["git_max_size"]
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
require "grit"
|
require "grit"
|
||||||
|
|
||||||
class GraphCommit
|
class GraphCommit
|
||||||
include Utils::CharEncode
|
|
||||||
attr_accessor :time, :space
|
attr_accessor :time, :space
|
||||||
attr_accessor :refs
|
attr_accessor :refs
|
||||||
|
|
||||||
|
@ -97,13 +96,13 @@ class GraphCommit
|
||||||
h[:parents] = self.parents.collect do |p|
|
h[:parents] = self.parents.collect do |p|
|
||||||
[p.id,0,0]
|
[p.id,0,0]
|
||||||
end
|
end
|
||||||
h[:author] = encode(author.name)
|
h[:author] = author.name
|
||||||
h[:time] = time
|
h[:time] = time
|
||||||
h[:space] = space
|
h[:space] = space
|
||||||
h[:refs] = refs.collect{|r|r.name}.join(" ") unless refs.nil?
|
h[:refs] = refs.collect{|r|r.name}.join(" ") unless refs.nil?
|
||||||
h[:id] = sha
|
h[:id] = sha
|
||||||
h[:date] = date
|
h[:date] = date
|
||||||
h[:message] = encode(message)
|
h[:message] = message
|
||||||
h[:login] = author.email
|
h[:login] = author.email
|
||||||
h
|
h
|
||||||
end
|
end
|
||||||
|
|
16
lib/utils.rb
16
lib/utils.rb
|
@ -16,28 +16,14 @@ module Utils
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module CharEncode
|
|
||||||
def encode(string)
|
|
||||||
return '' unless string
|
|
||||||
cd = CharDet.detect(string)
|
|
||||||
if cd.confidence > 0.6
|
|
||||||
string.force_encoding(cd.encoding)
|
|
||||||
end
|
|
||||||
string.encode("utf-8", :undef => :replace, :replace => "?", :invalid => :replace)
|
|
||||||
rescue
|
|
||||||
"Invalid Encoding"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
module Colorize
|
module Colorize
|
||||||
include CharEncode
|
|
||||||
def colorize
|
def colorize
|
||||||
system_colorize(data, name)
|
system_colorize(data, name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def system_colorize(data, file_name)
|
def system_colorize(data, file_name)
|
||||||
ft = handle_file_type(file_name)
|
ft = handle_file_type(file_name)
|
||||||
Pygments.highlight(encode(data), :lexer => ft, :options => { :encoding => 'utf-8', :linenos => 'True' })
|
Pygments.highlight(data, :lexer => ft, :options => { :encoding => 'utf-8', :linenos => 'True' })
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_file_type(file_name, mime_type = nil)
|
def handle_file_type(file_name, mime_type = nil)
|
||||||
|
|
Loading…
Reference in a new issue