template_docx 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 659fd10b37a237160b5030a416a992af4df658fd
4
- data.tar.gz: 9f3dc09be8c5c2304b7df86de79232f1abb8d856
3
+ metadata.gz: 9c9d90aaa205d811250db75db6f0e4ba55f69798
4
+ data.tar.gz: c4354b59bd2c7894b726e45225248e22d9d83f41
5
5
  SHA512:
6
- metadata.gz: bdefb2005499f76a403312f742e15b0348c2a91e0a7bebdba4aab07233950ac6d8e15247f0317ffc67978a0a64935b10b0ef4f33c28a0f37ff4577b9523916e0
7
- data.tar.gz: a676e275f69ec389615d89e7f44f84b080c825553e03d6f7eda906376307e14a559796219dcb25c4b092fab2f07bef2543c3c678148f7906126b6869883f6463
6
+ metadata.gz: 70b9a32eb1c0b61a6ff895fdf52599ae8fc74c9e455f61a4db02946ade51a6a8744bd0b08629baef5aaa3bda14ce02b24b3cd8ed745a987174772f06b7b6bc21
7
+ data.tar.gz: 800b6eb23206a9898e2c94f95076651c56cf9178d38145d010fb7c8016884e46e0c2db6c5fc557c74dbef680688c6e24842cd7fdabdb69c4d242fbc73a84de15
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- <img src="https://travis-ci.org/jawspeak/ruby-docx-templater.png" /> [https://travis-ci.org/jawspeak/ruby-docx-templater]
2
-
3
- [!](https://travis-ci.org/jawspeak/ruby-docx-templater.png) [https://travis-ci.org/jawspeak/ruby-docx-templater]
1
+ <a href='https://travis-ci.org/jawspeak/ruby-docx-templater'>
2
+ <img src="https://travis-ci.org/jawspeak/ruby-docx-templater.png" />
3
+ </a>
4
4
 
5
5
  # ruby-docx-templater
6
6
 
@@ -17,8 +17,9 @@ gem 'template_docx'
17
17
 
18
18
  Or,
19
19
 
20
- ```ruby
21
20
 
21
+ ```ruby
22
+ gem 'template_docx', github: 'xiajian/ruby-docx-templater'
22
23
  ```
23
24
 
24
25
  And then execute:
@@ -27,12 +28,16 @@ And then execute:
27
28
 
28
29
  Or install it yourself as:
29
30
 
30
- $ gem install aliexpress
31
+ $ gem install template_docx
32
+
31
33
 
32
34
  ## Usage
33
35
 
36
+ [中文文档](https://github.com/Yundianjia/ruby-docx-templater/blob/master/README_cn.md)
37
+
38
+ ### Command Line:
34
39
 
35
- Command Line:
40
+ Base Usage
36
41
 
37
42
  ```
38
43
  Usage: docx-templater [options]
@@ -43,7 +48,45 @@ Usage: docx-templater [options]
43
48
  -v, --version Print version
44
49
  ```
45
50
 
46
- Program:
51
+ Usage example: `docx-templater -i -d tmp/test.json -o` or `docx-templater -i -d tmp/test.json -o`
52
+
53
+ [Example yml file](https://raw.githubusercontent.com/xiajian/ruby-docx-templater/master/spec/example_input/brand_input.yml):
54
+
55
+ ```
56
+ ---
57
+ :company: 伟大的邪王真眼
58
+ :shop_name: 斜阳西下,三百二十七
59
+ :shop_id: 122323232323
60
+ :shop_url: http://blog.csdn.net/ruixj/article/details/3765385
61
+ :master_company: 紫电清爽公司
62
+ :brand_name: 邪王正眼
63
+ :start_date: 2016年-08月-31日
64
+ :end_date: 2016年-09月-01日
65
+ :license_number: 1212121212
66
+ :authorized_party: 夏健的夏天
67
+ :authorized_date: 2016年-09月-01日
68
+ ```
69
+
70
+ [Example json file](https://raw.githubusercontent.com/xiajian/ruby-docx-templater/master/spec/example_input/brand_input.json):
71
+
72
+
73
+ ```
74
+ {
75
+ "company": "伟大的邪王真眼",
76
+ "shop_name": "斜阳西下,三百二十七",
77
+ "shop_id": 122323232323,
78
+ "shop_url": "http://blog.csdn.net/ruixj/article/details/3765385",
79
+ "master_company": "紫电清爽公司",
80
+ "brand_name": "邪王正眼",
81
+ "start_date": "2016年-08月-31日",
82
+ "end_date": "2016年-09月-01日",
83
+ "license_number": 1212121212,
84
+ "authorized_party": "夏健的夏天",
85
+ "authorized_date": "2016年-09月-01日"
86
+ }
87
+ ```
88
+
89
+ Programming:
47
90
 
48
91
  ```
49
92
  options = {
@@ -67,7 +110,7 @@ options = {
67
110
  DocxTemplater.template_docx options
68
111
  ```
69
112
 
70
- ### operatation flow
113
+ ### workflow
71
114
 
72
115
  * Create your docx "template" in Word
73
116
  * Install rvm and bundler
@@ -77,15 +120,18 @@ DocxTemplater.template_docx options
77
120
 
78
121
  __TECHNICAL NOTE:__ You will probably need to extract and edit the xml template manually after creating in Word, to prepare the ruby script template with it. This is very fiddly / hacky. You can’t have Word’s ugly markup around the fields to template. It will try to break up fields with markup. Test the template, fixing it until the extracted word/document.xml as needed.
79
122
 
80
- I frequently use this workflow:
81
- `rm -rf word/; unzip ExampleTemplate.docx word/document.xml; mate word/document.xml`
82
- Grep/search for all $ and # lines and ensure no templating is split with xml markup.
83
- And then re-add the edited document:
84
- `zip ExampleTemplate.docx word/document.xml`
123
+ **Workflow**:
85
124
 
86
- __PRO TIP:__ You don’t want any grammar errors on the template Keys, or they will not substitute. (Grammar suggestion markup splits up the tokens in the xml). Right click and choose Ignore each grammar error.
125
+ 1. remove word directory file: `rm -rf word/`
87
126
 
88
- [中文文档](https://github.com/Yundianjia/ruby-docx-templater/blob/master/README_cn.md)
127
+ 2. unzip example template docx: `unzip ExampleTemplate.docx word/document.xml`
128
+
129
+ 3. edit xml: `vi word/document.xml`
130
+
131
+ 4. Grep/search for all $ and # lines and ensure no templating is split with xml markup.
132
+ And then re-add the edited document: `zip ExampleTemplate.docx word/document.xml`
133
+
134
+ __PRO TIP:__ You don’t want any grammar errors on the template Keys, or they will not substitute. (Grammar suggestion markup splits up the tokens in the xml). Right click and choose Ignore each grammar error.
89
135
 
90
136
 
91
137
  ## Development
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'optparse'
4
3
  require 'json'
4
+ require 'psych'
5
+ require 'optparse'
5
6
  require 'bundler/setup'
6
7
  require 'docx_templater'
7
8
 
@@ -25,23 +26,33 @@ OptionParser.new do |opts|
25
26
  options[:input_file] = file || 'Example.docx'
26
27
  end
27
28
 
28
- opts.on('-d', '--format-data [data]', 'Default: data format file, json format') do |data|
29
- unless data
30
- options[:data] = {
31
- company: '伟大的邪王真眼',
32
- shop_name: '斜阳西下,三百二十七',
33
- shop_id: 122323232323,
34
- shop_url: 'http://blog.csdn.net/ruixj/article/details/3765385',
35
- master_company: '紫电清爽公司',
36
- brand_name: '邪王正眼',
37
- start_date: (Time.now - 3600 * 24).strftime('%Y年-%m月-%d日'),
38
- end_date: Time.now.strftime('%Y年-%m月-%d日'),
39
- license_number: 1212121212,
40
- authorized_party: '夏健的夏天',
41
- authorized_date: Time.now.strftime('%Y年-%m月-%d日')
42
- }
29
+ opts.on('-d', '--data-file [data-file]', 'Default: data format file, json format or yaml format') do |file|
30
+ unless file
31
+ options[:data] = Psych.load_file 'spec/example_input/brand_input.yml'
43
32
  else
44
33
  # 可以选择的 YML 文件,或者 json 文件之类格式化的文件,或者直接就是 Ruby 的 Hash 对象
34
+ if File.exist? file
35
+ file_name = File.basename file
36
+ file_type = file_name.split('.').last
37
+
38
+ begin
39
+ case file_type
40
+ when 'yml'.freeze
41
+ options[:data] = Psych.load_file file
42
+ when 'json'.freeze
43
+ json_string = ''
44
+ File.foreach(file) { |line| json_string << line.strip }
45
+
46
+ options[:data] = JSON.parse json_string
47
+ end
48
+ rescue => e
49
+ puts 'Parse file occurred exception!!'
50
+ puts e
51
+ end
52
+
53
+ else
54
+ puts 'File no exist !!'
55
+ end
45
56
  end
46
57
  end
47
58
 
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
24
24
  root_files = %w(docx_templater.gemspec LICENSE.txt Rakefile README.md .gitignore Gemfile)
25
25
  s.files = Dir['{lib,script,spec,bin}/**/*'] + root_files
26
26
  s.test_files = Dir['spec/**/*']
27
- s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ s.executables = ['docx-templater']
28
28
  s.required_ruby_version = '>= 1.9.3'
29
29
 
30
30
  s.add_dependency 'nokogiri'
@@ -1,3 +1,3 @@
1
1
  module DocxTemplater
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.3'
3
3
  end
@@ -0,0 +1,13 @@
1
+ {
2
+ "company": "伟大的邪王真眼",
3
+ "shop_name": "斜阳西下,三百二十七",
4
+ "shop_id": 122323232323,
5
+ "shop_url": "http://blog.csdn.net/ruixj/article/details/3765385",
6
+ "master_company": "紫电清爽公司",
7
+ "brand_name": "邪王正眼",
8
+ "start_date": "2016年-08月-31日",
9
+ "end_date": "2016年-09月-01日",
10
+ "license_number": 1212121212,
11
+ "authorized_party": "夏健的夏天",
12
+ "authorized_date": "2016年-09月-01日"
13
+ }
@@ -0,0 +1,12 @@
1
+ ---
2
+ :company: 伟大的邪王真眼
3
+ :shop_name: 斜阳西下,三百二十七
4
+ :shop_id: 122323232323
5
+ :shop_url: http://blog.csdn.net/ruixj/article/details/3765385
6
+ :master_company: 紫电清爽公司
7
+ :brand_name: 邪王正眼
8
+ :start_date: 2016年-08月-31日
9
+ :end_date: 2016年-09月-01日
10
+ :license_number: 1212121212
11
+ :authorized_party: 夏健的夏天
12
+ :authorized_date: 2016年-09月-01日
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: template_docx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Andrew Wolter
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-08-15 00:00:00.000000000 Z
12
+ date: 2016-09-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -100,7 +100,8 @@ description: 'A Ruby library to template Microsoft Word .docx files. Uses a .doc
100
100
  email:
101
101
  - jaw@jawspeak.com
102
102
  - jhqy2011@gmail.com
103
- executables: []
103
+ executables:
104
+ - docx-templater
104
105
  extensions: []
105
106
  extra_rdoc_files: []
106
107
  files:
@@ -120,6 +121,9 @@ files:
120
121
  - lib/docx_templater/version.rb
121
122
  - spec/example_input/ExampleBrand.docx
122
123
  - spec/example_input/ExampleTemplate.docx
124
+ - spec/example_input/brand_input.json
125
+ - spec/example_input/brand_input.yml
126
+ - spec/example_input/tmp/IntegrationBrandOutput.docx
123
127
  - spec/example_input/tmp/IntegrationTestOutput.docx
124
128
  - spec/example_input/word/document.xml
125
129
  - spec/integration_spec.rb
@@ -150,8 +154,11 @@ signing_key:
150
154
  specification_version: 4
151
155
  summary: Generates new Word .docx files based on a template file.
152
156
  test_files:
157
+ - spec/example_input/brand_input.json
158
+ - spec/example_input/brand_input.yml
153
159
  - spec/example_input/ExampleBrand.docx
154
160
  - spec/example_input/ExampleTemplate.docx
161
+ - spec/example_input/tmp/IntegrationBrandOutput.docx
155
162
  - spec/example_input/tmp/IntegrationTestOutput.docx
156
163
  - spec/example_input/word/document.xml
157
164
  - spec/integration_spec.rb