simple_docx_generator 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3167a561448b81036fbf5ef507a973903be10949
4
+ data.tar.gz: bf9bc6a33453a6a5e2d3194ba192d9ec30eedaef
5
+ SHA512:
6
+ metadata.gz: 4a8c66c4c3209bc2856248572c4c88e86996ad3693fc8cea1ccc2032f94c30621f8968b22fe4664dd9810911e17ca7aae759ba6d1b02f397bd064eab42aed19a
7
+ data.tar.gz: 2b9a9ae9505c1c4ee68a6b7ea8ba04b360da284dab6971db94aec641253249d84eac1c0df67e4b186164c1c9a90f67248f00250658943c098cd27e144b29ad16
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.4
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in simple_docx_generator.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 seventhsense
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,72 @@
1
+ [![Dependency Status](https://gemnasium.com/badges/github.com/seventhsense/simple_docx_generator.svg)](https://gemnasium.com/github.com/seventhsense/simple_docx_generator)
2
+ [![Code Climate](https://codeclimate.com/github/seventhsense/simple_docx_generator/badges/gpa.svg)](https://codeclimate.com/github/seventhsense/simple_docx_generator)
3
+ [![Test Coverage](https://codeclimate.com/github/seventhsense/simple_docx_generator/badges/coverage.svg)](https://codeclimate.com/github/seventhsense/simple_docx_generator/coverage)
4
+ [![Travis CI](https://travis-ci.org/seventhsense/simple_docx_generator.svg?branch=master)](https://travis-ci.org/seventhsense/simple_docx_generator)
5
+
6
+
7
+ # SimpleDocxGenerator
8
+
9
+ RubyやRailsからdocxファイルの@@で囲まれた文字列を置換えます.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'simple_docx_generator', git: 'git://github.com/seventhsense/simple_docx_generator.git'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install simple_docx_generator --source git://github.com/seventhsense/simple_docx_generator.git
24
+
25
+ ## Usage
26
+
27
+ ### docxファイルを準備する
28
+
29
+ 変数(@@で始まり@@で終わる大文字小文字の英数字とアンダーバー)を含むテンプレートを準備します.
30
+ ex. @@hello@@
31
+
32
+ 変数の後ろに.checkboxとつけるとWordのチェックボックスを作成します.
33
+ 値に"1"を設定するとチェックつきのチェックボックスを出力します.
34
+ 変数の後ろに.textとつけると改行も反映されます.
35
+
36
+ ### require 'simple_docx_generator'
37
+
38
+
39
+ ### initialize
40
+
41
+ mydocx = MyDocx.new(path_to_docxfile)
42
+
43
+ ### 変数を確認する
44
+
45
+ mydocx.keys
46
+
47
+ テンプレート内の変数を得ます
48
+
49
+ ### 変数に値をセットする
50
+
51
+ mydocx.set key, value
52
+
53
+ ### 新しいdocxファイルを作成する
54
+
55
+ mydocx.generate filename
56
+
57
+ テンプレートファイルと同じディレクトリにfilename.docxという名前のdocxファイルが生成されます.
58
+ filenameを省略すると、output_元のファイル名となります.
59
+
60
+ ### Railsでの活用
61
+
62
+ [状況に応じてRailsのフォームの種類を変える](http://blog.scimpr.com/2012/11/09/%e7%8a%b6%e6%b3%81%e3%81%ab%e5%bf%9c%e3%81%98%e3%81%a6rails%e3%81%ae%e3%83%95%e3%82%a9%e3%83%bc%e3%83%a0%e3%81%ae%e7%a8%ae%e9%a1%9e%e3%82%92%e5%a4%89%e3%81%88%e3%82%8b/)
63
+
64
+ [![IMAGE ALT TEXT HERE](https://img.youtube.com/vi/ztu2OP_p4ec/0.jpg)](https://www.youtube.com/watch?v=ztu2OP_p4ec)
65
+
66
+ ## Contributing
67
+
68
+ 1. Fork it
69
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
70
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
71
+ 4. Push to the branch (`git push origin my-new-feature`)
72
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task default: :spec
6
+
data/coverage.vim ADDED
@@ -0,0 +1,84 @@
1
+ "hi HitLine ctermbg=Cyan guibg=Cyan
2
+ "hi MissLine ctermbg=Magenta guibg=Magenta
3
+ hi HitSign ctermfg=Green cterm=bold gui=bold guifg=Green
4
+ hi MissSign ctermfg=Red cterm=bold gui=bold guifg=Red
5
+
6
+ sign define hit linehl=HitLine texthl=HitSign text=>>
7
+ sign define miss linehl=MissLine texthl=MissSign text=:(
8
+
9
+ "Generated by simplecov-vim
10
+ let s:coverage = {'/home/yahihi/simple_docx_generator/spec/simple_docx_generator_spec.rb': [[],[]], }
11
+
12
+ let s:generatedTime = 1476313772
13
+
14
+ function! BestCoverage(coverageForName)
15
+ let matchBadness = strlen(a:coverageForName)
16
+ for filename in keys(s:coverage)
17
+ let matchQuality = match(a:coverageForName, filename . "$")
18
+ if (matchQuality >= 0 && matchQuality < matchBadness)
19
+ let found = filename
20
+ endif
21
+ endfor
22
+
23
+ if exists("found")
24
+ return s:coverage[found]
25
+ else
26
+ echom "No coverage recorded for " . a:coverageForName
27
+ return [[],[]]
28
+ endif
29
+ endfunction
30
+
31
+ let s:signs = {}
32
+ let s:signIndex = 1
33
+
34
+ function! s:CoverageSigns(filename)
35
+ let [hits,misses] = BestCoverage(a:filename)
36
+
37
+ if (getftime(a:filename) > s:generatedTime)
38
+ echom "File is newer than coverage report which was generated at " . strftime("%c", s:generatedTime)
39
+ endif
40
+
41
+ if (! exists("s:signs['".a:filename."']"))
42
+ let s:signs[a:filename] = []
43
+ endif
44
+
45
+ for hit in hits
46
+ let id = s:signIndex
47
+ let s:signIndex += 1
48
+ let s:signs[a:filename] += [id]
49
+ exe ":sign place ". id ." line=".hit." name=hit file=" . a:filename
50
+ endfor
51
+
52
+ for miss in misses
53
+ let id = s:signIndex
54
+ let s:signIndex += 1
55
+ let s:signs[a:filename] += [id]
56
+ exe ":sign place ".id." line=".miss." name=miss file=" . a:filename
57
+ endfor
58
+ endfunction
59
+
60
+ function! s:ClearCoverageSigns(filename)
61
+ if(exists("s:signs['". a:filename."']"))
62
+ for signId in s:signs[a:filename]
63
+ exe ":sign unplace ".signId
64
+ endfor
65
+ let s:signs[a:filename] = []
66
+ endif
67
+ endfunction
68
+
69
+ let s:filename = expand("<sfile>")
70
+ function! s:AutocommandUncov(sourced)
71
+ if(a:sourced == s:filename)
72
+ call s:ClearCoverageSigns(expand("%:p"))
73
+ endif
74
+ endfunction
75
+
76
+ command! -nargs=0 Cov call s:CoverageSigns(expand("%:p"))
77
+ command! -nargs=0 Uncov call s:ClearCoverageSigns(expand("%:p"))
78
+
79
+ augroup SimpleCov
80
+ au!
81
+ exe "au SourcePre ".expand("<sfile>:t")." call s:AutocommandUncov(expand('<afile>:p'))"
82
+ augroup end
83
+
84
+ Cov
@@ -0,0 +1,197 @@
1
+ #encoding: utf-8
2
+ # require 'zipruby'
3
+ require 'nokogiri'
4
+ require 'ydocx'
5
+
6
+ #= クラス/MyDocx
7
+ # docxを扱うクラスです
8
+ # 主な機能は次のとおりです
9
+ # * テンプレートファイルの場所を指定してインスタンス化します
10
+ # * keysメソッドでテンプレートファイルに含まれる変数(以下、テンプレートファイルで使う変数を単に変数といいます)を取得します
11
+ # * setメソッドで変数に値を代入することができます
12
+ # * generateメソッドでdocxファイルを生成します
13
+ class MyDocx
14
+
15
+ #== 変数を定義する正規表現
16
+ #=== 変数の定義
17
+ # * @@で始まり、@@で終わる
18
+ # * 半角アルファベットの大文字・小文字またはアンダーバーで始まる
19
+ # * 2文字目以降は半角アルファベットの大文字・小文字アンダーバーのほかに数字とピリオドを使うことができる
20
+ # * 最初のピリオドから次のピリオドないし最後の@@までの文字列をプロパティという
21
+ # 例:: @@hello.text@@
22
+ # - .checkboxプロパティ 値をStringの"1"に指定すると☑に置換えます。それ以外の値は☐に置換えます
23
+ # - .textプロパティ 改行も含めて再現します
24
+ VAR_REGEX = Regexp.new('@@[a-zA-Z_][a-zA-Z0-9_.]+?@@')
25
+
26
+ #== initialize
27
+ # インスタンスの初期化
28
+ # Param:: path_to_templateはテンプレートファイルの場所を指定します
29
+ # テンプレートファイルに半角スペースなどを含んでいると生成されたdocxにエラーが出ます
30
+ def initialize(path_to_template)
31
+ @keys_index = {}
32
+ @filename = File.basename(path_to_template)
33
+ @dir = File.dirname(path_to_template)
34
+ set_document_xml(path_to_template)
35
+ set_keys_index
36
+ end
37
+
38
+ #== set
39
+ # 変数に値を代入します
40
+ # Params:: key, valueともにString valueを指定しない場合は''になります
41
+ # Return:: setに成功したらtrue、失敗したらfalseが返ります
42
+ # 典型的にはkeyが存在しない場合を想定しています
43
+ def set(key, value = '')
44
+ value = set_checkbox_value(key, value)
45
+ if key.gsub(/@@/, '').split('.')[1] == 'text'
46
+ replace_br(key, value)
47
+ else
48
+ replace(key, value)
49
+ end
50
+ end
51
+
52
+ #== keys
53
+ # 変数の一覧をArrayで返します
54
+ # Return:: 変数の一覧をArrayで返します
55
+ def keys
56
+ @keys_index.map do |key, value|
57
+ key
58
+ end
59
+ end
60
+
61
+ #== keys_index
62
+ # 変数と変数が含まれている場所です
63
+ # Return:: 形式は変数をkey、対応する場所のArray(同じ変数がテンプレートファイル内に複数存在する可能性があります)をvalueとしたハッシュ形式です。デバッグ用。
64
+ def keys_index
65
+ @keys_index
66
+ end
67
+
68
+ #== all_text
69
+ # すべてのテキストをArrayで返します。今のところヘッダー・フッターは未対応です。デバッグ用。
70
+ def all_text
71
+ @document_xml.xpath("//w:t").map do |t_node|
72
+ t_node.content
73
+ end
74
+ end
75
+
76
+ #== to_html
77
+ # ydocxというパーサーを介して<div>タグで囲んだhtmlを返します
78
+ # オプションで<div>タグのclass名を指定できます
79
+ def to_html(class_name='')
80
+ ydocx = YDocx::Document.open File.join(@dir, @filename)
81
+ html = Nokogiri::HTML ydocx.to_html
82
+ nodes = html.xpath("//body").children
83
+ myhtml = Nokogiri::HTML::DocumentFragment.parse "<div></div>"
84
+ myhtml.child['class'] = class_name unless class_name.empty?
85
+ myhtml.child << nodes
86
+ myhtml.to_s
87
+ end
88
+
89
+ #== generate
90
+ # @document_xmlを使ってdocxファイルを生成します
91
+ # docxファイルはテンプレートファイルと同じディレクトリに生成されます
92
+ # もし同じファイル名のファイルが存在していた場合はそのファイルを上書きします
93
+ # Param:: filenameにdocx拡張子をつけた名前がファイル名となります
94
+ # もしfilenameを指定しない場合はoutput_元のファイル名.docxというファイルになります
95
+ # Return: パス付きのfilenameを値として返します
96
+ def generate(filename = 'output_' + @filename)
97
+ File.delete(filename) if File.exist?(filename)
98
+ buffer = Zip::OutputStream.write_buffer(::StringIO.new('')) do |out|
99
+ Zip::InputStream.open(File.join(@dir, @filename)) do |input|
100
+ while (entry = input.get_next_entry)
101
+ out.put_next_entry(entry.name)
102
+ if entry.name == 'word/document.xml'
103
+ out.write @document_xml.to_xml
104
+ else
105
+ out.write input.read
106
+ end
107
+ end
108
+ end
109
+ end
110
+ File.open(File.join(@dir, filename), 'wb') {|f| f.write(buffer.string)}
111
+ File.join @dir, filename
112
+ end
113
+
114
+ private
115
+ def set_document_xml(path_to_template)
116
+ Zip::File.open(path_to_template) do |zip_files|
117
+ document_file = zip_files.find_entry('word/document.xml')
118
+ @document_xml = Nokogiri::XML document_file.get_input_stream.read
119
+ end
120
+ end
121
+
122
+ def set_keys_index
123
+ i = 0
124
+ @document_xml.xpath("//w:t").each do |t_node|
125
+ text = t_node.content
126
+ if VAR_REGEX =~ text
127
+ text.scan(VAR_REGEX).each do |t|
128
+ @keys_index[t] ||= []
129
+ @keys_index[t] << i
130
+ end
131
+ end
132
+ # t_node.set_attribute("text_no" , i.to_s)
133
+ i += 1
134
+ end
135
+ end
136
+
137
+ def set_checkbox_value(key, value)
138
+ if key.gsub(/@@/, '').split('.')[1] == 'checkbox'
139
+ value = (value == "1") ? "☑" : "☐"
140
+ end
141
+ value
142
+ end
143
+
144
+ def replace(key, value)
145
+ index = @keys_index[key]
146
+ unless index == nil
147
+ index.each do |num|
148
+ text = @document_xml.xpath("//w:t")[num].content
149
+ text.gsub!(key, value)
150
+ @document_xml.xpath("//w:t")[num].content = text
151
+ end
152
+ true
153
+ else
154
+ false
155
+ end
156
+ end
157
+
158
+ def replace_br(key, value)
159
+ index = @keys_index[key]
160
+ unless index == nil
161
+ index.each do |num|
162
+ index_node = @document_xml.xpath("//w:t")[num].parent
163
+ index_p_node = index_node.parent
164
+ @document_xml.xpath("//w:t")[num].remove
165
+ frag = Nokogiri::XML::DocumentFragment.new @document_xml
166
+ value.split("\n").each do |t|
167
+ run_node = index_node.dup
168
+ p_node = index_p_node.dup
169
+ node = Nokogiri::XML::Node.new "t", @document_xml
170
+ node['prefix'] = "w"
171
+ node.content = t
172
+ run_node << node
173
+ p_node << run_node
174
+ frag << p_node
175
+ end
176
+ index_p_node.add_next_sibling frag
177
+ index_p_node.remove
178
+ end
179
+ set_keys_index
180
+ true
181
+ else
182
+ false
183
+ end
184
+ end
185
+
186
+ # def br_node
187
+ # br_node = Nokogiri::XML::Node.new "br", @document_xml
188
+ # br_node['prefix'] = "w"
189
+ # br_node
190
+ # end
191
+
192
+ # def _run_node
193
+ # run_node = Nokogiri::XML::Node.new "r", @document_xml
194
+ # run_node['prefix'] = "w"
195
+ # run_node
196
+ # end
197
+ end
@@ -0,0 +1,3 @@
1
+ module SimpleDocxGenerator
2
+ VERSION = "0.4.4"
3
+ end
@@ -0,0 +1,7 @@
1
+ #
2
+ # Author:: seventhsense
3
+ # Date:: 2012/11/13
4
+ # Copyright:: Copyright(c) 2012- seventhsense
5
+ require "simple_docx_generator/version"
6
+ require "simple_docx_generator/mydocx"
7
+
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'simple_docx_generator/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "simple_docx_generator"
8
+ gem.version = SimpleDocxGenerator::VERSION
9
+ gem.authors = ["seventhsense"]
10
+ gem.email = ["seventh@scimpr.com"]
11
+ gem.description = %q{テンプレートdocxに値を代入して新しいdocxファイルを生成します。}
12
+ gem.summary = %q{テンプレートdocxに値を代入して新しいdocxファイルを生成します。}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_runtime_dependency "nokogiri", "1.8.2"
21
+ gem.add_runtime_dependency "rubyzip" , "1.2.1"
22
+ gem.add_runtime_dependency "rmagick" , "2.16.0"
23
+ gem.add_runtime_dependency "htmlentities" , "4.3.4"
24
+ gem.add_runtime_dependency "ydocx" , "1.2.5"
25
+ gem.add_development_dependency "rspec"
26
+ gem.add_development_dependency "rake"
27
+ gem.add_development_dependency "simplecov"
28
+ gem.add_development_dependency "simplecov-vim"
29
+ gem.add_development_dependency "codeclimate-test-reporter"
30
+ end
Binary file
Binary file
File without changes
@@ -0,0 +1,112 @@
1
+ #encoding: utf-8
2
+ require 'spec_helper'
3
+ describe MyDocx do
4
+ before do
5
+ @mydocx = MyDocx.new 'spec/fixtures/helloworld.docx'
6
+ end
7
+
8
+ describe ".keys" do
9
+ it 'get keys collect' do
10
+ @mydocx.keys.should include("@@hello@@","@@world@@")
11
+ end
12
+ end
13
+ describe ".keys_index" do
14
+ it 'get keys_index collect' do
15
+ @mydocx.keys_index.should include({"@@hello@@"=>[0, 1]})
16
+ end
17
+ end
18
+ describe ".all_text" do
19
+ it 'get all_text collect' do
20
+ @mydocx.all_text.should include("@@hello@@ @@world@@", " @@hello@@")
21
+ end
22
+ end
23
+ describe ".set" do
24
+ it "set collectly key and value" do
25
+ @mydocx.set( '@@hello@@', 'HELLOOOO')
26
+ @mydocx.all_text.join.should include "HELLOOOO"
27
+ end
28
+ it "set collectly key and value" do
29
+ @mydocx.set( '@@hello@@', 'HELLOOOO')
30
+ @mydocx.all_text.join.should_not include "@@hello@@"
31
+ end
32
+
33
+ it "get true when collectly set key and value" do
34
+ @mydocx.set( '@@hello@@', 'HELLOOOO').should be true
35
+ end
36
+
37
+ it "get false when try to set incollect key and value" do
38
+ @mydocx.set( '@@HELLO@@', 'HELLOOOO').should be false
39
+ end
40
+ end
41
+
42
+ describe ".generate" do
43
+ it 'generate new file with output_' do
44
+ @mydocx.set( '@@hello@@', 'HELLOOOO')
45
+ @mydocx.generate
46
+ expect(File).to exist ("spec/fixtures/output_helloworld.docx")
47
+ end
48
+ it 'generate collect docx file' do
49
+ @mydocx.set( '@@hello@@', 'HELLOOOO')
50
+ @mydocx.generate
51
+ output_mydocx = MyDocx.new('spec/fixtures/output_helloworld.docx')
52
+ output_mydocx.all_text.join.should include "HELLOOOO"
53
+ end
54
+ end
55
+
56
+ describe "set_checkbox_value" do
57
+ it 'get key for checkbox property' do
58
+ @mydocx.keys.should include "@@hello.checkbox@@"
59
+ end
60
+ it 'set ☑ when checkbox is set as "1"' do
61
+ @mydocx.set('@@hello.checkbox@@', "1")
62
+ @mydocx.generate
63
+ output_mydocx = MyDocx.new('spec/fixtures/output_helloworld.docx')
64
+ output_mydocx.all_text.join.should include '☑'
65
+ end
66
+ it 'set ☐ when checkbox is set as "0"' do
67
+ @mydocx.set('@@hello.checkbox@@', "0")
68
+ @mydocx.all_text.join.should include '☐'
69
+ end
70
+ end
71
+
72
+ describe ".replace_rb" do
73
+ # it 'replace \n\r to <w:br />' do
74
+ # @mydocx.set('@@hello.text@@', "こんにちは \n world")
75
+ # @mydocx.generate
76
+ # output_mydocx = MyDocx.new('spec/fixtures/output_helloworld.docx')
77
+ # output_mydocx.all_text.join.should include "<w:br />"
78
+ # end
79
+
80
+ it 'doesnt contain \n when replace \n\r to <w:br />' do
81
+ @mydocx.set('@@hello.text@@', "こんにちは \n world")
82
+ @mydocx.generate
83
+ output_mydocx = MyDocx.new('spec/fixtures/output_helloworld.docx')
84
+ output_mydocx.all_text.join.should_not include "\n"
85
+ end
86
+
87
+ it 'does with fax cover template without no word error' do
88
+ @mydocx2 = MyDocx.new('spec/fixtures/Fax_cover_sheet.docx')
89
+ @mydocx2.set('@@memo.text@@', "拝啓 \n お元気ですか。")
90
+ @mydocx2.generate
91
+ output_mydocx2 = MyDocx.new('spec/fixtures/output_Fax_cover_sheet.docx')
92
+ output_mydocx2.all_text.join.should include "拝啓", "お元気ですか"
93
+ end
94
+ end
95
+
96
+ describe ".to_html" do
97
+ it 'contain @@hello@@ before set' do
98
+ html = @mydocx.to_html
99
+ html.should include "@@hello@@"
100
+ end
101
+ it 'contain <div>' do
102
+ html = @mydocx.to_html
103
+ html.should include "<div>"
104
+ end
105
+
106
+ it 'set class with option' do
107
+ html = @mydocx.to_html "myclass"
108
+ html.should include '<div class="myclass">'
109
+ end
110
+ end
111
+ end
112
+
@@ -0,0 +1,11 @@
1
+ require 'simplecov'
2
+ require 'simplecov-vim/formatter'
3
+ require 'codeclimate-test-reporter'
4
+ require 'simple_docx_generator'
5
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
6
+ SimpleCov::Formatter::HTMLFormatter,
7
+ CodeClimate::TestReporter::Formatter
8
+ ]
9
+ SimpleCov.start do
10
+ add_filter '/lib/'
11
+ end
metadata ADDED
@@ -0,0 +1,209 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_docx_generator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.4
5
+ platform: ruby
6
+ authors:
7
+ - seventhsense
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-02-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.8.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.8.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubyzip
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.2.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.2.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: rmagick
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 2.16.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 2.16.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: htmlentities
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 4.3.4
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 4.3.4
69
+ - !ruby/object:Gem::Dependency
70
+ name: ydocx
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 1.2.5
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 1.2.5
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: simplecov-vim
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: codeclimate-test-reporter
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: テンプレートdocxに値を代入して新しいdocxファイルを生成します。
154
+ email:
155
+ - seventh@scimpr.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".gitignore"
161
+ - ".rspec"
162
+ - ".travis.yml"
163
+ - Gemfile
164
+ - LICENSE.txt
165
+ - README.md
166
+ - Rakefile
167
+ - coverage.vim
168
+ - lib/simple_docx_generator.rb
169
+ - lib/simple_docx_generator/mydocx.rb
170
+ - lib/simple_docx_generator/version.rb
171
+ - simple_docx_generator.gemspec
172
+ - spec/fixtures/Fax_cover_sheet.docx
173
+ - spec/fixtures/helloworld.docx
174
+ - spec/fixtures/output_Fax_cover_sheet.docx
175
+ - spec/fixtures/output_helloworld.docx
176
+ - spec/simple_docx_generator/mydocx_spec.rb
177
+ - spec/simple_docx_generator_spec.rb
178
+ - spec/spec_helper.rb
179
+ homepage: ''
180
+ licenses: []
181
+ metadata: {}
182
+ post_install_message:
183
+ rdoc_options: []
184
+ require_paths:
185
+ - lib
186
+ required_ruby_version: !ruby/object:Gem::Requirement
187
+ requirements:
188
+ - - ">="
189
+ - !ruby/object:Gem::Version
190
+ version: '0'
191
+ required_rubygems_version: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - ">="
194
+ - !ruby/object:Gem::Version
195
+ version: '0'
196
+ requirements: []
197
+ rubyforge_project:
198
+ rubygems_version: 2.6.13
199
+ signing_key:
200
+ specification_version: 4
201
+ summary: テンプレートdocxに値を代入して新しいdocxファイルを生成します。
202
+ test_files:
203
+ - spec/fixtures/Fax_cover_sheet.docx
204
+ - spec/fixtures/helloworld.docx
205
+ - spec/fixtures/output_Fax_cover_sheet.docx
206
+ - spec/fixtures/output_helloworld.docx
207
+ - spec/simple_docx_generator/mydocx_spec.rb
208
+ - spec/simple_docx_generator_spec.rb
209
+ - spec/spec_helper.rb