rtf 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +3 -0
- data/VERSION.yml +3 -3
- data/examples/example01.rb +5 -1
- data/examples/example02.rb +1 -0
- data/examples/example03.rb +1 -0
- data/examples/example04.rb +1 -0
- data/lib/rtf/node.rb +21 -6
- data/test/test_helper.rb +1 -0
- data/test/text_node_test.rb +25 -9
- metadata +22 -53
data/CHANGES
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
== CHANGES
|
2
2
|
|
3
|
+
0.3.2
|
4
|
+
* Added support for utf-8 thanks to clbustos
|
5
|
+
|
3
6
|
0.3.0
|
4
7
|
* Resolve problems on Ruby 1.9.1 with ImageNode#read_source. Peter uses IO#getc, which returns a String on Ruby 1.9.1, not a Integer, so I replaced with getbyte. [clbustos]
|
5
8
|
* Deleted duplicated definition of ImageNode#style= with attr_writer and def. [clbustos]
|
data/VERSION.yml
CHANGED
data/examples/example01.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
#!/usr/bin/env ruby
|
2
3
|
|
4
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__)+"/../lib/")
|
5
|
+
|
6
|
+
|
3
7
|
require 'rubygems'
|
4
8
|
require 'rtf'
|
5
9
|
|
@@ -48,4 +52,4 @@ end
|
|
48
52
|
|
49
53
|
File.open('example01.rtf', 'w') do |file|
|
50
54
|
file.write(document.to_rtf)
|
51
|
-
end
|
55
|
+
end
|
data/examples/example02.rb
CHANGED
data/examples/example03.rb
CHANGED
data/examples/example04.rb
CHANGED
data/lib/rtf/node.rb
CHANGED
@@ -118,7 +118,22 @@ module RTF
|
|
118
118
|
# This method generates the RTF equivalent for a TextNode object. This
|
119
119
|
# method escapes any special sequences that appear in the text.
|
120
120
|
def to_rtf
|
121
|
-
|
121
|
+
rtf=(@text == nil ? '' : @text.gsub("{", "\\{").gsub("}", "\\}").gsub("\\", "\\\\"))
|
122
|
+
# This is from lfarcy / rtf-extensions
|
123
|
+
# I don't see the point of coding different 128<n<256 range
|
124
|
+
|
125
|
+
#f1=lambda { |n| n < 128 ? n.chr : n < 256 ? "\\'#{n.to_s(16)}" : "\\u#{n}\\'3f" }
|
126
|
+
# Encode as Unicode.
|
127
|
+
|
128
|
+
f=lambda { |n| n < 128 ? n.chr : "\\u#{n}\\'3f" }
|
129
|
+
# Ruby 1.9 is safe, cause detect original encoding
|
130
|
+
# and convert text to utf-16 first
|
131
|
+
if RUBY_VERSION>"1.9.0"
|
132
|
+
return rtf.encode("UTF-16LE", :undef=>:replace).each_codepoint.map(&f).join('')
|
133
|
+
else
|
134
|
+
# You SHOULD use UTF-8 as input, ok?
|
135
|
+
return rtf.unpack('U*').map(&f).join('')
|
136
|
+
end
|
122
137
|
end
|
123
138
|
end # End of the TextNode class.
|
124
139
|
|
@@ -521,7 +536,7 @@ module RTF
|
|
521
536
|
class TableNode < ContainerNode
|
522
537
|
# Cell margin. Default to 100
|
523
538
|
attr_accessor :cell_margin
|
524
|
-
|
539
|
+
|
525
540
|
# This is a constructor for the TableNode class.
|
526
541
|
#
|
527
542
|
# ==== Parameters
|
@@ -540,7 +555,7 @@ module RTF
|
|
540
555
|
rows.times {entries.push(TableRowNode.new(self, columns, *widths))}
|
541
556
|
entries
|
542
557
|
end
|
543
|
-
|
558
|
+
|
544
559
|
elsif block
|
545
560
|
block.arity<1 ? self.instance_eval(&block) : block.call(self)
|
546
561
|
else
|
@@ -753,7 +768,7 @@ module RTF
|
|
753
768
|
attr_accessor :width
|
754
769
|
# Attribute accessor.
|
755
770
|
attr_reader :shading_colour, :style
|
756
|
-
|
771
|
+
|
757
772
|
# This is the constructor for the TableCellNode class.
|
758
773
|
#
|
759
774
|
# ==== Parameters
|
@@ -1262,7 +1277,7 @@ module RTF
|
|
1262
1277
|
if size > 0
|
1263
1278
|
total = 0
|
1264
1279
|
while @source.eof? == false && total < size
|
1265
|
-
|
1280
|
+
|
1266
1281
|
@read << @source.getbyte
|
1267
1282
|
total += 1
|
1268
1283
|
end
|
@@ -1660,4 +1675,4 @@ module RTF
|
|
1660
1675
|
text.string
|
1661
1676
|
end
|
1662
1677
|
end # End of the Document class.
|
1663
|
-
end # End of the RTF module.
|
1678
|
+
end # End of the RTF module.
|
data/test/test_helper.rb
CHANGED
data/test/text_node_test.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding:UTF-8
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
# Information class unit test class.
|
@@ -5,7 +6,7 @@ class TextNodeTest < Test::Unit::TestCase
|
|
5
6
|
def setup
|
6
7
|
@node = Node.new(nil)
|
7
8
|
end
|
8
|
-
|
9
|
+
|
9
10
|
def test01
|
10
11
|
nodes = []
|
11
12
|
nodes.push(TextNode.new(@node))
|
@@ -13,25 +14,25 @@ class TextNodeTest < Test::Unit::TestCase
|
|
13
14
|
nodes.push(TextNode.new(@node))
|
14
15
|
nodes.push(TextNode.new(@node, ''))
|
15
16
|
|
16
|
-
assert(nodes[0].text == nil)
|
17
|
-
assert(nodes[1].text == 'Node 2')
|
18
|
-
assert(nodes[2].text == nil)
|
17
|
+
assert(nodes[0].text == nil)
|
18
|
+
assert(nodes[1].text == 'Node 2')
|
19
|
+
assert(nodes[2].text == nil)
|
19
20
|
assert(nodes[3].text == '')
|
20
|
-
|
21
|
+
|
21
22
|
nodes[0].text = 'This is the altered text for node 1.'
|
22
23
|
assert(nodes[0].text == 'This is the altered text for node 1.')
|
23
|
-
|
24
|
+
|
24
25
|
nodes[1].append('La la la')
|
25
26
|
nodes[2].append('La la la')
|
26
27
|
assert(nodes[1].text == 'Node 2La la la')
|
27
28
|
assert(nodes[2].text == 'La la la')
|
28
|
-
|
29
|
+
|
29
30
|
nodes[2].text = nil
|
30
31
|
nodes[1].insert(' - ', 6)
|
31
32
|
nodes[2].insert('TEXT', 2)
|
32
33
|
assert(nodes[1].text == 'Node 2 - La la la')
|
33
34
|
assert(nodes[2].text == 'TEXT')
|
34
|
-
|
35
|
+
|
35
36
|
nodes[2].text = nil
|
36
37
|
nodes[3].text = '{\}'
|
37
38
|
assert(nodes[0].to_rtf == 'This is the altered text for node 1.')
|
@@ -39,7 +40,7 @@ class TextNodeTest < Test::Unit::TestCase
|
|
39
40
|
assert(nodes[2].to_rtf == '')
|
40
41
|
assert(nodes[3].to_rtf == '\{\\\}')
|
41
42
|
end
|
42
|
-
|
43
|
+
|
43
44
|
def test02
|
44
45
|
begin
|
45
46
|
TextNode.new(nil)
|
@@ -47,4 +48,19 @@ class TextNodeTest < Test::Unit::TestCase
|
|
47
48
|
rescue => error
|
48
49
|
end
|
49
50
|
end
|
51
|
+
def test_utf8
|
52
|
+
nodes = []
|
53
|
+
nodes.push(TextNode.new(@node))
|
54
|
+
nodes.push(TextNode.new(@node))
|
55
|
+
|
56
|
+
nodes[0].text="ASCCI"
|
57
|
+
assert_equal("ASCCI", nodes[0].to_rtf)
|
58
|
+
|
59
|
+
|
60
|
+
utf8="Á"
|
61
|
+
exp="\\u#{utf8.unpack("U")[0]}\\'3f"
|
62
|
+
nodes[0].text=utf8
|
63
|
+
assert_equal(exp, nodes[0].to_rtf)
|
64
|
+
|
65
|
+
end
|
50
66
|
end
|
metadata
CHANGED
@@ -1,29 +1,26 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rtf
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.2
|
4
5
|
prerelease:
|
5
|
-
version: 0.3.0
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Peter Wood
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
date: 2011-04-15 00:00:00 +01:00
|
12
|
+
date: 2011-09-07 00:00:00.000000000 +01:00
|
14
13
|
default_executable:
|
15
14
|
dependencies: []
|
16
|
-
|
17
|
-
|
15
|
+
description: Ruby RTF is a library that can be used to create rich text format (RTF)
|
16
|
+
documents. RTF is a text based standard for laying out document content.
|
18
17
|
email: paw220470@yahoo.ie
|
19
18
|
executables: []
|
20
|
-
|
21
19
|
extensions: []
|
22
|
-
|
23
|
-
extra_rdoc_files:
|
20
|
+
extra_rdoc_files:
|
24
21
|
- LICENSE
|
25
22
|
- README.rdoc
|
26
|
-
files:
|
23
|
+
files:
|
27
24
|
- CHANGES
|
28
25
|
- LICENSE
|
29
26
|
- README.rdoc
|
@@ -74,54 +71,26 @@ files:
|
|
74
71
|
has_rdoc: true
|
75
72
|
homepage: http://github.com/thechrisoshow/rtf
|
76
73
|
licenses: []
|
77
|
-
|
78
74
|
post_install_message:
|
79
75
|
rdoc_options: []
|
80
|
-
|
81
|
-
require_paths:
|
76
|
+
require_paths:
|
82
77
|
- lib
|
83
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
79
|
none: false
|
85
|
-
requirements:
|
86
|
-
- -
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
version:
|
89
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
85
|
none: false
|
91
|
-
requirements:
|
92
|
-
- -
|
93
|
-
- !ruby/object:Gem::Version
|
94
|
-
version:
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
95
90
|
requirements: []
|
96
|
-
|
97
91
|
rubyforge_project:
|
98
|
-
rubygems_version: 1.
|
92
|
+
rubygems_version: 1.6.2
|
99
93
|
signing_key:
|
100
94
|
specification_version: 3
|
101
95
|
summary: Ruby library to create rich text format documents.
|
102
|
-
test_files:
|
103
|
-
- examples/example01.rb
|
104
|
-
- examples/example02.rb
|
105
|
-
- examples/example03.rb
|
106
|
-
- examples/example04.rb
|
107
|
-
- test/character_style_test.rb
|
108
|
-
- test/colour_table_test.rb
|
109
|
-
- test/colour_test.rb
|
110
|
-
- test/command_node_test.rb
|
111
|
-
- test/container_node_test.rb
|
112
|
-
- test/document_style_test.rb
|
113
|
-
- test/document_test.rb
|
114
|
-
- test/font_table_test.rb
|
115
|
-
- test/font_test.rb
|
116
|
-
- test/footer_node_test.rb
|
117
|
-
- test/header_node_test.rb
|
118
|
-
- test/image_node_test.rb
|
119
|
-
- test/information_test.rb
|
120
|
-
- test/node_test.rb
|
121
|
-
- test/paragraph_style_test.rb
|
122
|
-
- test/style_test.rb
|
123
|
-
- test/table_cell_node_test.rb
|
124
|
-
- test/table_node_test.rb
|
125
|
-
- test/table_row_node_test.rb
|
126
|
-
- test/test_helper.rb
|
127
|
-
- test/text_node_test.rb
|
96
|
+
test_files: []
|