avv2word 1.0.0 → 1.0.4

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: 7933697b51e17a3323bce8bf811072d0dd12551c
4
- data.tar.gz: 217e4cbcd2f30f77694cabdb9709a1e9d0cfb900
3
+ metadata.gz: fdc07474033eaa3627510d65a6cb39e999e52bb2
4
+ data.tar.gz: d86ce9614ba5be66695d6154b1c83748e8b83b8d
5
5
  SHA512:
6
- metadata.gz: 33d2afe64f13b6a10290b8610931d9f400218cc2fe510ad79b7db8e76723bc0af5123e029c9d5b30cd9a3f149735aefab09ae81e35755971777a9e91dd78aeab
7
- data.tar.gz: bb69cb58ef3ca4293aa78b7a5e61030a8ccd7c9d1975f1a4066fff6f980be3e1f638e694aefd3dd105a0651da82e56845aaf75f17738163f9d620abc48c29418
6
+ metadata.gz: b3ab9e21c9d5ac04ff8900391c8f67a62c0660c175cc0b72f7d91e0d5b0c432f911204a6303b95ead3ffad437ac10d8c40830612680bc47530ace40a0581b73b
7
+ data.tar.gz: 56ee60d57d6185d73b7acaae5127f8a010866745a09a357c97422f601a4d142f7bf0c9dd91266fed7c1e21d16a37412a75c9ae8d36757763d6cd1804554773a2
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # Ruby Avvoka Html to word Gem
2
+ The original code was taken from htmltoword gem. Because of need to adapt it to special "avvoka" html it is now being developed as new gem.
2
3
 
3
4
  This simple gem allows you to create MS Word docx documents from Avvoka html documents. This makes it easy to create dynamic reports and forms that can be downloaded by your users as simple MS Word docx files.
4
5
 
@@ -71,6 +71,11 @@ module Avv2word
71
71
  source = entry.get_input_stream.read
72
72
  # Change only the body of document. TODO: Improve this...
73
73
  source = source.sub(/(<w:body>)((.|\n)*?)(<w:sectPr)/, "\\1#{@replaceable_files[entry.name]}\\4")
74
+ # add header and footer only if they really exist
75
+ if entry.name == 'word/document.xml'
76
+ source.sub!('<!--<w:headerReference w:type="default" r:id="rId8"/>-->','<w:headerReference w:type="default" r:id="rId8"/>') if @header
77
+ source.sub!('<!--<w:footerReference w:type="default" r:id="rId9"/>-->','<w:footerReference w:type="default" r:id="rId9"/>') if @footer
78
+ end
74
79
  out.write(source)
75
80
  elsif @replaceable_files[entry.name]
76
81
  out.write(@replaceable_files[entry.name])
@@ -99,9 +104,16 @@ module Avv2word
99
104
 
100
105
  def replace_files(html, extras = false)
101
106
  html = '<body></body>' if html.nil? || html.empty?
107
+
108
+ header_html = (html =~ /(<header>.*?<\/header>)/m ? $1 : '')
109
+ footer_html = (html =~ /(<footer>.*?<\/footer>)/m ? $1 : '')
102
110
  original_source = Nokogiri::HTML(html.gsub(/>\s+</, '><'))
103
- transform_and_replace(original_source, xslt_path('header'), Document.header_xml_file)
104
- transform_and_replace(original_source, xslt_path('footer'), Document.footer_xml_file)
111
+ header = Nokogiri::HTML(header_html.gsub(/>\s+</, '><'))
112
+ footer = Nokogiri::HTML(footer_html.gsub(/>\s+</, '><'))
113
+ @header = (header_html.empty? ? false : true)
114
+ @footer = (footer_html.empty? ? false : true)
115
+ transform_and_replace(header, xslt_path('header'), Document.header_xml_file)
116
+ transform_and_replace(footer, xslt_path('footer'), Document.footer_xml_file)
105
117
  transform_and_replace(original_source, xslt_path('relations'), Document.relations_xml_file)
106
118
  source = xslt(stylesheet_name: 'cleanup').transform(original_source)
107
119
  transform_and_replace(source, xslt_path('numbering'), Document.numbering_xml_file)
Binary file
@@ -1,3 +1,3 @@
1
1
  module Avv2word
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.4'
3
3
  end
@@ -16,8 +16,7 @@
16
16
  exclude-result-prefixes="java msxsl ext w o v WX aml w10"
17
17
  extension-element-prefixes="func">
18
18
  <xsl:output method="xml" encoding="utf-8" omit-xml-declaration="yes" indent="yes" />
19
- <xsl:include href="./functions.xslt"/>
20
- <xsl:include href="./tables.xslt"/>
19
+ <xsl:include href="./base.xslt"/>
21
20
 
22
21
  <xsl:template match="footer">
23
22
  <w:ftr xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas"
@@ -47,78 +46,4 @@
47
46
  </w:ftr>
48
47
  </xsl:template>
49
48
 
