docx-cloner 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.gitignore +68 -0
- data/.rspec +2 -0
- data/Gemfile +4 -1
- data/docx-examples/read-single-tags-body.xml +1383 -0
- data/docx-examples/read-single-tags.docx +0 -0
- data/docx-examples/source.docx +0 -0
- data/docx-examples/wp.xml +52 -0
- data/features/read.feature +46 -0
- data/features/replace.feature +64 -0
- data/features/steps_define/steps.rb +92 -0
- data/lib/docx/cloner.rb +251 -1
- data/lib/docx/cloner/version.rb +1 -1
- data/spec/cloner_spec.rb +101 -0
- data/spec/spec_helper.rb +3 -0
- metadata +18 -3
data/lib/docx/cloner/version.rb
CHANGED
data/spec/cloner_spec.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
module Docx
|
5
|
+
module Cloner
|
6
|
+
describe DocxTool do
|
7
|
+
context "以下适用于读单个标签" do
|
8
|
+
before :all do
|
9
|
+
@docx = DocxTool.new 'docx-examples/read-single-tags.docx'
|
10
|
+
end
|
11
|
+
context "#include_single_tag?" do
|
12
|
+
it "读取'$名字$'标签" do
|
13
|
+
result = @docx.include_single_tag? "$名字$"
|
14
|
+
result.should be_true
|
15
|
+
end
|
16
|
+
it "读取'{Name}'标签" do
|
17
|
+
result = @docx.include_single_tag? "{Name}"
|
18
|
+
result.should be_true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "#read_single_tags_xml" do
|
23
|
+
it "读取'{name}'的xml标签'<w:r>',应该是" do
|
24
|
+
result = @docx.read_single_tag_xml "{name}"
|
25
|
+
result.should == <<-HERE
|
26
|
+
<w:r w:rsidR="000F595B">
|
27
|
+
<w:rPr>
|
28
|
+
<w:rFonts w:hint="eastAsia"/>
|
29
|
+
<w:lang w:eastAsia="zh-CN"/>
|
30
|
+
</w:rPr>
|
31
|
+
<w:t>{</w:t>
|
32
|
+
</w:r>
|
33
|
+
<w:r>
|
34
|
+
<w:rPr>
|
35
|
+
<w:rFonts w:hint="eastAsia"/>
|
36
|
+
<w:lang w:eastAsia="zh-CN"/>
|
37
|
+
</w:rPr>
|
38
|
+
<w:t>n</w:t>
|
39
|
+
</w:r>
|
40
|
+
<w:r w:rsidR="000F595B">
|
41
|
+
<w:rPr>
|
42
|
+
<w:rFonts w:hint="eastAsia"/>
|
43
|
+
<w:lang w:eastAsia="zh-CN"/>
|
44
|
+
</w:rPr>
|
45
|
+
<w:t>ame}</w:t>
|
46
|
+
</w:r>
|
47
|
+
HERE
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
after :all do
|
52
|
+
@docx.release
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "以下测试是针对标签替换,即写操作" do
|
57
|
+
before :all do
|
58
|
+
@sourc_file = 'docx-examples/source.docx'
|
59
|
+
@dest_file = 'docx-examples/dest.docx'
|
60
|
+
File.delete @dest_file if File.exist?(@dest_file)
|
61
|
+
|
62
|
+
@source_docx = DocxTool.new @sourc_file
|
63
|
+
end
|
64
|
+
|
65
|
+
context "#set_single_tag" do
|
66
|
+
it "设置单个标签{Name}" do
|
67
|
+
value = '周大福'
|
68
|
+
@source_docx.set_single_tag '{Name}', value
|
69
|
+
@source_docx.save @dest_file
|
70
|
+
|
71
|
+
dest = DocxTool.new @dest_file
|
72
|
+
result = dest.include_single_tag? value
|
73
|
+
dest.release
|
74
|
+
result.should be_true
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context "#set_row_tags" do
|
79
|
+
it "找到标签所在行的父节点" do
|
80
|
+
tags = ["{名称1}", "{00.01}"]
|
81
|
+
tags.each do |tag|
|
82
|
+
node = @source_docx.get_tag_scope tag, 'tr'
|
83
|
+
node.node_name.should == 'tr'
|
84
|
+
end
|
85
|
+
end
|
86
|
+
it "设置表格中的行标签", wip: true do
|
87
|
+
data = [["{名称1}", "{00.01}"], ["自行车1", "125.00"], ["大卡车1", "256500.00"], ["自行车2", "125.00"], ["大卡车2", "256500.00"],]
|
88
|
+
result = @source_docx.set_row_tags data.first, data[1..-1], 'tr'
|
89
|
+
@source_docx.save @dest_file
|
90
|
+
result.should be_true
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
after :all do
|
95
|
+
@source_docx.release
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: docx-cloner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- homeway
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -46,13 +46,23 @@ extensions: []
|
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
48
|
- .gitignore
|
49
|
+
- .rspec
|
49
50
|
- Gemfile
|
50
51
|
- LICENSE.txt
|
51
52
|
- README.md
|
52
53
|
- Rakefile
|
53
54
|
- docx-cloner.gemspec
|
55
|
+
- docx-examples/read-single-tags-body.xml
|
56
|
+
- docx-examples/read-single-tags.docx
|
57
|
+
- docx-examples/source.docx
|
58
|
+
- docx-examples/wp.xml
|
59
|
+
- features/read.feature
|
60
|
+
- features/replace.feature
|
61
|
+
- features/steps_define/steps.rb
|
54
62
|
- lib/docx/cloner.rb
|
55
63
|
- lib/docx/cloner/version.rb
|
64
|
+
- spec/cloner_spec.rb
|
65
|
+
- spec/spec_helper.rb
|
56
66
|
homepage: ''
|
57
67
|
licenses:
|
58
68
|
- MIT
|
@@ -77,4 +87,9 @@ rubygems_version: 2.0.6
|
|
77
87
|
signing_key:
|
78
88
|
specification_version: 4
|
79
89
|
summary: generate docx file with tags
|
80
|
-
test_files:
|
90
|
+
test_files:
|
91
|
+
- features/read.feature
|
92
|
+
- features/replace.feature
|
93
|
+
- features/steps_define/steps.rb
|
94
|
+
- spec/cloner_spec.rb
|
95
|
+
- spec/spec_helper.rb
|