Commit 7002b9ff authored by Saito's avatar Saito

Merge branch 'chardet'

parents 22442039 46cbe541
source 'http://rubygems.org' source "http://rubygems.org"
gem 'rails', '3.1.1' gem "rails", "3.1.1"
gem 'sqlite3' gem "sqlite3"
gem 'devise', "1.5.0" gem "devise", "1.5.0"
gem 'stamp' gem "stamp"
gem 'kaminari' gem "kaminari"
gem 'haml-rails' gem "haml-rails"
gem 'jquery-rails' gem "jquery-rails"
gem 'grit', :git => 'https://github.com/gitlabhq/grit.git' gem "grit", :git => "https://github.com/gitlabhq/grit.git"
gem "carrierwave" gem "carrierwave"
gem 'six' gem "six"
gem 'therubyracer' gem "therubyracer"
gem 'faker' gem "faker"
gem 'seed-fu', '~> 2.1.0' gem "seed-fu", "~> 2.1.0"
gem "inifile" gem "inifile"
gem "pygments.rb", "0.2.3" gem "pygments.rb", "0.2.3"
gem "thin" gem "thin"
gem "git" gem "git"
gem "acts_as_list" 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"
group :assets do group :assets do
gem 'sass-rails', "~> 3.1.0" gem "sass-rails", "~> 3.1.0"
gem 'coffee-rails', "~> 3.1.0" gem "coffee-rails", "~> 3.1.0"
gem 'uglifier' gem "uglifier"
end end
group :development do group :development do
gem 'letter_opener' gem "letter_opener"
gem 'rails-footnotes', '~> 3.7.5' gem "rails-footnotes", "~> 3.7.5"
gem 'annotate', :git => 'https://github.com/ctran/annotate_models.git' gem "annotate", :git => "https://github.com/ctran/annotate_models.git"
end end
group :development, :test do group :development, :test do
gem 'rspec-rails' gem "rspec-rails"
gem 'capybara' gem "capybara"
gem 'autotest' gem "autotest"
gem 'autotest-rails' gem "autotest-rails"
unless ENV["CI"] unless ENV["CI"]
gem 'ruby-debug19', :require => 'ruby-debug' gem "ruby-debug19", :require => "ruby-debug"
end end
gem 'awesome_print' gem "awesome_print"
gem 'database_cleaner' gem "database_cleaner"
gem 'launchy' gem "launchy"
end end
group :test do group :test do
gem 'turn', :require => false gem "turn", :require => false
gem 'simplecov', :require => false gem "simplecov", :require => false
gem "shoulda", "~> 3.0.0.beta2" gem "shoulda", "~> 3.0.0.beta2"
end end
...@@ -157,6 +157,7 @@ GEM ...@@ -157,6 +157,7 @@ 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)
...@@ -268,6 +269,7 @@ DEPENDENCIES ...@@ -268,6 +269,7 @@ 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
rspec-rails rspec-rails
ruby-debug19 ruby-debug19
......
module CommitsHelper module CommitsHelper
include Utils::CharEncode
def diff_line(line, line_new = 0, line_old = 0) def diff_line(line, line_new = 0, line_old = 0)
full_line = html_escape(line.gsub(/\n/, '')) full_line = html_escape(line.gsub(/\n/, ''))
color = if line[0] == "+" color = if line[0] == "+"
......
class Commit class Commit
include Utils::CharEncode
attr_accessor :commit attr_accessor :commit
attr_accessor :head attr_accessor :head
...@@ -20,7 +22,7 @@ class Commit ...@@ -20,7 +22,7 @@ class Commit
end end
def safe_message def safe_message
message.force_encoding(Encoding::UTF_8) encode(message)
end end
def created_at def created_at
...@@ -28,10 +30,10 @@ class Commit ...@@ -28,10 +30,10 @@ class Commit
end end
def author_email def author_email
author.email.force_encoding(Encoding::UTF_8) encode(author.email)
end end
def author_name def author_name
author.name.force_encoding(Encoding::UTF_8) encode(author.name)
end end
end end
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
- line_new = 0 - line_new = 0
- lines_arr = diff.diff.lines.to_a - lines_arr = diff.diff.lines.to_a
- lines_arr.each do |line| - lines_arr.each do |line|
- line.force_encoding(Encoding::UTF_8) - encode(line)
- next if line.match(/^--- \/dev\/null/) - next if line.match(/^--- \/dev\/null/)
- next if line.match(/^--- a/) - next if line.match(/^--- a/)
- next if line.match(/^\+\+\+ b/) - next if line.match(/^\+\+\+ b/)
......
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
...@@ -65,7 +66,7 @@ class GraphCommit ...@@ -65,7 +66,7 @@ class GraphCommit
# @param [GraphCommit] the commit object. # @param [GraphCommit] the commit object.
# @param [Hash<String,GraphCommit>] map of commits # @param [Hash<String,GraphCommit>] map of commits
# #
# @return [Fixnum] max space used. # @return [Fixnum] max space used.
def self.mark_chain(mark, commit, map) def self.mark_chain(mark, commit, map)
commit.space = mark if commit.space == 0 commit.space = mark if commit.space == 0
m1 = mark - 1 m1 = mark - 1
...@@ -96,13 +97,13 @@ class GraphCommit ...@@ -96,13 +97,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] = author.name.force_encoding("UTF-8") h[:author] = encode(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] = message.force_encoding("UTF-8") h[:message] = encode(message)
h[:login] = author.email h[:login] = author.email
h h
end end
......
...@@ -16,9 +16,20 @@ module Utils ...@@ -16,9 +16,20 @@ module Utils
end end
end end
module CharEncode
def encode(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)
end
end
module Colorize module Colorize
include CharEncode
def colorize def colorize
system_colorize(data, name) system_colorize(encode(data), name)
end end
def system_colorize(data, file_name) def system_colorize(data, file_name)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment