isodoc 0.7.1 → 0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +8 -6
  3. data/README.adoc +3 -3
  4. data/lib/{isodoc → isodoc-yaml}/i18n-en.yaml +0 -0
  5. data/lib/{isodoc → isodoc-yaml}/i18n-fr.yaml +0 -0
  6. data/lib/{isodoc → isodoc-yaml}/i18n-zh-Hans.yaml +0 -0
  7. data/lib/isodoc.rb +13 -6
  8. data/lib/isodoc/class_utils.rb +24 -0
  9. data/lib/isodoc/common.rb +34 -0
  10. data/lib/isodoc/convert.rb +3 -16
  11. data/lib/isodoc/function.rb +4 -0
  12. data/lib/isodoc/{blocks.rb → function/blocks.rb} +2 -2
  13. data/lib/isodoc/{cleanup.rb → function/cleanup.rb} +4 -9
  14. data/lib/isodoc/{i18n.rb → function/i18n.rb} +13 -10
  15. data/lib/isodoc/{inline.rb → function/inline.rb} +2 -4
  16. data/lib/isodoc/{lists.rb → function/lists.rb} +5 -4
  17. data/lib/isodoc/{references.rb → function/references.rb} +4 -3
  18. data/lib/isodoc/{section.rb → function/section.rb} +4 -3
  19. data/lib/isodoc/{table.rb → function/table.rb} +3 -2
  20. data/lib/isodoc/{terms.rb → function/terms.rb} +3 -2
  21. data/lib/isodoc/{iso2wordhtml.rb → function/to_word_html.rb} +2 -3
  22. data/lib/isodoc/{utils.rb → function/utils.rb} +6 -22
  23. data/lib/isodoc/{xref_gen.rb → function/xref_gen.rb} +4 -3
  24. data/lib/isodoc/{xref_sect_gen.rb → function/xref_sect_gen.rb} +4 -3
  25. data/lib/isodoc/html_convert.rb +12 -0
  26. data/lib/isodoc/html_function.rb +4 -0
  27. data/lib/isodoc/{htmlconvert → html_function}/comments.rb +2 -3
  28. data/lib/isodoc/{htmlconvert → html_function}/footnotes.rb +3 -4
  29. data/lib/isodoc/{htmlconvert → html_function}/html.rb +5 -5
  30. data/lib/isodoc/iso/html/html_iso_titlepage.html +2 -2
  31. data/lib/isodoc/iso/{convert.rb → html_convert.rb} +1 -1
  32. data/lib/isodoc/iso/{wordconvert.rb → word_convert.rb} +0 -0
  33. data/lib/isodoc/metadata.rb +27 -12
  34. data/lib/isodoc/version.rb +1 -1
  35. data/lib/isodoc/{wordconvert/convert.rb → word_convert.rb} +9 -11
  36. data/lib/isodoc/word_function.rb +4 -0
  37. data/lib/isodoc/word_function/body.rb +149 -0
  38. data/lib/isodoc/{wordconvert → word_function}/comments.rb +2 -2
  39. data/lib/isodoc/word_function/footnotes.rb +81 -0
  40. data/lib/isodoc/word_function/postprocess.rb +116 -0
  41. data/spec/isodoc/blocks_spec.rb +17 -17
  42. data/spec/isodoc/cleanup_spec.rb +8 -8
  43. data/spec/isodoc/footnotes_spec.rb +2 -2
  44. data/spec/isodoc/i18n_spec.rb +4 -4
  45. data/spec/isodoc/inline_spec.rb +7 -7
  46. data/spec/isodoc/iso_spec.rb +5 -5
  47. data/spec/isodoc/lists_spec.rb +4 -4
  48. data/spec/isodoc/metadata_spec.rb +2 -2
  49. data/spec/isodoc/postproc_spec.rb +9 -9
  50. data/spec/isodoc/ref_spec.rb +3 -3
  51. data/spec/isodoc/section_spec.rb +6 -6
  52. data/spec/isodoc/table_spec.rb +1 -1
  53. data/spec/isodoc/terms_spec.rb +1 -1
  54. data/spec/isodoc/xref_spec.rb +11 -11
  55. metadata +35 -30
  56. data/lib/isodoc/htmlconvert/convert.rb +0 -13
  57. data/lib/isodoc/wordconvert/footnotes.rb +0 -81
  58. data/lib/isodoc/wordconvert/postprocess.rb +0 -115
  59. data/lib/isodoc/wordconvert/wordconvertmodule.rb +0 -150
