grit_ext 0.1.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -3
- data/grit_ext.gemspec +2 -3
- data/lib/grit_ext/actor.rb +10 -0
- data/lib/grit_ext/blob.rb +14 -16
- data/lib/grit_ext/commit.rb +15 -0
- data/lib/grit_ext/diff.rb +16 -0
- data/lib/grit_ext/tag.rb +10 -0
- data/lib/grit_ext/tree.rb +10 -0
- data/lib/grit_ext/version.rb +5 -1
- data/lib/grit_ext.rb +29 -10
- metadata +12 -14
- data/lib/grit_ext/raw_object.rb +0 -13
data/README.md
CHANGED
@@ -39,11 +39,11 @@ Or install it yourself as:
|
|
39
39
|
=> "ISO-8859-1"
|
40
40
|
[7] pry(main)> blob.data
|
41
41
|
=> "source 'https://rubygems.org'\n\n# Specify your gem's dependencies in grit_ext.gemspec\ngemspec\n"
|
42
|
-
[
|
42
|
+
[8] pry(main)> blob.text?
|
43
43
|
=> true
|
44
|
-
[
|
44
|
+
[9] pry(main)> blob.image?
|
45
45
|
=> false
|
46
|
-
[
|
46
|
+
[10] pry(main)> blob.binary?
|
47
47
|
=> false
|
48
48
|
```
|
49
49
|
|
data/grit_ext.gemspec
CHANGED
@@ -13,8 +13,7 @@ Gem::Specification.new do |gem|
|
|
13
13
|
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
14
|
gem.name = "grit_ext"
|
15
15
|
gem.require_paths = ["lib"]
|
16
|
-
gem.version = GritExt
|
16
|
+
gem.version = GritExt.version
|
17
17
|
|
18
|
-
gem.add_dependency("charlock_holmes", "~> 0.6.
|
19
|
-
gem.add_dependency("language_sniffer", "~> 1.0.1")
|
18
|
+
gem.add_dependency("charlock_holmes", "~> 0.6.9")
|
20
19
|
end
|
data/lib/grit_ext/blob.rb
CHANGED
@@ -1,28 +1,26 @@
|
|
1
1
|
module Grit
|
2
2
|
class Blob
|
3
|
-
def text?
|
4
|
-
!!(mime_type =~ /application|text/ && !binary?)
|
5
|
-
end
|
6
3
|
|
7
|
-
|
8
|
-
|
9
|
-
end
|
4
|
+
alias_method :old_name, :name
|
5
|
+
alias_method :old_data, :data
|
10
6
|
|
11
|
-
def
|
12
|
-
|
7
|
+
def name
|
8
|
+
GritExt.transcode old_name
|
13
9
|
end
|
14
10
|
|
15
|
-
def
|
16
|
-
|
17
|
-
detection[:encoding]
|
18
|
-
end
|
11
|
+
def data
|
12
|
+
GritExt.transcode old_data
|
19
13
|
end
|
20
14
|
|
21
|
-
|
22
|
-
|
23
|
-
|
15
|
+
class << self
|
16
|
+
alias_method :old_blame, :blame
|
17
|
+
|
18
|
+
def blame(repo, commit, file)
|
19
|
+
old_blame(repo, commit, file).map do |b,lines|
|
20
|
+
[b, GritExt.transcode(lines.join('\n')).split('\n')]
|
21
|
+
end
|
24
22
|
end
|
25
23
|
end
|
24
|
+
|
26
25
|
end
|
27
26
|
end
|
28
|
-
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Grit
|
2
|
+
class Commit
|
3
|
+
|
4
|
+
alias_method :old_message, :message
|
5
|
+
alias_method :old_short_message, :short_message
|
6
|
+
|
7
|
+
def message
|
8
|
+
GritExt.transcode old_message
|
9
|
+
end
|
10
|
+
|
11
|
+
def short_message
|
12
|
+
GritExt.transcode old_short_message
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/grit_ext/tag.rb
ADDED
data/lib/grit_ext/version.rb
CHANGED
data/lib/grit_ext.rb
CHANGED
@@ -1,18 +1,37 @@
|
|
1
|
-
require "rubygems"
|
2
1
|
require "charlock_holmes"
|
3
|
-
require "
|
2
|
+
require "grit_ext/actor"
|
4
3
|
require "grit_ext/blob"
|
4
|
+
require "grit_ext/commit"
|
5
|
+
require "grit_ext/tree"
|
6
|
+
require "grit_ext/diff"
|
5
7
|
require "grit_ext/version"
|
6
|
-
require "grit_ext/raw_object"
|
7
8
|
|
8
9
|
module GritExt
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
extend self
|
11
|
+
|
12
|
+
def transcode(message)
|
13
|
+
return nil unless message.respond_to? :force_encoding
|
14
|
+
|
15
|
+
# if message is utf-8 encoding, just return it
|
16
|
+
message.force_encoding("UTF-8")
|
17
|
+
return message if message.valid_encoding?
|
18
|
+
|
19
|
+
# return message if message type is binary
|
20
|
+
detect = CharlockHolmes::EncodingDetector.detect(message)
|
21
|
+
return message if detect[:type] == :binary
|
22
|
+
|
23
|
+
# if message is not utf-8 encoding, convert it
|
24
|
+
if detect[:encoding]
|
25
|
+
message.force_encoding(detect[:encoding])
|
26
|
+
message.encode!("UTF-8", detect[:encoding], undef: :replace, replace: "", invalid: :replace)
|
14
27
|
end
|
15
|
-
|
28
|
+
|
29
|
+
# ensure message encoding is utf8
|
30
|
+
message.valid_encoding? ? message : raise
|
31
|
+
|
32
|
+
# Prevent app from crash cause of encoding errors
|
33
|
+
rescue
|
34
|
+
encoding = detect ? detect[:encoding] : "unknown"
|
35
|
+
"--broken encoding: #{encoding}"
|
16
36
|
end
|
17
37
|
end
|
18
|
-
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grit_ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,30 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: charlock_holmes
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.6.
|
21
|
+
version: 0.6.9
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: language_sniffer
|
27
|
-
requirement: &70258891864420 !ruby/object:Gem::Requirement
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
25
|
none: false
|
29
26
|
requirements:
|
30
27
|
- - ~>
|
31
28
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
33
|
-
type: :runtime
|
34
|
-
prerelease: false
|
35
|
-
version_requirements: *70258891864420
|
29
|
+
version: 0.6.9
|
36
30
|
description: the grit's extension
|
37
31
|
email:
|
38
32
|
- saitowu@gmail.com
|
@@ -47,8 +41,12 @@ files:
|
|
47
41
|
- Rakefile
|
48
42
|
- grit_ext.gemspec
|
49
43
|
- lib/grit_ext.rb
|
44
|
+
- lib/grit_ext/actor.rb
|
50
45
|
- lib/grit_ext/blob.rb
|
51
|
-
- lib/grit_ext/
|
46
|
+
- lib/grit_ext/commit.rb
|
47
|
+
- lib/grit_ext/diff.rb
|
48
|
+
- lib/grit_ext/tag.rb
|
49
|
+
- lib/grit_ext/tree.rb
|
52
50
|
- lib/grit_ext/version.rb
|
53
51
|
homepage: http://saito.im
|
54
52
|
licenses: []
|
@@ -70,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
68
|
version: '0'
|
71
69
|
requirements: []
|
72
70
|
rubyforge_project:
|
73
|
-
rubygems_version: 1.8.
|
71
|
+
rubygems_version: 1.8.24
|
74
72
|
signing_key:
|
75
73
|
specification_version: 3
|
76
74
|
summary: gives grit utf-8 support and some misc enhancement
|