50
- <xsl:template match="p[ancestor::footer]">
51
- <w:p>
52
- <xsl:call-template name="text-alignment" />
53
- <xsl:apply-templates />
54
- </w:p>
55
- </xsl:template>
56
-
57
- <xsl:template name="text-alignment">
58
- <xsl:param name="class" select="@class" />
59
- <xsl:param name="style" select="@style" />
60
- <xsl:param name="line-height" select="@line-height" />
61
- <xsl:param name="margin-bottom" select="@margin-bottom" />
62
- <xsl:param name="margin-top" select="@margin-top" />
63
- <xsl:param name="text-indent" select="@text-indent" />
64
- <xsl:param name="text-hanging" select="@text-hanging" />
65
- <xsl:variable name="alignment">
66
- <xsl:choose>
67
- <xsl:when test="contains(concat(' ', $class, ' '), ' center ') or contains(translate(normalize-space($style),' ',''), 'text-align:center')">center</xsl:when>
68
- <xsl:when test="contains(concat(' ', $class, ' '), ' right ') or contains(translate(normalize-space($style),' ',''), 'text-align:right')">right</xsl:when>
69
- <xsl:when test="contains(concat(' ', $class, ' '), ' left ') or contains(translate(normalize-space($style),' ',''), 'text-align:left')">left</xsl:when>
70
- <xsl:when test="contains(concat(' ', $class, ' '), ' justify ') or contains(translate(normalize-space($style),' ',''), 'text-align:justify')">both</xsl:when>
71
- <xsl:otherwise></xsl:otherwise>
72
- </xsl:choose>
73
- </xsl:variable>
74
- <xsl:variable name="indent">
75
- <xsl:choose>
76
- <xsl:when test="$text-indent &gt; 0"><xsl:value-of select="$text-indent"/></xsl:when>
77
- <xsl:otherwise></xsl:otherwise>
78
- </xsl:choose>
79
- </xsl:variable>
80
- <xsl:variable name="hanging">
81
- <xsl:choose>
82
- <xsl:when test="string-length(normalize-space($indent)) > 0 and string-length(normalize-space($text-hanging)) > 0"><xsl:value-of select="$text-hanging"/></xsl:when>
83
- <xsl:when test="string-length(normalize-space($indent)) > 0">0</xsl:when>
84
- <xsl:otherwise></xsl:otherwise>
85
- </xsl:choose>
86
- </xsl:variable>
87
- <xsl:variable name="height">
88
- <xsl:choose>
89
- <xsl:when test="string-length($line-height) > 0"><xsl:value-of select="@line-height"/></xsl:when>
90
- <xsl:otherwise>336</xsl:otherwise>
91
- </xsl:choose>
92
- </xsl:variable>
93
- <xsl:variable name="bottom">
94
- <xsl:choose>
95
- <xsl:when test="string-length($margin-bottom) > 0"><xsl:value-of select="@margin-bottom"/></xsl:when>
96
- <xsl:otherwise>112</xsl:otherwise>
97
- </xsl:choose>
98
- </xsl:variable>
99
- <xsl:variable name="top">
100
- <xsl:choose>
101
- <xsl:when test="string-length($margin-top) > 0"><xsl:value-of select="@margin-top"/></xsl:when>
102
- <xsl:otherwise>0</xsl:otherwise>
103
- </xsl:choose>
104
- </xsl:variable>
105
- <w:pPr>
106
- <w:spacing w:lineRule="atLeast" w:line="{$height}" w:before="{$top}" w:after="{$bottom}"/>
107
- <xsl:choose>
108
- <xsl:when test="string-length(normalize-space($alignment)) > 0 and string-length(normalize-space($indent)) > 0">
109
- <w:ind w:left="{$indent}" w:hanging="{$hanging}"/>
110
- <w:jc w:val="{$alignment}"/>
111
- </xsl:when>
112
- <xsl:when test="string-length(normalize-space($indent)) > 0">
113
- <w:ind w:left="{$indent}" w:hanging="{$hanging}"/>
114
- </xsl:when>
115
- <xsl:when test="string-length(normalize-space($alignment)) > 0">
116
- <w:jc w:val="{$alignment}"/>
117
- </xsl:when>
118
- </xsl:choose>
119
- </w:pPr>
120
- </xsl:template>
121
-
122
- <xsl:template match="*[not(descendant-or-self::footer)]"/>
123
-
124
49
  </xsl:stylesheet>
@@ -16,8 +16,7 @@
16
16
  exclude-result-prefixes="java msxsl ext w o v WX aml w10"
17
17
  extension-element-prefixes="func">
18
18
  <xsl:output method="xml" encoding="utf-8" omit-xml-declaration="yes" indent="yes" />
19
- <xsl:include href="./functions.xslt"/>
20
- <xsl:include href="./tables.xslt"/>
19
+ <xsl:include href="./base.xslt"/>
21
20
 
22
21
  <xsl:template match="header">
23
22
  <w:hdr xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas"
@@ -47,78 +46,4 @@
47
46
  </w:hdr>
