template_docx 0.1.0 → 0.1.1

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: e83a00f787254eadc60f298a9a4c0ffa25b5e3cf
4
- data.tar.gz: 2df41e4ca1e89b5e8e3db65aa0916c2c73738cba
3
+ metadata.gz: 659fd10b37a237160b5030a416a992af4df658fd
4
+ data.tar.gz: 9f3dc09be8c5c2304b7df86de79232f1abb8d856
5
5
  SHA512:
6
- metadata.gz: 40f9f1eb8bb3c42027c84a07064ac3983803cbfeb605e6a021017442e6bbfbb2c5f7e0f38381a53fdac93c290963072e02ecec1866c453d07fb06345381a570f
7
- data.tar.gz: 64d4898ddf60c4076e4ac77fd9e8e5fdabfacf2f3f001d4c64d98a37b22af755a210ea21e5b03529caecd7ead2374cb84615236c9918857a514e0c97ae440a77
6
+ metadata.gz: bdefb2005499f76a403312f742e15b0348c2a91e0a7bebdba4aab07233950ac6d8e15247f0317ffc67978a0a64935b10b0ef4f33c28a0f37ff4577b9523916e0
7
+ data.tar.gz: a676e275f69ec389615d89e7f44f84b080c825553e03d6f7eda906376307e14a559796219dcb25c4b092fab2f07bef2543c3c678148f7906126b6869883f6463
data/README.md CHANGED
@@ -1,17 +1,74 @@
1
- {<img src#"https://travis-ci.org/jawspeak/ruby-docx-templater.png" />}[https://travis-ci.org/jawspeak/ruby-docx-templater]
1
+ <img src="https://travis-ci.org/jawspeak/ruby-docx-templater.png" /> [https://travis-ci.org/jawspeak/ruby-docx-templater]
2
2
 
3
+ [!](https://travis-ci.org/jawspeak/ruby-docx-templater.png) [https://travis-ci.org/jawspeak/ruby-docx-templater]
3
4
 
4
- # Roughly, this takes a .docx file and uses it as a template to create a new docx, with your data
5
+ # ruby-docx-templater
5
6
 
6
- ## Features
7
+ Roughly, this takes a .docx file and uses it as a template to create a new docx, with your data
7
8
 
8
- * All manipulation in memory (great if you have sensitive data)
9
- * Global key/value substitutions by entering a `$KEY$` anywhere in the word document, with whatever formatting you want.
10
- * Multi-row loops inside tables, also with whatever your formatting you wish. `#BEGIN_ROW:XYZ#`... `#END_ROW:XYZ#` see tests/example
11
- * Summation formula for row count `#SUM:XYZ_LIST#`
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+
14
+ ```ruby
15
+ gem 'template_docx'
16
+ ```
17
+
18
+ Or,
19
+
20
+ ```ruby
21
+
22
+ ```
23
+
24
+ And then execute:
25
+
26
+ $ bundle
27
+
28
+ Or install it yourself as:
29
+
30
+ $ gem install aliexpress
12
31
 
13
32
  ## Usage
14
33
 
34
+
35
+ Command Line:
36
+
37
+ ```
38
+ Usage: docx-templater [options]
39
+ -i, --input-file [file] Default: Example.docx
40
+ -d, --format-data [data] Default: data format file, json format - Not Implementation, No Used!!
41
+ -o, --output-file [file] Default: OutputTemplate.docx
42
+ -h, --help Show this message
43
+ -v, --version Print version
44
+ ```
45
+
46
+ Program:
47
+
48
+ ```
49
+ options = {
50
+ input_file: 'spec/example_input/ExampleBrand.docx'
51
+ output_file: 'OutputTemplate.docx',
52
+ data = {
53
+ company: '伟大的邪王真眼',
54
+ shop_name: '斜阳西下,三百二十七',
55
+ shop_id: 122323232323,
56
+ shop_url: 'http://blog.csdn.net/ruixj/article/details/3765385',
57
+ master_company: '紫电清爽公司',
58
+ brand_name: '邪王正眼',
59
+ start_date: (Time.now - 3600 * 24).strftime('%Y年-%m月-%d日'),
60
+ end_date: Time.now.strftime('%Y年-%m月-%d日'),
61
+ license_number: 1212121212,
62
+ authorized_party: '夏健的夏天',
63
+ authorized_date: Time.now.strftime('%Y年-%m月-%d日')
64
+ }
65
+ }
66
+
67
+ DocxTemplater.template_docx options
68
+ ```
69
+
70
+ ### operatation flow
71
+
15
72
  * Create your docx "template" in Word
16
73
  * Install rvm and bundler
17
74
  * Run `bundle install`.
@@ -37,6 +94,13 @@ __PRO TIP:__ You don’t want any grammar errors on the template Keys, or they w
37
94
  * Run the integration test suite (on mac, with word installed): `rake integration`
38
95
  * Build the gem file: `gem build docx_templater.gemspec`
39
96
 
97
+ ## Features
98
+
99
+ * All manipulation in memory (great if you have sensitive data)
100
+ * Global key/value substitutions by entering a `$KEY$` anywhere in the word document, with whatever formatting you want.
101
+ * Multi-row loops inside tables, also with whatever your formatting you wish. `#BEGIN_ROW:XYZ#`... `#END_ROW:XYZ#` see tests/example
102
+ * Summation formula for row count `#SUM:XYZ_LIST#`
103
+
40
104
 
41
105
  ## Future ideas
42
106
 
@@ -44,4 +108,4 @@ __PRO TIP:__ You don’t want any grammar errors on the template Keys, or they w
44
108
  ** See also: {http://tomasvarsavsky.com/2009/04/04/simple-word-document-templating-using-ruby-and-xml/} and {https://github.com/bagilevi/docx_builder/tree/master/example/plan_report_template},
45
109
  * Possibly, also use Fields to create the looping constructs. That would be a big win for preventing word adding markup between words in by text.
46
110
  * Make rendering from the template more efficient.
47
- * Try templating header/footer (I haven't attempted that yet because I do not have a need for it.)
111
+ * Try templating header/footer (I haven't attempted that yet because I do not have a need for it.)
@@ -21,14 +21,7 @@ module DocxTemplater
21
21
  end
22
22
 
23
23
  def self.generate_doc(options = {})
24
- puts "options: #{options}"
25
-
26
- DocxTemplater::DocxCreator.new(options[:input_file], options[:data]).generate_docx_file(options[:output_file])
27
-
28
- archive = Zip::File.open(options[:output_file])
29
- archive.close
30
-
31
- DocxTemplater.open_output_file options[:output_file]
24
+ DocxTemplater.template_docx options
32
25
  end
33
26
 
34
27
  protected
@@ -1,3 +1,3 @@
1
1
  module DocxTemplater
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -1,5 +1,6 @@
1
1
  require 'docx_templater/version'
2
2
  require 'docx_templater/template_processor'
3
+ require 'docx_templater/docx_creator'
3
4
 
4
5
  module DocxTemplater
5
6
  module_function
@@ -9,6 +10,29 @@ module DocxTemplater
9
10
  puts str if ENV['DEBUG']
10
11
  end
11
12
 
13
+ # template docx file
14
+ #
15
+ # @param {Hash} options -
16
+ #
17
+ # @example
18
+ # options = {
19
+ # input_file: 'xxx',
20
+ # output_file: 'xxx',
21
+ # data: { key: value }
22
+ # }
23
+ def template_docx(options = {})
24
+ puts "options: #{options}"
25
+
26
+ DocxTemplater::DocxCreator.new(options[:input_file], options[:data]).generate_docx_file(options[:output_file])
27
+
28
+ archive = Zip::File.open(options[:output_file])
29
+ archive.close
30
+
31
+ DocxTemplater.open_output_file options[:output_file]
32
+ end
33
+
34
+
35
+ # Open word file in mac os(with word installed)
12
36
  def open_output_file(output_file)
13
37
  puts "\n************************************"
14
38
  puts ' >>> Only will work on mac <<<'
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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Andrew Wolter