@@ -1,115 +0,0 @@
1
- module IsoDoc
2
- class WordConvert < Common
3
-
4
- def postprocess(result, filename, dir)
5
- generate_header(filename, dir)
6
- result = from_xhtml(cleanup(to_xhtml(result)))
7
- toWord(result, filename, dir)
8
- @files_to_delete.each { |f| system "rm #{f}" }
9
- end
10
-
11
- def toWord(result, filename, dir)
12
- result = populate_template(result, :word)
13
- result = from_xhtml(word_cleanup(to_xhtml(result)))
14
- Html2Doc.process(result, filename: filename, stylesheet: @wordstylesheet,
15
- header_file: "header.html", dir: dir,
16
- asciimathdelims: [@openmathdelim, @closemathdelim],
17
- liststyles: { ul: @ulstyle, ol: @olstyle })
18
- end
19
-
20
- def word_cleanup(docxml)
21
- word_preface(docxml)
22
- word_annex_cleanup(docxml)
23
- docxml
24
- end
25
-
26
- # force Annex h2 to be p.h2Annex, so it is not picked up by ToC
27
- def word_annex_cleanup(docxml)
28
- docxml.xpath("//h2[ancestor::*[@class = 'Section3']]").each do |h2|
29
- h2.name = "p"
30
- h2["class"] = "h2Annex"
31
- end
32
- end
33
-
34
- def word_preface(docxml)
35
- word_cover(docxml) if @wordcoverpage
36
- word_intro(docxml) if @wordintropage
37
- end
38
-
39
- def word_cover(docxml)
40
- cover = File.read(@wordcoverpage, encoding: "UTF-8")
41
- cover = populate_template(cover, :word)
42
- coverxml = to_xhtml_fragment(cover)
43
- docxml.at('//div[@class="WordSection1"]').children.first.previous =
44
- coverxml.to_xml(encoding: "US-ASCII")
45
- end
46
-
47
- def word_intro(docxml)
48
- intro = File.read(@wordintropage, encoding: "UTF-8").
49
- sub(/WORDTOC/, make_WordToC(docxml))
50
- intro = populate_template(intro, :word)
51
- introxml = to_xhtml_fragment(intro)
52
- docxml.at('//div[@class="WordSection2"]').children.first.previous =
53
- introxml.to_xml(encoding: "US-ASCII")
54
- end
55
-
56
- def generate_header(filename, _dir)
57
- return unless @header
58
- template = Liquid::Template.parse(File.read(@header, encoding: "UTF-8"))
59
- meta = @meta.get
60
- meta[:filename] = filename
61
- params = meta.map { |k, v| [k.to_s, v] }.to_h
62
- File.open("header.html", "w") do |f|
63
- f.write(template.render(params))
64
- end
65
- @files_to_delete << "header.html"
66
- end
67
-
68
- def word_toc_entry(toclevel, heading)
69
- bookmark = Random.rand(1000000000)
70
- <<~TOC
71
- <p class="MsoToc#{toclevel}"><span class="MsoHyperlink"><span
72
- lang="EN-GB" style='mso-no-proof:yes'>
73
- <a href="#_Toc#{bookmark}">#{heading}<span lang="EN-GB"
74
- class="MsoTocTextSpan">
75
- <span style='mso-tab-count:1 dotted'>. </span>
76
- </span><span lang="EN-GB" class="MsoTocTextSpan">
77
- <span style='mso-element:field-begin'></span></span>
78
- <span lang="EN-GB"
79
- class="MsoTocTextSpan"> PAGEREF _Toc#{bookmark} \\h </span>
80
- <span lang="EN-GB" class="MsoTocTextSpan"><span
81
- style='mso-element:field-separator'></span></span><span
82
- lang="EN-GB" class="MsoTocTextSpan">1</span>
83
- <span lang="EN-GB"
84
- class="MsoTocTextSpan"></span><span
85
- lang="EN-GB" class="MsoTocTextSpan"><span
86
- style='mso-element:field-end'></span></span></a></span></span></p>
87
-
88
- TOC
89
- end
90
-
91
- WORD_TOC_PREFACE1 = <<~TOC.freeze
92
- <span lang="EN-GB"><span
93
- style='mso-element:field-begin'></span><span
94
- style='mso-spacerun:yes'>&#xA0;</span>TOC
95
- \\o &quot;1-2&quot; \\h \\z \\u <span
96
- style='mso-element:field-separator'></span></span>
97
- TOC
98
-
99
- WORD_TOC_SUFFIX1 = <<~TOC.freeze
100
- <p class="MsoToc1"><span lang="EN-GB"><span
101
- style='mso-element:field-end'></span></span><span
102
- lang="EN-GB"><o:p>&nbsp;</o:p></span></p>
103
- TOC
104
-
105
- def make_WordToC(docxml)
106
- toc = ""
107
- docxml.xpath("//h1 | //h2[not(ancestor::*[@class = 'Section3'])]").
108
- each do |h|
109
- toc += word_toc_entry(h.name == "h1" ? 1 : 2, header_strip(h))
110
- end
111
- toc.sub(/(<p class="MsoToc1">)/,
112
- %{\\1#{WORD_TOC_PREFACE1}}) + WORD_TOC_SUFFIX1
113
- end
114
- end
115
- end
@@ -1,150 +0,0 @@
1
- module IsoDoc
2
- class WordConvert < Common
3
- def make_body1(body, _docxml)
4
- body.div **{ class: "WordSection1" } do |div1|
5
- div1.p { |p| p << "&nbsp;" } # placeholder
6
- end
7
- section_break(body)
8
- end
9
-
10
- def make_body2(body, docxml)
11
- body.div **{ class: "WordSection2" } do |div2|
12
- info docxml, div2
13
- foreword docxml, div2
14
- introduction docxml, div2
15
- div2.p { |p| p << "&nbsp;" } # placeholder
16
- end
17
- section_break(body)
18
- end
19
-
20
- def make_body3(body, docxml)
21
- body.div **{ class: "WordSection3" } do |div3|
22
- middle docxml, div3
23
- footnotes div3
24
- comments div3
25
- end
26
- end
27
-
28
- def insert_tab(out, n)
29
- out.span **attr_code(style: "mso-tab-count:#{n}") do |span|
30
- [1..n].each { span << "&#xA0; " }
31
- end
32
- end
33
-
34
- def para_attrs(node)
35
- classtype = nil
36
- classtype = "Note" if @note
37
- classtype = "MsoCommentText" if in_comment
38
- classtype = "Sourcecode" if @annotation
39
- attrs = { class: classtype, id: node["id"] }
40
- unless node["align"].nil?
41
- attrs[:align] = node["align"] unless node["align"] == "justify"
42
- attrs[:style] = "text-align:#{node['align']}"
43
- end
44
- attrs
45
- end
46
-
47
- def remove_bottom_border(td)
48
- td["style"] =
49
- td["style"].gsub(/border-bottom:[^;]+;/, "border-bottom:0pt;").
50
- gsub(/mso-border-bottom-alt:[^;]+;/, "mso-border-bottom-alt:0pt;")
51
- end
52
-
53
- SW1 = "solid windowtext".freeze
54
-
55
- def new_fullcolspan_row(t, tfoot)
56
- # how many columns in the table?
57
- cols = 0
58
- t.at(".//tr").xpath("./td | ./th").each do |td|
59
- cols += (td["colspan"] ? td["colspan"].to_i : 1)
60
- end
61
- style = %{border-top:0pt;mso-border-top-alt:0pt;
62
- border-bottom:#{SW1} 1.5pt;mso-border-bottom-alt:#{SW1} 1.5pt;}
63
- tfoot.add_child("<tr><td colspan='#{cols}' style='#{style}'/></tr>")
64
- tfoot.xpath(".//td").last
65
- end
66
-
67
- def make_tr_attr(td, row, totalrows)
68
- style = td.name == "th" ? "font-weight:bold;" : ""
69
- rowmax = td["rowspan"] ? row + td["rowspan"].to_i - 1 : row
70
- style += <<~STYLE
71
- border-top:#{row.zero? ? "#{SW1} 1.5pt;" : 'none;'}
72
- mso-border-top-alt:#{row.zero? ? "#{SW1} 1.5pt;" : 'none;'}
73
- border-bottom:#{SW1} #{rowmax == totalrows ? '1.5' : '1.0'}pt;
74
- mso-border-bottom-alt:#{SW1} #{rowmax == totalrows ? '1.5' : '1.0'}pt;
75
- STYLE
76
- { rowspan: td["rowspan"], colspan: td["colspan"],
77
- align: td["align"], style: style.gsub(/\n/, "") }
78
- end
79
-
80
- def section_break(body)
81
- body.br **{ clear: "all", class: "section" }
82
- end
83
-
84
- def page_break(out)
85
- out.br **{ clear: "all",
86
- style: "mso-special-character:line-break;page-break-before:always" }
87
- end
88
-
89
- WORD_DT_ATTRS = {class: @note ? "Note" : nil, align: "left",
90
- style: "margin-left:0pt;text-align:left;"}.freeze
91
-
92
- def dt_parse(dt, term)
93
- term.p **attr_code(WORD_DT_ATTRS) do |p|
94
- if dt.elements.empty?
95
- p << dt.text
96
- else
97
- dt.children.each { |n| parse(n, p) }
98
- end
99
- end
100
- end
101
-
102
- def dl_parse(node, out)
103
- out.table **{ class: "dl" } do |v|
104
- node.elements.select { |n| dt_dd? n }.each_slice(2) do |dt, dd|
105
- v.tr do |tr|
106
- tr.td **{ valign: "top", align: "left" } do |term|
107
- dt_parse(dt, term)
108
- end
109
- tr.td **{ valign: "top" } do |listitem|
110
- dd.children.each { |n| parse(n, listitem) }
111
- end
112
- end
113
- end
114
- dl_parse_notes(node, v)
115
- end
116
- end
117
-
118
- def dl_parse_notes(node, v)
119
- return if node.elements.reject { |n| dt_dd? n }.empty?
120
- v.tr do |tr|
121
- tr.td **{ rowspan: 2 } do |td|
122
- node.elements.reject { |n| dt_dd? n }.each { |n| parse(n, td) }
123
- end
124
- end
125
- end
126
-
127
- def figure_get_or_make_dl(t)
128
- dl = t.at(".//table[@class = 'dl']")
129
- if dl.nil?
130
- t.add_child("<p><b>#{@key_lbl}</b></p><table class='dl'></table>")
131
- dl = t.at(".//table[@class = 'dl']")
132
- end
133
- dl
134
- end
135
-
136
- def figure_aside_process(f, aside, key)
137
- # get rid of footnote link, it is in diagram
138
- f&.at("./a[@class='TableFootnoteRef']")&.remove
139
- fnref = f.at(".//a[@class='TableFootnoteRef']")
140
- tr = key.add_child("<tr></tr>").first
141
- dt = tr.add_child("<td valign='top' align='left'></td>").first
142
- dd = tr.add_child("<td valign='top'></td>").first
143
- fnref.parent = dt
144
- aside.xpath(".//p").each do |a|
145
- a.delete("class")
146
- a.parent = dd
147
- end
148
- end
149
- end
150
- end