caracal 1.0.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/CHANGELOG.md +95 -5
- data/README.md +171 -35
- data/caracal.gemspec +4 -4
- data/lib/caracal/core/custom_properties.rb +49 -0
- data/lib/caracal/core/iframes.rb +42 -0
- data/lib/caracal/core/ignorables.rb +47 -0
- data/lib/caracal/core/models/custom_property_model.rb +60 -0
- data/lib/caracal/core/models/iframe_model.rb +148 -0
- data/lib/caracal/core/models/namespace_model.rb +65 -0
- data/lib/caracal/core/models/page_break_model.rb +50 -4
- data/lib/caracal/core/models/page_number_model.rb +50 -24
- data/lib/caracal/core/models/page_size_model.rb +34 -25
- data/lib/caracal/core/models/paragraph_model.rb +11 -4
- data/lib/caracal/core/models/style_model.rb +44 -15
- data/lib/caracal/core/models/table_cell_model.rb +61 -50
- data/lib/caracal/core/models/table_model.rb +1 -1
- data/lib/caracal/core/models/text_model.rb +42 -20
- data/lib/caracal/core/namespaces.rb +89 -0
- data/lib/caracal/core/page_numbers.rb +22 -16
- data/lib/caracal/core/page_settings.rb +18 -16
- data/lib/caracal/document.rb +75 -58
- data/lib/caracal/renderers/content_types_renderer.rb +18 -17
- data/lib/caracal/renderers/core_renderer.rb +1 -1
- data/lib/caracal/renderers/custom_renderer.rb +64 -0
- data/lib/caracal/renderers/document_renderer.rb +205 -118
- data/lib/caracal/renderers/fonts_renderer.rb +2 -2
- data/lib/caracal/renderers/footer_renderer.rb +41 -20
- data/lib/caracal/renderers/numbering_renderer.rb +27 -26
- data/lib/caracal/renderers/package_relationships_renderer.rb +14 -13
- data/lib/caracal/renderers/settings_renderer.rb +5 -5
- data/lib/caracal/renderers/styles_renderer.rb +88 -73
- data/lib/caracal/renderers/xml_renderer.rb +20 -20
- data/lib/caracal/version.rb +1 -1
- data/lib/caracal.rb +11 -2
- data/spec/lib/caracal/core/iframes_spec.rb +29 -0
- data/spec/lib/caracal/core/ignorables_spec.rb +79 -0
- data/spec/lib/caracal/core/models/iframe_model_spec.rb +83 -0
- data/spec/lib/caracal/core/models/image_model_spec.rb +60 -62
- data/spec/lib/caracal/core/models/link_model_spec.rb +12 -11
- data/spec/lib/caracal/core/models/namespace_model_spec.rb +107 -0
- data/spec/lib/caracal/core/models/page_number_model_spec.rb +66 -31
- data/spec/lib/caracal/core/models/page_size_model_spec.rb +42 -32
- data/spec/lib/caracal/core/models/style_model_spec.rb +32 -1
- data/spec/lib/caracal/core/models/table_cell_model_spec.rb +10 -1
- data/spec/lib/caracal/core/models/text_model_spec.rb +18 -10
- data/spec/lib/caracal/core/namespaces_spec.rb +116 -0
- data/spec/lib/caracal/core/page_numbers_spec.rb +32 -23
- data/spec/lib/caracal/core/page_settings_spec.rb +33 -25
- data/spec/lib/caracal/core/relationships_spec.rb +47 -47
- data/spec/support/_fixtures/snippet.docx +0 -0
- metadata +28 -8
|
@@ -17,9 +17,9 @@ module Caracal
|
|
|
17
17
|
#
|
|
18
18
|
def to_xml
|
|
19
19
|
builder = ::Nokogiri::XML::Builder.with(declaration_xml) do |xml|
|
|
20
|
-
xml
|
|
21
|
-
xml
|
|
22
|
-
xml
|
|
20
|
+
xml['w'].document root_options do
|
|
21
|
+
xml['w'].background({ 'w:color' => 'FFFFFF' })
|
|
22
|
+
xml['w'].body do
|
|
23
23
|
|
|
24
24
|
#============= CONTENTS ===================================
|
|
25
25
|
|
|
@@ -30,14 +30,14 @@ module Caracal
|
|
|
30
30
|
|
|
31
31
|
#============= PAGE SETTINGS ==============================
|
|
32
32
|
|
|
33
|
-
xml
|
|
33
|
+
xml['w'].sectPr do
|
|
34
34
|
if document.page_number_show
|
|
35
35
|
if rel = document.find_relationship('footer1.xml')
|
|
36
|
-
xml
|
|
36
|
+
xml['w'].footerReference({ 'r:id' => rel.formatted_id, 'w:type' => 'default' })
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
|
-
xml
|
|
40
|
-
xml
|
|
39
|
+
xml['w'].pgSz page_size_options
|
|
40
|
+
xml['w'].pgMar page_margin_options
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
end
|
|
@@ -73,21 +73,22 @@ module Caracal
|
|
|
73
73
|
if paragraph_level && attrs.empty?
|
|
74
74
|
# skip
|
|
75
75
|
else
|
|
76
|
-
xml
|
|
76
|
+
xml['w'].rPr do
|
|
77
77
|
unless attrs.empty?
|
|
78
|
-
xml
|
|
79
|
-
xml
|
|
80
|
-
xml
|
|
81
|
-
xml
|
|
82
|
-
xml
|
|
83
|
-
xml
|
|
84
|
-
xml
|
|
78
|
+
xml['w'].rStyle( { 'w:val' => attrs[:style] }) unless attrs[:style].nil?
|
|
79
|
+
xml['w'].color( { 'w:val' => attrs[:color] }) unless attrs[:color].nil?
|
|
80
|
+
xml['w'].sz( { 'w:val' => attrs[:size] }) unless attrs[:size].nil?
|
|
81
|
+
xml['w'].b( { 'w:val' => (attrs[:bold] ? '1' : '0') }) unless attrs[:bold].nil?
|
|
82
|
+
xml['w'].i( { 'w:val' => (attrs[:italic] ? '1' : '0') }) unless attrs[:italic].nil?
|
|
83
|
+
xml['w'].u( { 'w:val' => (attrs[:underline] ? 'single' : 'none') }) unless attrs[:underline].nil?
|
|
84
|
+
xml['w'].shd( { 'w:fill' => attrs[:bgcolor], 'w:val' => 'clear' }) unless attrs[:bgcolor].nil?
|
|
85
|
+
xml['w'].vertAlign( { 'w:val' => attrs[:vertical_align] }) unless attrs[:vertical_align].nil?
|
|
85
86
|
unless attrs[:font].nil?
|
|
86
87
|
f = attrs[:font]
|
|
87
|
-
xml
|
|
88
|
+
xml['w'].rFonts( { 'w:ascii' => f, 'w:hAnsi' => f, 'w:eastAsia' => f, 'w:cs' => f })
|
|
88
89
|
end
|
|
89
90
|
end
|
|
90
|
-
xml
|
|
91
|
+
xml['w'].rtl({ 'w:val' => '0' })
|
|
91
92
|
end
|
|
92
93
|
end
|
|
93
94
|
end
|
|
@@ -96,6 +97,40 @@ module Caracal
|
|
|
96
97
|
|
|
97
98
|
#============= MODEL RENDERERS ===========================
|
|
98
99
|
|
|
100
|
+
def render_iframe(xml, model)
|
|
101
|
+
::Zip::File.open(model.file) do |zip|
|
|
102
|
+
a_href = 'http://schemas.openxmlformats.org/drawingml/2006/main'
|
|
103
|
+
pic_href = 'http://schemas.openxmlformats.org/drawingml/2006/picture'
|
|
104
|
+
r_href = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'
|
|
105
|
+
|
|
106
|
+
entry = zip.glob('word/document.xml').first
|
|
107
|
+
content = entry.get_input_stream.read
|
|
108
|
+
doc_xml = Nokogiri::XML(content)
|
|
109
|
+
|
|
110
|
+
fragment = doc_xml.xpath('//w:body').first.children
|
|
111
|
+
fragment.pop
|
|
112
|
+
|
|
113
|
+
model.relationships.each do |r_hash|
|
|
114
|
+
id = r_hash.delete(:id) # we can't update the fragment until
|
|
115
|
+
model = document.relationship(r_hash) # the parent document assigns the embedded
|
|
116
|
+
index = model.relationship_id # relationship an id.
|
|
117
|
+
|
|
118
|
+
r_node = fragment.at_xpath("//a:blip[@r:embed='#{ id }']", { a: a_href, r: r_href })
|
|
119
|
+
if r_attr = r_node.attributes['embed']
|
|
120
|
+
r_attr.value = "rId#{ index }"
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
p_parent = r_node.parent.parent
|
|
124
|
+
p_node = p_parent.children[0].children[0]
|
|
125
|
+
if p_attr = p_node.attributes['id']
|
|
126
|
+
p_attr.value = index.to_s
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
xml << fragment.to_s
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
99
134
|
def render_image(xml, model)
|
|
100
135
|
unless ds = document.default_style
|
|
101
136
|
raise Caracal::Errors::NoDefaultStyleError 'Document must declare a default paragraph style.'
|
|
@@ -105,39 +140,39 @@ module Caracal
|
|
|
105
140
|
rel_id = rel.relationship_id
|
|
106
141
|
rel_name = rel.formatted_target
|
|
107
142
|
|
|
108
|
-
xml
|
|
109
|
-
xml
|
|
110
|
-
xml
|
|
111
|
-
xml
|
|
112
|
-
xml
|
|
113
|
-
xml
|
|
143
|
+
xml['w'].p paragraph_options do
|
|
144
|
+
xml['w'].pPr do
|
|
145
|
+
xml['w'].spacing({ 'w:lineRule' => 'auto', 'w:line' => ds.style_line })
|
|
146
|
+
xml['w'].contextualSpacing({ 'w:val' => '0' })
|
|
147
|
+
xml['w'].jc({ 'w:val' => model.image_align.to_s })
|
|
148
|
+
xml['w'].rPr
|
|
114
149
|
end
|
|
115
|
-
xml
|
|
116
|
-
xml
|
|
117
|
-
xml
|
|
118
|
-
xml
|
|
119
|
-
xml
|
|
120
|
-
xml
|
|
121
|
-
xml
|
|
122
|
-
xml
|
|
123
|
-
xml
|
|
124
|
-
xml
|
|
125
|
-
xml
|
|
126
|
-
xml
|
|
150
|
+
xml['w'].r run_options do
|
|
151
|
+
xml['w'].drawing do
|
|
152
|
+
xml['wp'].inline({ distR: model.formatted_right, distT: model.formatted_top, distB: model.formatted_bottom, distL: model.formatted_left }) do
|
|
153
|
+
xml['wp'].extent({ cx: model.formatted_width, cy: model.formatted_height })
|
|
154
|
+
xml['wp'].effectExtent({ t: 0, b: 0, r: 0, l: 0 })
|
|
155
|
+
xml['wp'].docPr({ id: rel_id, name: rel_name })
|
|
156
|
+
xml['a'].graphic do
|
|
157
|
+
xml['a'].graphicData({ uri: 'http://schemas.openxmlformats.org/drawingml/2006/picture' }) do
|
|
158
|
+
xml['pic'].pic do
|
|
159
|
+
xml['pic'].nvPicPr do
|
|
160
|
+
xml['pic'].cNvPr({ id: rel_id, name: rel_name })
|
|
161
|
+
xml['pic'].cNvPicPr
|
|
127
162
|
end
|
|
128
|
-
xml
|
|
129
|
-
xml
|
|
130
|
-
xml
|
|
131
|
-
xml
|
|
132
|
-
xml
|
|
163
|
+
xml['pic'].blipFill do
|
|
164
|
+
xml['a'].blip({ 'r:embed' => rel.formatted_id })
|
|
165
|
+
xml['a'].srcRect
|
|
166
|
+
xml['a'].stretch do
|
|
167
|
+
xml['a'].fillRect
|
|
133
168
|
end
|
|
134
169
|
end
|
|
135
|
-
xml
|
|
136
|
-
xml
|
|
137
|
-
xml
|
|
170
|
+
xml['pic'].spPr do
|
|
171
|
+
xml['a'].xfrm do
|
|
172
|
+
xml['a'].ext({ cx: model.formatted_width, cy: model.formatted_height })
|
|
138
173
|
end
|
|
139
|
-
xml
|
|
140
|
-
xml
|
|
174
|
+
xml['a'].prstGeom({ prst: 'rect' })
|
|
175
|
+
xml['a'].ln
|
|
141
176
|
end
|
|
142
177
|
end
|
|
143
178
|
end
|
|
@@ -145,27 +180,27 @@ module Caracal
|
|
|
145
180
|
end
|
|
146
181
|
end
|
|
147
182
|
end
|
|
148
|
-
xml
|
|
149
|
-
xml
|
|
150
|
-
xml
|
|
183
|
+
xml['w'].r run_options do
|
|
184
|
+
xml['w'].rPr do
|
|
185
|
+
xml['w'].rtl({ 'w:val' => '0' })
|
|
151
186
|
end
|
|
152
187
|
end
|
|
153
188
|
end
|
|
154
189
|
end
|
|
155
190
|
|
|
156
191
|
def render_linebreak(xml, model)
|
|
157
|
-
xml
|
|
158
|
-
xml
|
|
192
|
+
xml['w'].r do
|
|
193
|
+
xml['w'].br
|
|
159
194
|
end
|
|
160
195
|
end
|
|
161
196
|
|
|
162
197
|
def render_link(xml, model)
|
|
163
198
|
rel = document.relationship({ target: model.link_href, type: :link })
|
|
164
199
|
|
|
165
|
-
xml
|
|
166
|
-
xml
|
|
200
|
+
xml['w'].hyperlink({ 'r:id' => rel.formatted_id }) do
|
|
201
|
+
xml['w'].r run_options do
|
|
167
202
|
render_run_attributes(xml, model, false)
|
|
168
|
-
xml
|
|
203
|
+
xml['w'].t({ 'xml:space' => 'preserve' }, model.link_content)
|
|
169
204
|
end
|
|
170
205
|
end
|
|
171
206
|
end
|
|
@@ -185,16 +220,16 @@ module Caracal
|
|
|
185
220
|
ls = document.find_list_style(model.list_item_type, model.list_item_level)
|
|
186
221
|
hanging = ls.style_left.to_i - ls.style_indent.to_i - 1
|
|
187
222
|
|
|
188
|
-
xml
|
|
189
|
-
xml
|
|
190
|
-
xml
|
|
191
|
-
xml
|
|
192
|
-
xml
|
|
223
|
+
xml['w'].p paragraph_options do
|
|
224
|
+
xml['w'].pPr do
|
|
225
|
+
xml['w'].numPr do
|
|
226
|
+
xml['w'].ilvl({ 'w:val' => model.list_item_level })
|
|
227
|
+
xml['w'].numId({ 'w:val' => list_num })
|
|
193
228
|
end
|
|
194
|
-
xml
|
|
195
|
-
xml
|
|
196
|
-
xml
|
|
197
|
-
xml
|
|
229
|
+
xml['w'].ind({ 'w:left' => ls.style_left, 'w:hanging' => hanging })
|
|
230
|
+
xml['w'].contextualSpacing({ 'w:val' => '1' })
|
|
231
|
+
xml['w'].rPr do
|
|
232
|
+
xml['w'].u({ 'w:val' => 'none' })
|
|
198
233
|
end
|
|
199
234
|
end
|
|
200
235
|
model.runs.each do |run|
|
|
@@ -205,9 +240,15 @@ module Caracal
|
|
|
205
240
|
end
|
|
206
241
|
|
|
207
242
|
def render_pagebreak(xml, model)
|
|
208
|
-
|
|
209
|
-
xml
|
|
210
|
-
xml
|
|
243
|
+
if model.page_break_wrap
|
|
244
|
+
xml['w'].p paragraph_options do
|
|
245
|
+
xml['w'].r run_options do
|
|
246
|
+
xml['w'].br({ 'w:type' => 'page' })
|
|
247
|
+
end
|
|
248
|
+
end
|
|
249
|
+
else
|
|
250
|
+
xml['w'].r run_options do
|
|
251
|
+
xml['w'].br({ 'w:type' => 'page' })
|
|
211
252
|
end
|
|
212
253
|
end
|
|
213
254
|
end
|
|
@@ -215,11 +256,11 @@ module Caracal
|
|
|
215
256
|
def render_paragraph(xml, model)
|
|
216
257
|
run_props = [:color, :size, :bold, :italic, :underline].map { |m| model.send("paragraph_#{ m }") }.compact
|
|
217
258
|
|
|
218
|
-
xml
|
|
219
|
-
xml
|
|
220
|
-
xml
|
|
221
|
-
xml
|
|
222
|
-
xml
|
|
259
|
+
xml['w'].p paragraph_options do
|
|
260
|
+
xml['w'].pPr do
|
|
261
|
+
xml['w'].pStyle({ 'w:val' => model.paragraph_style }) unless model.paragraph_style.nil?
|
|
262
|
+
xml['w'].contextualSpacing({ 'w:val' => '0' })
|
|
263
|
+
xml['w'].jc({ 'w:val' => model.paragraph_align }) unless model.paragraph_align.nil?
|
|
223
264
|
render_run_attributes(xml, model, true)
|
|
224
265
|
end
|
|
225
266
|
model.runs.each do |run|
|
|
@@ -232,19 +273,19 @@ module Caracal
|
|
|
232
273
|
def render_rule(xml, model)
|
|
233
274
|
options = { 'w:color' => model.rule_color, 'w:sz' => model.rule_size, 'w:val' => model.rule_line, 'w:space' => model.rule_spacing }
|
|
234
275
|
|
|
235
|
-
xml
|
|
236
|
-
xml
|
|
237
|
-
xml
|
|
238
|
-
xml
|
|
276
|
+
xml['w'].p paragraph_options do
|
|
277
|
+
xml['w'].pPr do
|
|
278
|
+
xml['w'].pBdr do
|
|
279
|
+
xml['w'].top options
|
|
239
280
|
end
|
|
240
281
|
end
|
|
241
282
|
end
|
|
242
283
|
end
|
|
243
284
|
|
|
244
285
|
def render_text(xml, model)
|
|
245
|
-
xml
|
|
286
|
+
xml['w'].r run_options do
|
|
246
287
|
render_run_attributes(xml, model, false)
|
|
247
|
-
xml
|
|
288
|
+
xml['w'].t({ 'xml:space' => 'preserve' }, model.text_content)
|
|
248
289
|
end
|
|
249
290
|
end
|
|
250
291
|
|
|
@@ -253,15 +294,15 @@ module Caracal
|
|
|
253
294
|
model.send("table_border_#{ m }_size") > 0
|
|
254
295
|
end
|
|
255
296
|
|
|
256
|
-
xml
|
|
257
|
-
xml
|
|
258
|
-
xml
|
|
259
|
-
xml
|
|
260
|
-
xml
|
|
261
|
-
xml
|
|
262
|
-
xml
|
|
297
|
+
xml['w'].tbl do
|
|
298
|
+
xml['w'].tblPr do
|
|
299
|
+
xml['w'].tblStyle({ 'w:val' => 'DefaultTable' })
|
|
300
|
+
xml['w'].bidiVisual({ 'w:val' => '0' })
|
|
301
|
+
xml['w'].tblW({ 'w:w' => model.table_width.to_f, 'w:type' => 'dxa' })
|
|
302
|
+
xml['w'].tblInd({ 'w:w' => '0.0', 'w:type' => 'dxa' })
|
|
303
|
+
xml['w'].jc({ 'w:val' => model.table_align })
|
|
263
304
|
unless borders.empty?
|
|
264
|
-
xml
|
|
305
|
+
xml['w'].tblBorders do
|
|
265
306
|
borders.each do |m|
|
|
266
307
|
options = {
|
|
267
308
|
'w:color' => model.send("table_border_#{ m }_color"),
|
|
@@ -269,34 +310,54 @@ module Caracal
|
|
|
269
310
|
'w:sz' => model.send("table_border_#{ m }_size"),
|
|
270
311
|
'w:space' => model.send("table_border_#{ m }_spacing")
|
|
271
312
|
}
|
|
272
|
-
xml.
|
|
313
|
+
xml['w'].method_missing "#{ Caracal::Core::Models::BorderModel.formatted_type(m) }", options
|
|
273
314
|
end
|
|
274
315
|
end
|
|
275
316
|
end
|
|
276
|
-
xml
|
|
277
|
-
xml
|
|
317
|
+
xml['w'].tblLayout({ 'w:type' => 'fixed' })
|
|
318
|
+
xml['w'].tblLook({ 'w:val' => '0600' })
|
|
278
319
|
end
|
|
279
|
-
xml
|
|
320
|
+
xml['w'].tblGrid do
|
|
280
321
|
model.rows.first.each do |tc|
|
|
281
|
-
|
|
322
|
+
(tc.cell_colspan || 1).times do
|
|
323
|
+
xml['w'].gridCol({ 'w:w' => tc.cell_width })
|
|
324
|
+
end
|
|
282
325
|
end
|
|
283
|
-
xml
|
|
284
|
-
xml
|
|
326
|
+
xml['w'].tblGridChange({ 'w:id' => '0' }) do
|
|
327
|
+
xml['w'].tblGrid do
|
|
285
328
|
model.rows.first.each do |tc|
|
|
286
|
-
|
|
329
|
+
(tc.cell_colspan || 1).times do
|
|
330
|
+
xml['w'].gridCol({ 'w:w' => tc.cell_width })
|
|
331
|
+
end
|
|
287
332
|
end
|
|
288
333
|
end
|
|
289
334
|
end
|
|
290
335
|
end
|
|
336
|
+
|
|
337
|
+
rowspan_hash = {}
|
|
291
338
|
model.rows.each do |row|
|
|
292
|
-
xml
|
|
293
|
-
row.
|
|
294
|
-
xml
|
|
295
|
-
xml.
|
|
296
|
-
xml
|
|
297
|
-
xml.
|
|
339
|
+
xml['w'].tr do
|
|
340
|
+
row.each_with_index do |tc, tc_index|
|
|
341
|
+
xml['w'].tc do
|
|
342
|
+
xml['w'].tcPr do
|
|
343
|
+
xml['w'].shd({ 'w:fill' => tc.cell_background })
|
|
344
|
+
xml['w'].vAlign({ 'w:val' => tc.cell_vertical_align })
|
|
345
|
+
|
|
346
|
+
# applying rowspan
|
|
347
|
+
if tc.cell_rowspan && tc.cell_rowspan > 0
|
|
348
|
+
rowspan_hash[tc_index] = tc.cell_rowspan - 1
|
|
349
|
+
xml['w'].vMerge({ 'w:val' => 'restart' })
|
|
350
|
+
elsif rowspan_hash[tc_index] && rowspan_hash[tc_index] > 0
|
|
351
|
+
xml['w'].vMerge({ 'w:val' => 'continue' })
|
|
352
|
+
rowspan_hash[tc_index] -= 1
|
|
353
|
+
end
|
|
354
|
+
|
|
355
|
+
# applying colspan
|
|
356
|
+
xml['w'].gridSpan({ 'w:val' => tc.cell_colspan }) if tc.cell_colspan
|
|
357
|
+
|
|
358
|
+
xml['w'].tcMar do
|
|
298
359
|
%w(top left bottom right).each do |d|
|
|
299
|
-
xml.
|
|
360
|
+
xml['w'].method_missing "#{ d }", { 'w:w' => tc.send("cell_margin_#{ d }").to_f, 'w:type' => 'dxa' }
|
|
300
361
|
end
|
|
301
362
|
end
|
|
302
363
|
end
|
|
@@ -307,6 +368,22 @@ module Caracal
|
|
|
307
368
|
end
|
|
308
369
|
end
|
|
309
370
|
end
|
|
371
|
+
|
|
372
|
+
# we need to adjust rowspan indexes as they depend on previous row colspans
|
|
373
|
+
adjusted_rowspan_hash = {}
|
|
374
|
+
rowspan_hash.each do |rowspan_cell_index, rowspan_value|
|
|
375
|
+
adjusted_rowspan_cell_index = rowspan_cell_index
|
|
376
|
+
row.each_with_index do |tc, tc_index|
|
|
377
|
+
if tc.cell_colspan && tc.cell_colspan >= 1
|
|
378
|
+
if tc_index < rowspan_cell_index
|
|
379
|
+
adjusted_rowspan_cell_index += tc.cell_colspan - 1
|
|
380
|
+
end
|
|
381
|
+
end
|
|
382
|
+
end
|
|
383
|
+
adjusted_rowspan_hash[adjusted_rowspan_cell_index] = rowspan_value
|
|
384
|
+
end
|
|
385
|
+
|
|
386
|
+
rowspan_hash = adjusted_rowspan_hash
|
|
310
387
|
end
|
|
311
388
|
end
|
|
312
389
|
|
|
@@ -319,23 +396,32 @@ module Caracal
|
|
|
319
396
|
#============= OPTIONS ===================================
|
|
320
397
|
|
|
321
398
|
def root_options
|
|
322
|
-
{
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
'
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
399
|
+
opts = {}
|
|
400
|
+
document.namespaces.each do |model|
|
|
401
|
+
opts[model.namespace_prefix] = model.namespace_href
|
|
402
|
+
end
|
|
403
|
+
unless document.ignorables.empty?
|
|
404
|
+
v = document.ignorables.join(' ')
|
|
405
|
+
opts['mc:Ignorable'] = v
|
|
406
|
+
end
|
|
407
|
+
opts
|
|
408
|
+
# {
|
|
409
|
+
# 'xmlns:mc' => 'http://schemas.openxmlformats.org/markup-compatibility/2006',
|
|
410
|
+
# 'xmlns:o' => 'urn:schemas-microsoft-com:office:office',
|
|
411
|
+
# 'xmlns:r' => 'http://schemas.openxmlformats.org/officeDocument/2006/relationships',
|
|
412
|
+
# 'xmlns:m' => 'http://schemas.openxmlformats.org/officeDocument/2006/math',
|
|
413
|
+
# 'xmlns:v' => 'urn:schemas-microsoft-com:vml',
|
|
414
|
+
# 'xmlns:wp' => 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing',
|
|
415
|
+
# 'xmlns:w10' => 'urn:schemas-microsoft-com:office:word',
|
|
416
|
+
# 'xmlns:w' => 'http://schemas.openxmlformats.org/wordprocessingml/2006/main',
|
|
417
|
+
# 'xmlns:wne' => 'http://schemas.microsoft.com/office/word/2006/wordml',
|
|
418
|
+
# 'xmlns:sl' => 'http://schemas.openxmlformats.org/schemaLibrary/2006/main',
|
|
419
|
+
# 'xmlns:a' => 'http://schemas.openxmlformats.org/drawingml/2006/main',
|
|
420
|
+
# 'xmlns:pic' => 'http://schemas.openxmlformats.org/drawingml/2006/picture',
|
|
421
|
+
# 'xmlns:c' => 'http://schemas.openxmlformats.org/drawingml/2006/chart',
|
|
422
|
+
# 'xmlns:lc' => 'http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas',
|
|
423
|
+
# 'xmlns:dgm' => 'http://schemas.openxmlformats.org/drawingml/2006/diagram'
|
|
424
|
+
# }
|
|
339
425
|
end
|
|
340
426
|
|
|
341
427
|
def page_margin_options
|
|
@@ -349,8 +435,9 @@ module Caracal
|
|
|
349
435
|
|
|
350
436
|
def page_size_options
|
|
351
437
|
{
|
|
352
|
-
'w:w'
|
|
353
|
-
'w:h'
|
|
438
|
+
'w:w' => document.page_width,
|
|
439
|
+
'w:h' => document.page_height,
|
|
440
|
+
'w:orient' => document.page_orientation
|
|
354
441
|
}
|
|
355
442
|
end
|
|
356
443
|
|
|
@@ -16,9 +16,9 @@ module Caracal
|
|
|
16
16
|
#
|
|
17
17
|
def to_xml
|
|
18
18
|
builder = ::Nokogiri::XML::Builder.with(declaration_xml) do |xml|
|
|
19
|
-
xml
|
|
19
|
+
xml['w'].fonts root_options do
|
|
20
20
|
document.fonts.each do |font|
|
|
21
|
-
xml
|
|
21
|
+
xml['w'].font({ 'w:name' => font.font_name })
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
end
|
|
@@ -6,30 +6,51 @@ require 'caracal/renderers/xml_renderer'
|
|
|
6
6
|
module Caracal
|
|
7
7
|
module Renderers
|
|
8
8
|
class FooterRenderer < XmlRenderer
|
|
9
|
-
|
|
9
|
+
|
|
10
10
|
#-------------------------------------------------------------
|
|
11
11
|
# Public Methods
|
|
12
12
|
#-------------------------------------------------------------
|
|
13
|
-
|
|
14
|
-
# This method produces the xml required for the `word/settings.xml`
|
|
13
|
+
|
|
14
|
+
# This method produces the xml required for the `word/settings.xml`
|
|
15
15
|
# sub-document.
|
|
16
16
|
#
|
|
17
17
|
def to_xml
|
|
18
18
|
builder = ::Nokogiri::XML::Builder.with(declaration_xml) do |xml|
|
|
19
|
-
xml
|
|
20
|
-
xml
|
|
21
|
-
xml
|
|
22
|
-
xml
|
|
23
|
-
xml
|
|
19
|
+
xml['w'].ftr root_options do
|
|
20
|
+
xml['w'].p paragraph_options do
|
|
21
|
+
xml['w'].pPr do
|
|
22
|
+
xml['w'].contextualSpacing({ 'w:val' => '0' })
|
|
23
|
+
xml['w'].jc({ 'w:val' => "#{ document.page_number_align }" })
|
|
24
24
|
end
|
|
25
|
-
|
|
26
|
-
xml
|
|
27
|
-
xml
|
|
25
|
+
unless document.page_number_label.nil?
|
|
26
|
+
xml['w'].r run_options do
|
|
27
|
+
xml['w'].rPr do
|
|
28
|
+
xml['w'].rStyle({ 'w:val' => 'PageNumber' })
|
|
29
|
+
unless document.page_number_label_size.nil?
|
|
30
|
+
xml['w'].sz({ 'w:val' => document.page_number_label_size })
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
xml['w'].t({ 'xml:space' => 'preserve' }) do
|
|
34
|
+
xml.text "#{ document.page_number_label } "
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
xml['w'].r run_options do
|
|
39
|
+
xml['w'].rPr do
|
|
40
|
+
unless document.page_number_number_size.nil?
|
|
41
|
+
xml['w'].sz({ 'w:val' => document.page_number_number_size })
|
|
42
|
+
xml['w'].szCs({ 'w:val' => document.page_number_number_size })
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
xml['w'].fldChar({ 'w:fldCharType' => 'begin' })
|
|
46
|
+
xml['w'].instrText({ 'xml:space' => 'preserve' }) do
|
|
47
|
+
xml.text 'PAGE'
|
|
28
48
|
end
|
|
49
|
+
xml['w'].fldChar({ 'w:fldCharType' => 'end' })
|
|
29
50
|
end
|
|
30
|
-
xml
|
|
31
|
-
xml
|
|
32
|
-
xml
|
|
51
|
+
xml['w'].r run_options do
|
|
52
|
+
xml['w'].rPr do
|
|
53
|
+
xml['w'].rtl({ 'w:val' => '0' })
|
|
33
54
|
end
|
|
34
55
|
end
|
|
35
56
|
end
|
|
@@ -37,13 +58,13 @@ module Caracal
|
|
|
37
58
|
end
|
|
38
59
|
builder.to_xml(save_options)
|
|
39
60
|
end
|
|
40
|
-
|
|
41
|
-
|
|
61
|
+
|
|
62
|
+
|
|
42
63
|
#-------------------------------------------------------------
|
|
43
64
|
# Private Methods
|
|
44
|
-
#-------------------------------------------------------------
|
|
65
|
+
#-------------------------------------------------------------
|
|
45
66
|
private
|
|
46
|
-
|
|
67
|
+
|
|
47
68
|
def root_options
|
|
48
69
|
{
|
|
49
70
|
'xmlns:mc' => 'http://schemas.openxmlformats.org/markup-compatibility/2006',
|
|
@@ -63,7 +84,7 @@ module Caracal
|
|
|
63
84
|
'xmlns:dgm' => 'http://schemas.openxmlformats.org/drawingml/2006/diagram'
|
|
64
85
|
}
|
|
65
86
|
end
|
|
66
|
-
|
|
87
|
+
|
|
67
88
|
end
|
|
68
89
|
end
|
|
69
|
-
end
|
|
90
|
+
end
|