htmltoword 0.4.2 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -0
- data/bin/htmltoword +1 -3
- data/lib/htmltoword/document.rb +6 -0
- data/lib/htmltoword/templates/default.docx +0 -0
- data/lib/htmltoword/version.rb +1 -1
- data/lib/htmltoword/xslt/base.xslt +26 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: befba72eb576d39090834848e2d36f81a89eb55f
|
4
|
+
data.tar.gz: c10496fa4f4a07f6a0ef22ded7f3fede7a5be334
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d859816964b95338f9396118e02316406efaa921a50c522314ddb836af6b0ff29f15fa3eda2c46649bca055f3d6afcffaabf5281236cd7851fe2a424315b0f7f
|
7
|
+
data.tar.gz: e7e58429b762efb32c24ab52fbcbe0148ab78f339c5d350d1feeef2154cfa5aa35526e4ecd1446ce15e7e05c9807b038b3496827ff58461a355e98d05afaca6a
|
data/README.md
CHANGED
@@ -14,16 +14,23 @@ Or install it yourself as:
|
|
14
14
|
|
15
15
|
$ gem install htmltoword
|
16
16
|
|
17
|
+
|
18
|
+
** Note: ** Since version 0.4.0 the ```create``` method will return a string with the contents of the file. If you want to save the file please use ```create_and_save```. See the usage for more
|
19
|
+
|
17
20
|
## Usage
|
18
21
|
|
19
22
|
### Standalone
|
20
23
|
|
24
|
+
By default, the file will be saved at the specified location. In case you want to handle the contents of the file
|
25
|
+
as a string and do what suits you best, you can specify that when calling the create function.
|
26
|
+
|
21
27
|
Using the default word file as template
|
22
28
|
```ruby
|
23
29
|
require 'htmltoword'
|
24
30
|
|
25
31
|
my_html = '<html><head></head><body><p>Hello</p></body></html>'
|
26
32
|
document = Htmltoword::Document.create(my_html)
|
33
|
+
file = Htmltoword::Document.create_and_save(my_html, file_path)
|
27
34
|
```
|
28
35
|
|
29
36
|
Using your custom word file as a template, where you can setup your own style for normal text, h1,h2, etc.
|
@@ -35,8 +42,12 @@ Htmltoword.config.custom_templates_path = 'some_path'
|
|
35
42
|
|
36
43
|
my_html = '<html><head></head><body><p>Hello</p></body></html>'
|
37
44
|
document = Htmltoword::Document.create(my_html, word_template_file_name)
|
45
|
+
file = Htmltoword::Document.create_and_save(my_html, file_path, word_template_file_name)
|
38
46
|
```
|
39
47
|
|
48
|
+
The ```create``` function will return a string with the file, so you can do with it what you consider best.
|
49
|
+
The ```create_and_save``` function will create the file in the specified file_path.
|
50
|
+
|
40
51
|
### With Rails
|
41
52
|
**For htmltoword version >= 0.2**
|
42
53
|
An action controller renderer has been defined, so there's no need to declare the mime-type and you can just respond to .docx format. It will look then for views with the extension ```.docx.erb``` which will provide the HTML that will be rendered in the Word file.
|
data/bin/htmltoword
CHANGED
@@ -12,9 +12,7 @@ main do |input, output|
|
|
12
12
|
if options[:format] == 'markdown'
|
13
13
|
markup = markdown2html(markup)
|
14
14
|
end
|
15
|
-
|
16
|
-
out << Htmltoword::Document.create(markup, options[:template_name], options[:extras])
|
17
|
-
end
|
15
|
+
Htmltoword::Document.create_and_save(markup, output, options[:template_name], options[:extras])
|
18
16
|
puts "Done" if options[:verbose]
|
19
17
|
end
|
20
18
|
|
data/lib/htmltoword/document.rb
CHANGED
@@ -10,6 +10,12 @@ module Htmltoword
|
|
10
10
|
document.generate
|
11
11
|
end
|
12
12
|
|
13
|
+
def create_and_save(content, file_path, template_name = nil, extras = false)
|
14
|
+
File.open(file_path, "wb") do |out|
|
15
|
+
out << create(content, template_name, extras)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
13
19
|
def create_with_content(template, content, set=nil, extras = false)
|
14
20
|
template += extension unless template.end_with?(extension)
|
15
21
|
content = replace_values(content, set) if set
|
Binary file
|
data/lib/htmltoword/version.rb
CHANGED
@@ -49,20 +49,34 @@
|
|
49
49
|
</w:p>
|
50
50
|
</xsl:template>
|
51
51
|
|
52
|
-
|
53
|
-
|
52
|
+
|
53
|
+
<xsl:template match="br[not(ancestor::p) and not(ancestor::div) and not(name(..)='td') and not(name(..)='li') or
|
54
|
+
(preceding-sibling::div or following-sibling::div or preceding-sibling::p or following-sibling::p)]">
|
54
55
|
<w:p>
|
55
56
|
<w:r></w:r>
|
56
57
|
</w:p>
|
57
58
|
</xsl:template>
|
58
59
|
|
60
|
+
<xsl:template match="br[(name(..)='li' or name(..)='td') and
|
61
|
+
(preceding-sibling::div or following-sibling::div or preceding-sibling::p or following-sibling::p)]">
|
62
|
+
<w:r>
|
63
|
+
<w:br />
|
64
|
+
</w:r>
|
65
|
+
</xsl:template>
|
66
|
+
|
59
67
|
<xsl:template match="br">
|
60
68
|
<w:r>
|
61
69
|
<w:br />
|
62
70
|
</w:r>
|
63
71
|
</xsl:template>
|
64
72
|
|
65
|
-
<xsl:template match="
|
73
|
+
<xsl:template match="pre">
|
74
|
+
<w:p>
|
75
|
+
<xsl:apply-templates />
|
76
|
+
</w:p>
|
77
|
+
</xsl:template>
|
78
|
+
|
79
|
+
<xsl:template match="div[not(ancestor::li) and not(ancestor::td) and not(ancestor::th) and not(ancestor::p) and not(descendant::div) and not(descendant::p) and not(descendant::h1) and not(descendant::h2) and not(descendant::h3) and not(descendant::h4) and not(descendant::h5) and not(descendant::h6) and not(descendant::table) and not(descendant::li) and not (descendant::pre)]">
|
66
80
|
<xsl:comment>Divs should create a p if nothing above them has and nothing below them will</xsl:comment>
|
67
81
|
<w:p>
|
68
82
|
<xsl:call-template name="text-alignment" />
|
@@ -122,14 +136,14 @@
|
|
122
136
|
</xsl:apply-templates>
|
123
137
|
</xsl:template>
|
124
138
|
|
125
|
-
<xsl:template match="span[not(ancestor::td) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]
|
126
|
-
|a[not(ancestor::td) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]
|
127
|
-
|small[not(ancestor::td) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]
|
128
|
-
|strong[not(ancestor::td) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]
|
129
|
-
|em[not(ancestor::td) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]
|
130
|
-
|i[not(ancestor::td) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]
|
131
|
-
|b[not(ancestor::td) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]
|
132
|
-
|u[not(ancestor::td) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]">
|
139
|
+
<xsl:template match="span[not(ancestor::td) and not(ancestor::li) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]
|
140
|
+
|a[not(ancestor::td) and not(ancestor::li) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]
|
141
|
+
|small[not(ancestor::td) and not(ancestor::li) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]
|
142
|
+
|strong[not(ancestor::td) and not(ancestor::li) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]
|
143
|
+
|em[not(ancestor::td) and not(ancestor::li) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]
|
144
|
+
|i[not(ancestor::td) and not(ancestor::li) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]
|
145
|
+
|b[not(ancestor::td) and not(ancestor::li) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]
|
146
|
+
|u[not(ancestor::td) and not(ancestor::li) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]">
|
133
147
|
<xsl:comment>
|
134
148
|
In the following situation:
|
135
149
|
|
@@ -148,7 +162,7 @@
|
|
148
162
|
</w:p>
|
149
163
|
</xsl:template>
|
150
164
|
|
151
|
-
<xsl:template match="text()[not(parent::li) and not(parent::td) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]">
|
165
|
+
<xsl:template match="text()[not(parent::li) and not(parent::td) and not(parent::pre) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]">
|
152
166
|
<xsl:comment>
|
153
167
|
In the following situation:
|
154
168
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: htmltoword
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicholas Frandsen, Cristina Matonte
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|