48
47
  </xsl:template>
49
48
 
50
- <xsl:template match="p[ancestor::header]">
51
- <w:p>
52
- <xsl:call-template name="text-alignment" />
53
- <xsl:apply-templates />
54
- </w:p>
55
- </xsl:template>
56
-
57
- <xsl:template name="text-alignment">
58
- <xsl:param name="class" select="@class" />
59
- <xsl:param name="style" select="@style" />
60
- <xsl:param name="line-height" select="@line-height" />
61
- <xsl:param name="margin-bottom" select="@margin-bottom" />
62
- <xsl:param name="margin-top" select="@margin-top" />
63
- <xsl:param name="text-indent" select="@text-indent" />
64
- <xsl:param name="text-hanging" select="@text-hanging" />
65
- <xsl:variable name="alignment">
66
- <xsl:choose>
67
- <xsl:when test="contains(concat(' ', $class, ' '), ' center ') or contains(translate(normalize-space($style),' ',''), 'text-align:center')">center</xsl:when>
68
- <xsl:when test="contains(concat(' ', $class, ' '), ' right ') or contains(translate(normalize-space($style),' ',''), 'text-align:right')">right</xsl:when>
69
- <xsl:when test="contains(concat(' ', $class, ' '), ' left ') or contains(translate(normalize-space($style),' ',''), 'text-align:left')">left</xsl:when>
70
- <xsl:when test="contains(concat(' ', $class, ' '), ' justify ') or contains(translate(normalize-space($style),' ',''), 'text-align:justify')">both</xsl:when>
71
- <xsl:otherwise></xsl:otherwise>
72
- </xsl:choose>
73
- </xsl:variable>
74
- <xsl:variable name="indent">
75
- <xsl:choose>
76
- <xsl:when test="$text-indent &gt; 0"><xsl:value-of select="$text-indent"/></xsl:when>
77
- <xsl:otherwise></xsl:otherwise>
78
- </xsl:choose>
79
- </xsl:variable>
80
- <xsl:variable name="hanging">
81
- <xsl:choose>
82
- <xsl:when test="string-length(normalize-space($indent)) > 0 and string-length(normalize-space($text-hanging)) > 0"><xsl:value-of select="$text-hanging"/></xsl:when>
83
- <xsl:when test="string-length(normalize-space($indent)) > 0">0</xsl:when>
84
- <xsl:otherwise></xsl:otherwise>
85
- </xsl:choose>
86
- </xsl:variable>
87
- <xsl:variable name="height">
88
- <xsl:choose>
89
- <xsl:when test="string-length($line-height) > 0"><xsl:value-of select="@line-height"/></xsl:when>
90
- <xsl:otherwise>336</xsl:otherwise>
91
- </xsl:choose>
92
- </xsl:variable>
93
- <xsl:variable name="bottom">
94
- <xsl:choose>
95
- <xsl:when test="string-length($margin-bottom) > 0"><xsl:value-of select="@margin-bottom"/></xsl:when>
96
- <xsl:otherwise>112</xsl:otherwise>
97
- </xsl:choose>
98
- </xsl:variable>
99
- <xsl:variable name="top">
100
- <xsl:choose>
101
- <xsl:when test="string-length($margin-top) > 0"><xsl:value-of select="@margin-top"/></xsl:when>
102
- <xsl:otherwise>0</xsl:otherwise>
103
- </xsl:choose>
104
- </xsl:variable>
105
- <w:pPr>
106
- <w:spacing w:lineRule="atLeast" w:line="{$height}" w:before="{$top}" w:after="{$bottom}"/>
107
- <xsl:choose>
108
- <xsl:when test="string-length(normalize-space($alignment)) > 0 and string-length(normalize-space($indent)) > 0">
109
- <w:ind w:left="{$indent}" w:hanging="{$hanging}"/>
110
- <w:jc w:val="{$alignment}"/>
111
- </xsl:when>
112
- <xsl:when test="string-length(normalize-space($indent)) > 0">
113
- <w:ind w:left="{$indent}" w:hanging="{$hanging}"/>
114
- </xsl:when>
115
- <xsl:when test="string-length(normalize-space($alignment)) > 0">
116
- <w:jc w:val="{$alignment}"/>
117
- </xsl:when>
118
- </xsl:choose>
119
- </w:pPr>
120
- </xsl:template>
121
-
122
- <xsl:template match="*[not(descendant-or-self::header)]"/>
123
-
124
49
  </xsl:stylesheet>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avv2word
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marián Bilas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-12 00:00:00.000000000 Z
11
+ date: 2018-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -141,6 +141,7 @@ files:
141
141
  - lib/avv2word/railtie.rb
142
142
  - lib/avv2word/renderer.rb
143
143
  - lib/avv2word/templates/default.docx
144
+ - lib/avv2word/templates/default2.docx
144
145
  - lib/avv2word/version.rb
145
146
  - lib/avv2word/xslt/base.xslt
146
147
  - lib/avv2word/xslt/cleanup.xslt