rubyword 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -2
- data/CHANGELOG.md +44 -0
- data/README.cn.md +167 -0
- data/README.md +24 -3
- data/bin/run-example +11 -0
- data/doc/README.md +18 -1
- data/doc/doc-information.md +16 -0
- data/doc/footer.md +19 -0
- data/doc/header.md +11 -0
- data/doc/image.md +10 -0
- data/doc/link.md +10 -0
- data/doc/list.md +17 -0
- data/doc/paragraph.md +27 -0
- data/doc/table.md +21 -0
- data/doc/text.md +26 -1
- data/doc/title.md +14 -0
- data/doc/toc.md +11 -0
- data/example/doc_information.rb +13 -0
- data/example/footer.rb +5 -0
- data/example/header.rb +5 -0
- data/example/image.rb +7 -0
- data/example/link.rb +7 -0
- data/example/list.rb +11 -0
- data/example/paragraph.rb +17 -0
- data/example/result/.keep +0 -0
- data/example/result/doc-information.docx +0 -0
- data/example/result/footer.docx +0 -0
- data/example/result/header.docx +0 -0
- data/example/result/image.docx +0 -0
- data/example/result/link.docx +0 -0
- data/example/result/list.docx +0 -0
- data/example/result/paragraph.docx +0 -0
- data/example/result/table.docx +0 -0
- data/example/result/test.docx +0 -0
- data/example/result/text.docx +0 -0
- data/example/table.rb +18 -0
- data/example/test.rb +117 -0
- data/example/text.rb +9 -0
- data/example/toc.rb +24 -0
- data/lib/rubyword.rb +1 -0
- data/lib/rubyword/configuration.rb +1 -1
- data/lib/rubyword/document.rb +29 -41
- data/lib/rubyword/element/base.rb +12 -0
- data/lib/rubyword/element/link.rb +6 -5
- data/lib/rubyword/element/list.rb +4 -2
- data/lib/rubyword/element/paragraph.rb +38 -0
- data/lib/rubyword/element/section.rb +23 -10
- data/lib/rubyword/element/table.rb +60 -0
- data/lib/rubyword/element/text.rb +14 -79
- data/lib/rubyword/style.rb +4 -0
- data/lib/rubyword/version.rb +1 -1
- data/lib/rubyword/writer.rb +0 -4
- data/lib/rubyword/writer/part/document.rb +51 -44
- data/lib/rubyword/writer/part/footer.rb +1 -6
- data/lib/rubyword/writer/part/header.rb +2 -6
- data/lib/rubyword/writer/style/base.rb +0 -1
- data/lib/rubyword/writer/style/paragraph.rb +47 -0
- data/lib/rubyword/writer/style/section.rb +0 -1
- data/lib/rubyword/writer/style/word.rb +40 -0
- data/rubyword.gemspec +1 -2
- data/spec/rubyword/document_spec.rb +18 -3
- data/spec/rubyword/element/page_break_spec.rb +55 -0
- data/spec/rubyword/element/text_break_spec.rb +46 -0
- data/spec/rubyword/element/text_spec.rb +50 -0
- data/spec/spec_helper.rb +3 -30
- metadata +50 -20
- data/CHANGELOG.txt +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4211931a53c84371b34bd29570a365bb1c9606bd
|
4
|
+
data.tar.gz: bbfecc910bb93c23ddd4e8403c24820da0cd1689
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d86f0449340b3274d3cc4844fb58b5205d0d55297a0fd62ecc6efe588c4ac8f5c3e7d9e1a67d3c736b4ec15851ab147e91106836f24ea3e63151fb3e185f79f
|
7
|
+
data.tar.gz: 63b6215169ff3ba6012189728d188ea1bbdd1552b48b479f4db467dab3d7fb3ce0b7f0e304b52167cf7fdb8e7310618b2e45850bd5203f82b351a4b063665f15
|
data/.gitignore
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# CHANGELOG
|
2
|
+
|
3
|
+
# Version 1.1.0 - 2017-11-02
|
4
|
+
+ add paragraph feature
|
5
|
+
+ add table feature
|
6
|
+
```
|
7
|
+
section {
|
8
|
+
text 'hello'
|
9
|
+
p(text_align: 'center') {
|
10
|
+
text 'i am '
|
11
|
+
text 'a boy'
|
12
|
+
}
|
13
|
+
text 'welcome to my home..'
|
14
|
+
|
15
|
+
p {
|
16
|
+
text 'This is a '
|
17
|
+
text 'apple, yellow apple', bgcolor: 'yellow', text_align: 'center'
|
18
|
+
}
|
19
|
+
|
20
|
+
table {
|
21
|
+
tr {
|
22
|
+
th 'id'
|
23
|
+
th 'name'
|
24
|
+
th 'age'
|
25
|
+
}
|
26
|
+
tr {
|
27
|
+
th '1'
|
28
|
+
th 'young'
|
29
|
+
th '66'
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
```
|
34
|
+
|
35
|
+
# Version 1.0.0 - 2017-10-21
|
36
|
+
|
37
|
+
+ Support for setting the properties of the document, such as: title, subject, author and other information
|
38
|
+
+ Support for generated TOC for the title
|
39
|
+
+ Support for setting header and footer
|
40
|
+
+ Support for insert title which is different attributes, such as: title, sub title, etc.
|
41
|
+
+ Support for insert blank lines and blank page
|
42
|
+
+ Support for insert multiple images
|
43
|
+
+ Support for insert multiple lists
|
44
|
+
+ Support for insert hyperlink
|
data/README.cn.md
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
# RubyWord: Microsoft Word Generation For Ruby
|
2
|
+
> RubyWord 是一个便捷的 word 文档生成工具
|
3
|
+
|
4
|
+
# 语言
|
5
|
+
* [English](README.md)
|
6
|
+
* [简体中文](README.cn.md)
|
7
|
+
|
8
|
+
# 更新日志
|
9
|
+
[ChANGELOG](CHANGELOG.md)
|
10
|
+
|
11
|
+
# 使用前请先阅读
|
12
|
+
这个项目正在开发中,因为只有我自己在开发,所以进度可能会比较缓慢以及可能会存在很多未知的问题。这方面请多谅解,同时也希望各位有兴趣的朋友也加入到开发来,欢迎多提宝贵意见或者直接提PR也是非常欢迎的,感谢支持。
|
13
|
+
|
14
|
+
# 安装
|
15
|
+
```
|
16
|
+
gem install rubyword
|
17
|
+
```
|
18
|
+
或者将下面这句代码写入到Gemfile
|
19
|
+
```
|
20
|
+
gem 'rubyword'
|
21
|
+
```
|
22
|
+
# 特性
|
23
|
+
+ 支持设置文档的属性,比如: 标题,副标题,作者以及等等
|
24
|
+
+ 支持插入段落
|
25
|
+
+ 支持根据一级标题,二级标题,多级标题自动生成目录结构
|
26
|
+
+ 支持设置页头和页尾
|
27
|
+
+ 支持插入多级标题
|
28
|
+
+ 支持插入空行符以及空白页
|
29
|
+
+ 支持插入图片
|
30
|
+
+ 支持插入列表
|
31
|
+
+ 支持插入超链接
|
32
|
+
+ 支持插入表格
|
33
|
+
+ 更多功能,敬请期待..
|
34
|
+
|
35
|
+
# 用法说明
|
36
|
+
```
|
37
|
+
require "rubyword"
|
38
|
+
Rubyword::Document::generate('hello.docx') {
|
39
|
+
# word 文档的属性
|
40
|
+
information({
|
41
|
+
company: 'ruby word',
|
42
|
+
creator: 'young',
|
43
|
+
title: 'example word file',
|
44
|
+
description: 'this is a example docx',
|
45
|
+
subject: 'how to create doc info',
|
46
|
+
keywords: 'remark',
|
47
|
+
category: 'category'
|
48
|
+
})
|
49
|
+
|
50
|
+
section {
|
51
|
+
text '普通段落1'
|
52
|
+
p(text_align: 'center') {
|
53
|
+
text '连续的文本1'
|
54
|
+
text '连续的文本'
|
55
|
+
}
|
56
|
+
text '普通段落2'
|
57
|
+
|
58
|
+
p {
|
59
|
+
text '不居中的文本 '
|
60
|
+
text '黄色的文本', bgcolor: 'yellow', text_align: 'center'
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
# 根据标题生成目录
|
65
|
+
title_directory font_size: 24
|
66
|
+
|
67
|
+
# 插入页头
|
68
|
+
add_header 'rubyword'
|
69
|
+
|
70
|
+
# 插入页尾,并以数字作为页码
|
71
|
+
add_footer nil, text_align: 'center', nums_type: 'number'
|
72
|
+
# 插入页尾,使用字符作为页码
|
73
|
+
# add_footer 'hello', text_align: 'center'
|
74
|
+
|
75
|
+
section {
|
76
|
+
# 二级标题
|
77
|
+
title_2 "It's a subtitle"
|
78
|
+
# 一级标题
|
79
|
+
title_1 'Database'
|
80
|
+
# 二级标题
|
81
|
+
title_2 'MySQL'
|
82
|
+
# 三级标题
|
83
|
+
title_3 'NoSQL'
|
84
|
+
# 一级标题,并且不把它列入目录生成的范围
|
85
|
+
title_1 "It's a title", ignore_dir: true
|
86
|
+
# 空白行
|
87
|
+
text_break 3
|
88
|
+
# 插入文本并指定样式
|
89
|
+
text 'hello word', bgcolor: 'yellow', text_align: 'center'
|
90
|
+
# 空白页
|
91
|
+
page_break 2
|
92
|
+
# 插入文本
|
93
|
+
text 'hello word', indent_between: '1440-1440'
|
94
|
+
text 'title', { font_size: 62, color: '996699', blod: true, text_align: 'center' }
|
95
|
+
|
96
|
+
# 插入标题
|
97
|
+
title_1 'section2 title'
|
98
|
+
title_2 'section2 title'
|
99
|
+
title_3 'section2 title'
|
100
|
+
|
101
|
+
# 插入链接
|
102
|
+
link 'baidu', 'http://www.baidu.com', text_align: 'center'
|
103
|
+
}
|
104
|
+
|
105
|
+
section {
|
106
|
+
# 插入文本
|
107
|
+
text 'another Section', bgcolor: 'yellow', text_align: 'center'
|
108
|
+
|
109
|
+
# 插入文本
|
110
|
+
text 'hello word', indent_between: '1440-1440'
|
111
|
+
text 'title', { font_size: 62, color: '996699', blod: true, text_align: 'center' }
|
112
|
+
}
|
113
|
+
|
114
|
+
# 插入列表
|
115
|
+
section {
|
116
|
+
list 'test1', 1
|
117
|
+
list 'test1', 2
|
118
|
+
list 'test3', 2
|
119
|
+
list 'test2', 1
|
120
|
+
list 'test2', 1
|
121
|
+
}
|
122
|
+
|
123
|
+
section {
|
124
|
+
# 插入链接
|
125
|
+
link 'baidu', 'http://www.baidu.com', text_align: 'center'
|
126
|
+
# 插入图片
|
127
|
+
image 'http://www.baidu.com/img/bd_logo1.png'
|
128
|
+
# 插入表格
|
129
|
+
table {
|
130
|
+
tr {
|
131
|
+
th 'id'
|
132
|
+
th 'name'
|
133
|
+
th 'age'
|
134
|
+
}
|
135
|
+
tr {
|
136
|
+
th '1'
|
137
|
+
th 'young'
|
138
|
+
th '66'
|
139
|
+
}
|
140
|
+
}
|
141
|
+
}
|
142
|
+
|
143
|
+
|
144
|
+
}
|
145
|
+
```
|
146
|
+
|
147
|
+
# 文档
|
148
|
+
[查看文档](doc/README.md)
|
149
|
+
|
150
|
+
# 马上要做的
|
151
|
+
+ 支持更多样式
|
152
|
+
+ 支持markdown/html转换为word
|
153
|
+
|
154
|
+
# 贡献
|
155
|
+
非常欢迎有兴趣的朋友加入到开发中,以下是提交流程
|
156
|
+
1. fork this project
|
157
|
+
2. git clone your fork project
|
158
|
+
3. git checkout -b fixed-something
|
159
|
+
4. git commit fixed some bug.
|
160
|
+
5. git push to your fork project
|
161
|
+
6. create a new pr to request merge
|
162
|
+
|
163
|
+
# 灵感
|
164
|
+
首先非常感谢 [PHPWord](https://github.com/PHPOffice/PHPWord), 因为在无意中发现了 PHPWord 的这个非常强大项目, 并且该项目支持很多各种各样的特性。但是当我在寻找我大 Ruby 这类相关项目的时候居然找不到,本着学习的精神,参考了 PHPWord 的设计,就自己写了一个啦,欢迎 Star 支持一下。
|
165
|
+
|
166
|
+
# 协议
|
167
|
+
RubyWord is licensed under [The MIT License](LICENSE)
|
data/README.md
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
# RubyWord: Microsoft Word Generation For Ruby
|
2
2
|
> RubyWord is a simple, efficient Word document generation gem and easy to generate docx file.
|
3
3
|
|
4
|
+
# Language
|
5
|
+
* [English](README.md)
|
6
|
+
* [简体中文](README.cn.md)
|
7
|
+
|
8
|
+
# CHANGELOG
|
9
|
+
[ChANGELOG](CHANGELOG.md)
|
10
|
+
|
4
11
|
# Please Read Before Use
|
5
12
|
This project is under developing, and develop by myself until now, so the progress may be slow and there may be a lot of problems, but i will try my best to improve it and welcome everyone to join the development. Thanks for supporting.
|
6
13
|
|
@@ -14,6 +21,7 @@ gem 'rubyword'
|
|
14
21
|
```
|
15
22
|
# Features
|
16
23
|
+ Support for setting the properties of the document, such as: title, subject, author and other information
|
24
|
+
+ Support for insert a paragraph
|
17
25
|
+ Support for generated TOC for the title
|
18
26
|
+ Support for setting header and footer
|
19
27
|
+ Support for insert title which is different attributes, such as: title, sub title, etc.
|
@@ -21,7 +29,7 @@ gem 'rubyword'
|
|
21
29
|
+ Support for insert multiple images
|
22
30
|
+ Support for insert multiple lists
|
23
31
|
+ Support for insert hyperlink
|
24
|
-
|
32
|
+
+ Support for insert table
|
25
33
|
# Usage
|
26
34
|
```
|
27
35
|
require "rubyword"
|
@@ -99,13 +107,26 @@ Rubyword::Document::generate('hello.docx') {
|
|
99
107
|
# add a link
|
100
108
|
link 'baidu', 'http://www.baidu.com', text_align: 'center'
|
101
109
|
image 'http://www.baidu.com/img/bd_logo1.png'
|
110
|
+
# add table
|
111
|
+
table {
|
112
|
+
tr {
|
113
|
+
th 'id'
|
114
|
+
th 'name'
|
115
|
+
th 'age'
|
116
|
+
}
|
117
|
+
tr {
|
118
|
+
th '1'
|
119
|
+
th 'young'
|
120
|
+
th '66'
|
121
|
+
}
|
122
|
+
}
|
102
123
|
}
|
103
124
|
}
|
104
125
|
```
|
126
|
+
# Document
|
127
|
+
[More Information](doc/README.md)
|
105
128
|
|
106
129
|
# TODO
|
107
|
-
+ Support table
|
108
|
-
+ Support paragraph
|
109
130
|
+ Support more style
|
110
131
|
+ Support Markdown/HTML to docx
|
111
132
|
|
data/bin/run-example
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
file_path = File.join(File.expand_path('../../', __FILE__), 'example')
|
3
|
+
puts file_path
|
4
|
+
Dir.foreach(file_path) do |filename|
|
5
|
+
real_path = "#{file_path}/#{filename}"
|
6
|
+
next if File.directory?(real_path)
|
7
|
+
if filename != "." and filename != ".."
|
8
|
+
system "ruby #{real_path}"
|
9
|
+
puts "#{filename} done."
|
10
|
+
end
|
11
|
+
end
|
data/doc/README.md
CHANGED
@@ -1 +1,18 @@
|
|
1
|
-
#
|
1
|
+
# Rubyword Document
|
2
|
+
|
3
|
+
### Example Text
|
4
|
+
+ You can check and run the example in `/example` dir or run `/bin/run-example`
|
5
|
+
|
6
|
+
### Feature List
|
7
|
+
+ [Text](text.md)
|
8
|
+
+ [Title](title.md)
|
9
|
+
+ [Toc](toc.md)
|
10
|
+
+ [Paragraph](paragraph.md)
|
11
|
+
+ [List](list.md)
|
12
|
+
+ [Link](link.md)
|
13
|
+
+ [Image](image.md)
|
14
|
+
+ [Table](table.md)
|
15
|
+
+ [Header](header.md)
|
16
|
+
+ [Footer](footer.md)
|
17
|
+
+ [Doc Information](doc-information.md)
|
18
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Doc Information
|
2
|
+
|
3
|
+
## Example
|
4
|
+
```
|
5
|
+
Rubyword::Document::generate('hello.docx') {
|
6
|
+
information({
|
7
|
+
company: 'ruby word',
|
8
|
+
creator: 'young',
|
9
|
+
title: 'example word file',
|
10
|
+
description: 'this is a example docx',
|
11
|
+
subject: 'how to create doc info',
|
12
|
+
keywords: 'remark',
|
13
|
+
category: 'category'
|
14
|
+
})
|
15
|
+
}
|
16
|
+
```
|
data/doc/footer.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Footer
|
2
|
+
|
3
|
+
## Options
|
4
|
+
+ text_align: 'left' | 'center' | 'right'
|
5
|
+
+ nums_type: 'number' | 'roman', Desc: when you need page numer as a footer, the text(first param) must be nil
|
6
|
+
|
7
|
+
## Example
|
8
|
+
```
|
9
|
+
Rubyword::Document::generate('hello.docx') {
|
10
|
+
# insert footer with page number
|
11
|
+
add_footer nil, text_align: 'center', nums_type: 'number'
|
12
|
+
|
13
|
+
# insert footer with roman number
|
14
|
+
add_footer nil, text_align: 'center', nums_type: 'roman'
|
15
|
+
|
16
|
+
# insert footer with string
|
17
|
+
add_footer 'hello', text_align: 'center'
|
18
|
+
}
|
19
|
+
```
|
data/doc/header.md
ADDED
data/doc/image.md
ADDED
data/doc/link.md
ADDED
data/doc/list.md
ADDED
data/doc/paragraph.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Paragraph
|
2
|
+
|
3
|
+
## Style
|
4
|
+
+ font_size: Number | 16
|
5
|
+
+ color: Number | 996699
|
6
|
+
+ bgcolor: Number | 996699
|
7
|
+
+ underline: Boolean | true
|
8
|
+
+ blod: Boolean | true
|
9
|
+
+ all_caps: Boolean | false
|
10
|
+
+ italic: Boolean | false
|
11
|
+
+ text_align: 'left' || 'center' || 'right',
|
12
|
+
+ spacing: Number 200
|
13
|
+
+ indent_left: Number 100
|
14
|
+
+ indent_right: Number 200
|
15
|
+
+ indent_between: Number 200
|
16
|
+
|
17
|
+
## Example
|
18
|
+
```
|
19
|
+
Rubyword::Document::generate('hello.docx') {
|
20
|
+
section {
|
21
|
+
p {
|
22
|
+
text 'This is a '
|
23
|
+
text 'apple, yellow apple', bgcolor: 'yellow', text_align: 'center'
|
24
|
+
}
|
25
|
+
}
|
26
|
+
}
|
27
|
+
```
|