grit-ext-0.8.1/0000755000175000017500000000000012133011763012604 5ustar ondrejondrejgrit-ext-0.8.1/spec/0000755000175000017500000000000012133011763013536 5ustar ondrejondrejgrit-ext-0.8.1/spec/spec_helper.rb0000644000175000017500000000006012133011763016350 0ustar ondrejondrejrequire 'pry' require 'grit' require 'grit_ext' grit-ext-0.8.1/spec/grit_ext_spec.rb0000644000175000017500000000213412133011763016722 0ustar ondrejondrej# encoding: UTF-8 require "spec_helper" describe GritExt do describe :encode! do it "should return nil if the message is nil" do message = GritExt.encode! nil message.should be_nil end it "should return binary it self when message is binary" do message = "\xFF\xD8\xFF\xE0" encoded_message = GritExt.encode!(message) encoded_message.bytes.to_a.should eql(message.bytes.to_a) message.encoding.name.should eql("ASCII-8BIT") end it "cleans up UTF-8 strings with invalid encoding" do message = GritExt.encode!("yummy\xE2 \xF0\x9F\x8D\x94 \x9F\x8D\x94") message.should eql("yummy 🍔 ") message.encoding.name.should eql("UTF-8") end it "encode string to UTF-8" do message = GritExt.encode!("{foo \xC3 'bar'}") message.should eql("{foo à 'bar'}") message.encoding.name.should eql("UTF-8") message = "我爱你".encode("GBK") message.encoding.name.should eql("GBK") GritExt.encode!(message) message.should eql("我爱你") message.encoding.name.should eql("UTF-8") end end end grit-ext-0.8.1/LICENSE0000644000175000017500000000204512133011763013612 0ustar ondrejondrejCopyright (c) 2012 Saito MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.grit-ext-0.8.1/Rakefile0000644000175000017500000000006012133011763014245 0ustar ondrejondrej#!/usr/bin/env rake require "bundler/gem_tasks" grit-ext-0.8.1/.gitignore0000644000175000017500000000024412133011763014574 0ustar ondrejondrej*.gem *.rbc .bundle .config .yardoc Gemfile.lock InstalledFiles _yardoc coverage doc/ lib/bundler/man pkg rdoc spec/reports test/tmp test/version_tmp tmp .Ds_Store grit-ext-0.8.1/.rspec0000644000175000017500000000003212133011763013714 0ustar ondrejondrej--color --format progress grit-ext-0.8.1/lib/0000755000175000017500000000000012133011763013352 5ustar ondrejondrejgrit-ext-0.8.1/lib/grit_ext.rb0000644000175000017500000000215112133011763015523 0ustar ondrejondrejrequire "charlock_holmes" require "grit_ext/actor" require "grit_ext/blob" require "grit_ext/commit" require "grit_ext/tree" require "grit_ext/diff" require "grit_ext/version" module GritExt extend self def encode!(message) return nil unless message.respond_to? :force_encoding # if message is utf-8 encoding, just return it message.force_encoding("UTF-8") return message if message.valid_encoding? # return message if message type is binary detect = CharlockHolmes::EncodingDetector.detect(message) return message.force_encoding("BINARY") if detect && detect[:type] == :binary # encoding message to detect encoding if detect && detect[:encoding] message.force_encoding(detect[:encoding]) end # encode and clean the bad chars message.replace clean(message) rescue encoding = detect ? detect[:encoding] : "unknown" "--broken encoding: #{encoding}" end private def clean(message) message.encode("UTF-16BE", :undef => :replace, :invalid => :replace, :replace => "") .encode("UTF-8") .gsub("\0".encode("UTF-8"), "") end end grit-ext-0.8.1/lib/grit_ext/0000755000175000017500000000000012133011763015177 5ustar ondrejondrejgrit-ext-0.8.1/lib/grit_ext/tag.rb0000644000175000017500000000020612133011763016275 0ustar ondrejondrejmodule Grit class Tag alias_method :old_message, :message def message GritExt.encode! old_message end end end grit-ext-0.8.1/lib/grit_ext/tree.rb0000644000175000017500000000017312133011763016464 0ustar ondrejondrejmodule Grit class Tree alias_method :old_name, :name def name GritExt.encode! old_name end end end grit-ext-0.8.1/lib/grit_ext/actor.rb0000644000175000017500000000032712133011763016636 0ustar ondrejondrejmodule Grit class Actor alias_method :old_name, :name alias_method :old_email, :email def name GritExt.encode! old_name end def email GritExt.encode! old_email end end end grit-ext-0.8.1/lib/grit_ext/blob.rb0000644000175000017500000000070312133011763016442 0ustar ondrejondrejmodule Grit class Blob alias_method :old_name, :name alias_method :old_data, :data def name GritExt.encode! old_name end def data GritExt.encode! old_data end class << self alias_method :old_blame, :blame def blame(repo, commit, file) old_blame(repo, commit, file).map do |b,lines| [b, GritExt.encode!(lines.join('\n')).split('\n')] end end end end end grit-ext-0.8.1/lib/grit_ext/diff.rb0000644000175000017500000000057712133011763016445 0ustar ondrejondrejmodule Grit class Diff def old_path GritExt.encode! @a_path end def new_path GritExt.encode! @b_path end def diff if @diff.nil? @diff = "" else lines = @diff.lines.to_a path = GritExt.encode! lines.shift(2).join body = GritExt.encode! lines.join @diff = path + body end end end end grit-ext-0.8.1/lib/grit_ext/commit.rb0000644000175000017500000000040412133011763017012 0ustar ondrejondrejmodule Grit class Commit alias_method :old_message, :message alias_method :old_short_message, :short_message def message GritExt.encode! old_message end def short_message GritExt.encode! old_short_message end end end grit-ext-0.8.1/lib/grit_ext/version.rb0000644000175000017500000000010212133011763017202 0ustar ondrejondrejmodule GritExt extend self def version "0.8.1" end end grit-ext-0.8.1/README.md0000644000175000017500000000106012133011763014060 0ustar ondrejondrej# GritExt grit_ext is a grit extension gem. ## Installation Add this line to your application's Gemfile: gem 'grit_ext' And then execute: $ bundle Or install it yourself as: $ gem install grit_ext ## Usage ```ruby [1] pry(main)> require'grit' => true [2] pry(main)> require'grit_ext' => true ``` ## Contributing 1. Fork it 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Added some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create new Pull Request grit-ext-0.8.1/metadata.yml0000644000175000017500000000644512133011763015120 0ustar ondrejondrej--- !ruby/object:Gem::Specification name: grit_ext version: !ruby/object:Gem::Version version: 0.8.1 prerelease: platform: ruby authors: - Saito autorequire: bindir: bin cert_chain: [] date: 2013-03-25 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: charlock_holmes requirement: !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: 0.6.9 type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: 0.6.9 - !ruby/object:Gem::Dependency name: rspec requirement: !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: '2.11' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: '2.11' - !ruby/object:Gem::Dependency name: grit requirement: !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: '2.5' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: '2.5' - !ruby/object:Gem::Dependency name: rake requirement: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: pry requirement: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' description: the grit's utf-8 support email: - saitowu@gmail.com executables: [] extensions: [] extra_rdoc_files: [] files: - .gitignore - .rspec - Gemfile - LICENSE - README.md - Rakefile - grit_ext.gemspec - lib/grit_ext.rb - lib/grit_ext/actor.rb - lib/grit_ext/blob.rb - lib/grit_ext/commit.rb - lib/grit_ext/diff.rb - lib/grit_ext/tag.rb - lib/grit_ext/tree.rb - lib/grit_ext/version.rb - spec/grit_ext_spec.rb - spec/spec_helper.rb homepage: https://github.com/saitowu/grit_ext licenses: [] post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' segments: - 0 hash: 1806124678689769249 required_rubygems_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' segments: - 0 hash: 1806124678689769249 requirements: [] rubyforge_project: rubygems_version: 1.8.25 signing_key: specification_version: 3 summary: gives grit utf-8 support test_files: - spec/grit_ext_spec.rb - spec/spec_helper.rb grit-ext-0.8.1/Gemfile0000644000175000017500000000013512133011763014076 0ustar ondrejondrejsource 'https://rubygems.org' # Specify your gem's dependencies in grit_ext.gemspec gemspec grit-ext-0.8.1/grit_ext.gemspec0000644000175000017500000000162212133011763015777 0ustar ondrejondrej# -*- encoding: utf-8 -*- require File.expand_path('../lib/grit_ext/version', __FILE__) Gem::Specification.new do |gem| gem.authors = ["Saito"] gem.email = ["saitowu@gmail.com"] gem.description = %q{the grit's utf-8 support} gem.summary = %q{gives grit utf-8 support} gem.homepage = "https://github.com/saitowu/grit_ext" gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } gem.files = `git ls-files`.split("\n") gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") gem.name = "grit_ext" gem.require_paths = ["lib"] gem.version = GritExt.version gem.add_dependency("charlock_holmes", "~> 0.6.9") gem.add_development_dependency("rspec", "~> 2.11") gem.add_development_dependency("grit", "~> 2.5") gem.add_development_dependency("rake") gem.add_development_dependency("pry") end