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 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
- [7] pry(main)> blob.text?
42
+ [8] pry(main)> blob.text?
43
43
  => true
44
- [7] pry(main)> blob.image?
44
+ [9] pry(main)> blob.image?
45
45
  => false
46
- [7] pry(main)> blob.binary?
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::VERSION
16
+ gem.version = GritExt.version
17
17
 
18
- gem.add_dependency("charlock_holmes", "~> 0.6.8")
19
- gem.add_dependency("language_sniffer", "~> 1.0.1")
18
+ gem.add_dependency("charlock_holmes", "~> 0.6.9")
20
19
  end
@@ -0,0 +1,10 @@
1
+ module Grit
2
+ class Actor
3
+
4
+ alias_method :old_name, :name
5
+
6
+ def name
7
+ GritExt.transcode old_name
8
+ end
9
+ end
10
+ 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
- def image?
8
- !!(mime_type =~ /image/)
9
- end
4
+ alias_method :old_name, :name
5
+ alias_method :old_data, :data
10
6
 
11
- def binary?
12
- data[0..1024].include?("\000")
7
+ def name
8
+ GritExt.transcode old_name
13
9
  end
14
10
 
15
- def encoding
16
- if detection = CharlockHolmes::EncodingDetector.detect(data)
17
- detection[:encoding]
18
- end
11
+ def data
12
+ GritExt.transcode old_data
19
13
  end
20
14
 
21
- def language
22
- if lang = LanguageSniffer.detect(basename, :content => data).language
23
- lang.name
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
@@ -0,0 +1,16 @@
1
+ module Grit
2
+ class Diff
3
+
4
+ def old_path
5
+ GritExt.transcode @a_path
6
+ end
7
+
8
+ def new_path
9
+ GritExt.transcode @b_path
10
+ end
11
+
12
+ def diff
13
+ GritExt.transcode @diff
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,10 @@
1
+ module Grit
2
+ class Tag
3
+
4
+ alias_method :old_message, :message
5
+
6
+ def message
7
+ GritExt.transcode old_message
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Grit
2
+ class Tree
3
+
4
+ alias_method :old_name, :name
5
+
6
+ def name
7
+ GritExt.transcode old_name
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,7 @@
1
1
  module GritExt
2
- VERSION = "0.1.0"
2
+ extend self
3
+
4
+ def version
5
+ "0.5.0"
6
+ end
3
7
  end
data/lib/grit_ext.rb CHANGED
@@ -1,18 +1,37 @@
1
- require "rubygems"
2
1
  require "charlock_holmes"
3
- require "language_sniffer"
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
- private
10
- def transcode(content)
11
- detection = CharlockHolmes::EncodingDetector.detect(content)
12
- if hash = detection
13
- content = CharlockHolmes::Converter.convert(content, hash[:encoding], 'UTF-8') if hash[:encoding]
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
- content
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.1.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-01-05 00:00:00.000000000Z
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: &70258896872560 !ruby/object:Gem::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.8
21
+ version: 0.6.9
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70258896872560
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: 1.0.1
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/raw_object.rb
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.10
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
@@ -1,13 +0,0 @@
1
- module Grit
2
- module GitRuby
3
- module Internal
4
- class RawObject
5
- include GritExt
6
-
7
- def content
8
- transcode(@content)
9
- end
10
- end
11
- end
12
- end
13
- end