wizport 0.1.1 → 0.1.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.
@@ -6,11 +6,12 @@
|
|
6
6
|
module Wizport
|
7
7
|
module Rtf
|
8
8
|
class Table < Element
|
9
|
+
DEFAULT_COLUMN_WIDTH = 40
|
9
10
|
|
10
11
|
def initialize(rtf, rows = [], options = {}, &block)
|
11
12
|
super(rtf)
|
12
13
|
@row_spans = {}
|
13
|
-
@column_widths = options[:column_widths] ||
|
14
|
+
@column_widths = options[:column_widths] || DEFAULT_COLUMN_WIDTH
|
14
15
|
rows.each_index do |index|
|
15
16
|
add_row rows[index]
|
16
17
|
end
|
@@ -24,15 +25,12 @@ module Wizport
|
|
24
25
|
@col_offset = 1
|
25
26
|
@right_width = 0
|
26
27
|
cells.each do |cell|
|
27
|
-
|
28
28
|
add_cell cell
|
29
|
-
|
30
29
|
end
|
31
30
|
cmd :row
|
32
31
|
end
|
33
32
|
|
34
33
|
def add_cell(cell,merge = false)
|
35
|
-
p row_spanned?(@col_offset)
|
36
34
|
add_cell "",true if !merge && row_spanned?(@col_offset)
|
37
35
|
if cell.is_a?(Hash)
|
38
36
|
rowspan = cell[:rowspan]
|
@@ -43,23 +41,22 @@ module Wizport
|
|
43
41
|
colspan = colspan || 1
|
44
42
|
rowspan = rowspan || 1
|
45
43
|
content = content || cell
|
46
|
-
|
47
|
-
cmd :celld
|
44
|
+
|
48
45
|
if rowspan > 1
|
49
|
-
|
46
|
+
v_merge = :gf
|
50
47
|
elsif row_spanned? @col_offset
|
51
|
-
|
48
|
+
v_merge = :rg
|
52
49
|
@row_spans[@col_offset][:rowspan] -= 1
|
53
|
-
#if @row_spans[@col_offset][:rowspan] < 2
|
54
|
-
# @row_spans[@col_offset].delete(:rowspan)
|
55
|
-
#end
|
56
50
|
colspan = @row_spans[@col_offset][:colspan] || colspan
|
57
51
|
end
|
58
|
-
p @row_spans
|
59
52
|
colspan.times do
|
60
53
|
@right_width += column_width(@col_offset)
|
61
54
|
@col_offset += 1
|
62
55
|
end
|
56
|
+
|
57
|
+
cmd :celld
|
58
|
+
cmd :clvmgf if v_merge == :gf
|
59
|
+
cmd :clvmrg if v_merge == :rg
|
63
60
|
cmd :cellx, @right_width
|
64
61
|
txt content
|
65
62
|
cmd :cell
|
@@ -71,13 +68,9 @@ module Wizport
|
|
71
68
|
@row_spans[offset] && @row_spans[offset][:rowspan].to_i > 1
|
72
69
|
end
|
73
70
|
|
74
|
-
def row_spans_with_colspan
|
75
|
-
return @row_spans[@col_offset][:colspan] || 1
|
76
|
-
end
|
77
|
-
|
78
71
|
def column_width(offset)
|
79
|
-
return @column_widths[offset] ||
|
80
|
-
@column_widths
|
72
|
+
return 20 * (@column_widths[offset] || DEFAULT_COLUMN_WIDTH) if @column_widths.is_a?(Hash)
|
73
|
+
@column_widths * 20
|
81
74
|
end
|
82
75
|
|
83
76
|
end
|
@@ -6,15 +6,16 @@
|
|
6
6
|
module Wizport
|
7
7
|
module Rtf
|
8
8
|
class Text < Element
|
9
|
-
ALIGN_MAP = {left:'ql',center:'qc'}
|
9
|
+
ALIGN_MAP = {left:'ql',center:'qc',right:'qr'}
|
10
|
+
FONT_MAP = {'font-size' => :fs}
|
10
11
|
|
11
12
|
def initialize(rtf, str = '', styles = {})
|
12
13
|
super(rtf)
|
13
|
-
styles = {:align => :left
|
14
|
+
styles = {:align => :left,'font-size' => 24}.merge(styles)
|
14
15
|
group do
|
15
|
-
cmd :
|
16
|
+
cmd :pard
|
16
17
|
cmd ALIGN_MAP[styles[:align]]
|
17
|
-
cmd
|
18
|
+
cmd FONT_MAP[styles['font-size']]
|
18
19
|
txt str
|
19
20
|
cmd :par
|
20
21
|
end
|
@@ -6,8 +6,10 @@
|
|
6
6
|
module Wizport
|
7
7
|
module Html
|
8
8
|
class Table < Element
|
9
|
+
DEFAULT_COLUMN_WIDTH = 40
|
9
10
|
def initialize(html, rows = [], options = {}, &block)
|
10
11
|
super html
|
12
|
+
@column_widths = options[:column_widths]
|
11
13
|
#{style:'border:1px solid red;'}
|
12
14
|
tag 'table' do
|
13
15
|
tag 'tbody' do
|
data/lib/wizport/version.rb
CHANGED
@@ -6,21 +6,23 @@ describe Wizport::Rtf::Document do
|
|
6
6
|
|
7
7
|
it "a simple example of Rtf" do
|
8
8
|
rtf = Wizport::Rtf::Document.new do
|
9
|
-
text "学生综合素质评价"
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
text "学生综合素质评价", :align => :center, 'font-size' => 48
|
10
|
+
page_break
|
11
|
+
text "ss"
|
12
|
+
table [[{content:'e',rowspan:4},{content:'4',rowspan:4},1,{content:'1',colspan:2}],
|
13
|
+
[{content:'4',rowspan:3,colspan:2},8],
|
14
|
+
[11]],column_widths:{1=>100,2 => 100,3 => 50,4 => 50,5 => 50} do
|
15
|
+
add_row [1]
|
16
|
+
end
|
15
17
|
|
16
18
|
#table [["姓名", "person.name", "性别", {content: "{Core::Person::GENDER_TYPE[person.gender]}", colspan: 3}, "出生日期", {content: "nil}", colspan: 2}, {content: "一寸照片", colspan: 2, rowspan: 3}],
|
17
19
|
# ["民族", {content: "{Core}", colspan: 2}, "入队(团)时间", {content: '', colspan: 5}],
|
18
20
|
# ["家庭住址", {content: "person", colspan: 8}]]
|
19
21
|
|
20
22
|
|
21
|
-
table [["入学身高", "", "体重", "", "视力", "左", "", "右", "", "血型", ""],
|
22
|
-
|
23
|
-
|
23
|
+
#table [["入学身高", "", "体重", "", "视力", "左", "", "右", "", "血型", ""],
|
24
|
+
# [{content:"简历", rowspan: 3}, {content:"日期", colspan: 2}, {content: "升(入)学前所在学校", colspan: 6}, {content: "担任何职务", colspan: 2}],
|
25
|
+
# [{content:"", colspan: 2}, {content:"", colspan: 6}, {content:"", colspan: 2}]]
|
24
26
|
end
|
25
27
|
|
26
28
|
rtf.save('c:/r.rtf')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wizport
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-07-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|