hirb-unicode 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (C) 2011 by BigCat a.k.a. miaout17 (miaout17 at gmail dot com)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,5 +1,61 @@
1
- NOT READY TO RELEASE
1
+ # Hirb-unicode
2
+ `hirb-unicode` fixes the problem that [full-width unicode characters](http://en.wikipedia.org/wiki/Fullwidth_form#Fullwidth_form) is aligned incorrectly.
2
3
 
3
- UNDER DEVELOPMENT
4
+ In the original `hirb` unicode gem, the full-width character will be misaligned:
4
5
 
6
+ +----+-------------+-------------------------+-------------------------+
7
+ | id | content | created_at | updated_at |
8
+ +----+-------------+-------------------------+-------------------------+
9
+ | 2 | 大樂透後天開獎! | 2011-02-17 15:28:32 UTC | 2011-02-17 15:28:32 UTC |
10
+ | 3 | Hello,World | 2011-02-17 15:28:40 UTC | 2011-02-17 15:28:40 UTC |
11
+ | 4 | 頭獎上看十八億 | 2011-02-17 15:29:02 UTC | 2011-02-17 15:29:02 UTC |
12
+ | 5 | 海角上看七億 | 2011-02-17 15:29:18 UTC | 2011-02-17 15:29:18 UTC |
13
+ | 6 | こんにちは | 2011-02-17 15:32:18 UTC | 2011-02-17 15:32:18 UTC |
14
+ +----+-------------+-------------------------+-------------------------+
15
+
16
+ With `hirb-unicode`, the cells is correctly aligned:
17
+
18
+ +----+------------------+-------------------------+-------------------------+
19
+ | id | content | created_at | updated_at |
20
+ +----+------------------+-------------------------+-------------------------+
21
+ | 2 | 大樂透後天開獎! | 2011-02-17 15:28:32 UTC | 2011-02-17 15:28:32 UTC |
22
+ | 3 | Hello,World | 2011-02-17 15:28:40 UTC | 2011-02-17 15:28:40 UTC |
23
+ | 4 | 頭獎上看十八億 | 2011-02-17 15:29:02 UTC | 2011-02-17 15:29:02 UTC |
24
+ | 5 | 海角上看七億 | 2011-02-17 15:29:18 UTC | 2011-02-17 15:29:18 UTC |
25
+ | 6 | こんにちは | 2011-02-17 15:32:18 UTC | 2011-02-17 15:32:18 UTC |
26
+ +----+------------------+-------------------------+-------------------------+
27
+
28
+ P.S. If the table is not perfectly aligned in your browser, that's font problem. Checkout the project and type `cat README.md` in your console :)
29
+
30
+
31
+ ## Installation
32
+
33
+ gem install hirb-unicode
34
+
35
+ ## Usage
36
+
37
+ This will load `hirb` and `hirb-unicode`, and fix the unicode problem automtically:
38
+
39
+ gem 'hirb-unicode'
40
+ require 'hirb-unicode'
41
+
42
+ If you are using `bundler` (ex. Rails 3), add `hirb-unicode` into your gemfile:
43
+
44
+ gem 'hirb-unicode'
45
+
46
+ And run `require 'hirb-unicode'` in your irb console or `.irbrc`
47
+
48
+ ## Dependency
49
+
50
+ `hirb-unicode` uses `unicode-display_width` gem to calculate width of unicode characters.
51
+
52
+ ## Testing
53
+
54
+ * `rake test:hirb` loads `hirb` and `hirb-unicode`, run all test of original `hirb` gem. This ensures the original `hirb` functionality is not broken.
55
+ * `rake test:unicode` tests functions about unicode string processing.
56
+ * `rake test` run both two tests above.
57
+
58
+ ## License
59
+
60
+ Read MIT-LICENSE file for details.
5
61
 
data/hirb-unicode.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
- require "hirb-unicode/version"
3
+ require "hirb/unicode/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "hirb-unicode"
data/lib/hirb-unicode.rb CHANGED
@@ -1,31 +1 @@
1
- require 'hirb'
2
- require 'unicode/display_width'
3
-
4
- module Hirb
5
- module Unicode
6
- module StringUtility
7
- def size(string)
8
- string.display_width
9
- end
10
-
11
- def slice(string, offset, width)
12
- chars = string.chars.to_a[offset..-1].to_a
13
-
14
- current_length = 0
15
- split_index = 0
16
- chars.each_with_index do |c, i|
17
- char_width = self.size(c)
18
- break if current_length + char_width > width
19
- split_index = i+1
20
- current_length += char_width
21
- end
22
-
23
- split_index ||= chars.count
24
- head = chars[0, split_index].join
25
- head
26
- end
27
- end
28
- end
29
- end
30
-
31
- Hirb::String.extend(Hirb::Unicode::StringUtility)
1
+ require 'hirb/unicode'
@@ -0,0 +1,4 @@
1
+ require 'hirb'
2
+ require 'unicode/display_width'
3
+ require 'hirb/unicode/version'
4
+ require 'hirb/unicode/string_util'
@@ -0,0 +1,28 @@
1
+ module Hirb
2
+ module Unicode
3
+ module StringUtil
4
+ def size(string)
5
+ string.display_width
6
+ end
7
+
8
+ def slice(string, offset, width)
9
+ chars = string.chars.to_a[offset..-1].to_a
10
+
11
+ current_length = 0
12
+ split_index = 0
13
+ chars.each_with_index do |c, i|
14
+ char_width = self.size(c)
15
+ break if current_length + char_width > width
16
+ split_index = i+1
17
+ current_length += char_width
18
+ end
19
+
20
+ split_index ||= chars.count
21
+ head = chars[0, split_index].join
22
+ head
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ Hirb::String.extend(Hirb::Unicode::StringUtil)
@@ -1,5 +1,5 @@
1
1
  module Hirb
2
2
  module Unicode
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hirb-unicode
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - miaout17
@@ -15,13 +15,13 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-17 00:00:00 +08:00
18
+ date: 2011-02-21 00:00:00 +08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: hirb
23
22
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
23
+ type: :runtime
24
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
27
  - - ~>
@@ -32,12 +32,12 @@ dependencies:
32
32
  - 3
33
33
  - 6
34
34
  version: 0.3.6
35
- type: :runtime
36
- version_requirements: *id001
35
+ requirement: *id001
36
+ name: hirb
37
37
  - !ruby/object:Gem::Dependency
38
- name: unicode-display_width
39
38
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
39
+ type: :runtime
40
+ version_requirements: &id002 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ~>
@@ -48,12 +48,12 @@ dependencies:
48
48
  - 1
49
49
  - 1
50
50
  version: 0.1.1
51
- type: :runtime
52
- version_requirements: *id002
51
+ requirement: *id002
52
+ name: unicode-display_width
53
53
  - !ruby/object:Gem::Dependency
54
- name: bacon
55
54
  prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
55
+ type: :development
56
+ version_requirements: &id003 !ruby/object:Gem::Requirement
57
57
  none: false
58
58
  requirements:
59
59
  - - ">="
@@ -64,12 +64,12 @@ dependencies:
64
64
  - 1
65
65
  - 0
66
66
  version: 1.1.0
67
- type: :development
68
- version_requirements: *id003
67
+ requirement: *id003
68
+ name: bacon
69
69
  - !ruby/object:Gem::Dependency
70
- name: mocha
71
70
  prerelease: false
72
- requirement: &id004 !ruby/object:Gem::Requirement
71
+ type: :development
72
+ version_requirements: &id004 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ">="
@@ -78,12 +78,12 @@ dependencies:
78
78
  segments:
79
79
  - 0
80
80
  version: "0"
81
- type: :development
82
- version_requirements: *id004
81
+ requirement: *id004
82
+ name: mocha
83
83
  - !ruby/object:Gem::Dependency
84
- name: mocha-on-bacon
85
84
  prerelease: false
86
- requirement: &id005 !ruby/object:Gem::Requirement
85
+ type: :development
86
+ version_requirements: &id005 !ruby/object:Gem::Requirement
87
87
  none: false
88
88
  requirements:
89
89
  - - ">="
@@ -92,12 +92,12 @@ dependencies:
92
92
  segments:
93
93
  - 0
94
94
  version: "0"
95
- type: :development
96
- version_requirements: *id005
95
+ requirement: *id005
96
+ name: mocha-on-bacon
97
97
  - !ruby/object:Gem::Dependency
98
- name: bacon-bits
99
98
  prerelease: false
100
- requirement: &id006 !ruby/object:Gem::Requirement
99
+ type: :development
100
+ version_requirements: &id006 !ruby/object:Gem::Requirement
101
101
  none: false
102
102
  requirements:
103
103
  - - ">="
@@ -106,8 +106,8 @@ dependencies:
106
106
  segments:
107
107
  - 0
108
108
  version: "0"
109
- type: :development
110
- version_requirements: *id006
109
+ requirement: *id006
110
+ name: bacon-bits
111
111
  description: Unicode support for hirb
112
112
  email:
113
113
  - miaout17 at gmail dot com
@@ -120,11 +120,14 @@ extra_rdoc_files: []
120
120
  files:
121
121
  - .gitignore
122
122
  - Gemfile
123
+ - MIT-LICENSE
123
124
  - README.md
124
125
  - Rakefile
125
126
  - hirb-unicode.gemspec
126
127
  - lib/hirb-unicode.rb
127
- - lib/hirb-unicode/version.rb
128
+ - lib/hirb/unicode.rb
129
+ - lib/hirb/unicode/string_util.rb
130
+ - lib/hirb/unicode/version.rb
128
131
  - test/string_test.rb
129
132
  - test/test_helper.rb
130
133
  has_rdoc: true
@@ -161,6 +164,5 @@ rubygems_version: 1.3.7
161
164
  signing_key:
162
165
  specification_version: 3
163
166
  summary: Unicode support for hirb
164
- test_files:
165
- - test/string_test.rb
166
- - test/test_helper.rb
167
+ test_files: []
168
+