metanorma-un 0.3.6 → 0.3.7

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.
@@ -7,128 +7,26 @@ module IsoDoc
7
7
  # A {Converter} implementation that generates HTML output, and a document
8
8
  # schema encapsulation of the document for validation
9
9
  #
10
- class PdfConvert < IsoDoc::PdfConvert
10
+ class PdfConvert < IsoDoc::XslfoPdfConvert
11
11
  def initialize(options)
12
12
  @libdir = File.dirname(__FILE__)
13
13
  super
14
14
  end
15
15
 
16
- #def convert1(docxml, filename, dir)
17
- #FileUtils.cp html_doc_path('logo.jpg'), File.join(@localdir, "logo.jpg")
18
- #@files_to_delete << File.join(@localdir, "logo.jpg")
19
- #super
20
- #end
21
-
22
- def default_fonts(options)
23
- {
24
- bodyfont: (
25
- options[:script] == "Hans" ?
26
- '"SimSun",serif' :
27
- '"Roboto", "Helvetica Neue", Helvetica, Arial, sans-serif'
28
- ),
29
- headerfont: (
30
- options[:script] == "Hans" ?
31
- '"SimHei",sans-serif' :
32
- '"Roboto", "Helvetica Neue", Helvetica, Arial, sans-serif'
33
- ),
34
- monospacefont: '"Space Mono",monospace'
35
- }
36
- end
37
-
38
- def default_file_locations(_options)
39
- {
40
- htmlstylesheet: html_doc_path("htmlstyle.scss"),
41
- htmlcoverpage: html_doc_path("html_unece_titlepage.html"),
42
- htmlintropage: html_doc_path("html_unece_intro.html"),
43
- scripts: html_doc_path("scripts.pdf.html"),
44
- }
45
- end
46
-
47
-
48
- def googlefonts
49
- <<~HEAD.freeze
50
- <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i|Space+Mono:400,700" rel="stylesheet">
51
- <link href="https://fonts.googleapis.com/css?family=Roboto:300,400,400i,500,700,900" rel="stylesheet">
52
- HEAD
53
- end
54
-
55
- def make_body(xml, docxml)
56
- plenary = is_plenary?(docxml)
57
- body_attr = { lang: "EN-US", link: "blue", vlink: "#954F72", "xml:lang": "EN-US", class: "container" }
58
- if plenary && @htmlcoverpage == html_doc_path("html_unece_titlepage.html")
59
- @htmlcoverpage = html_doc_path("html_unece_plenary_titlepage.html")
60
- end
61
- #@htmlintropage = nil if plenary
62
- xml.body **body_attr do |body|
63
- make_body1(body, docxml)
64
- make_body2(body, docxml)
65
- make_body3(body, docxml)
16
+ def convert(filename, file = nil, debug = false)
17
+ file = File.read(filename, encoding: "utf-8") if file.nil?
18
+ docxml, outname_html, dir = convert_init(file, filename, debug)
19
+ plenary = docxml.at(ns("//bibdata/ext[doctype = 'plenary']"))
20
+ /\.xml$/.match(filename) or
21
+ filename = Tempfile.open([outname_html, ".xml"], encoding: "utf-8") do |f|
22
+ f.write file
23
+ f.path
66
24
  end
25
+ FileUtils.rm_rf dir
26
+ ::Metanorma::Output::XslfoPdf.new.convert(
27
+ filename, outname_html + ".pdf",
28
+ File.join(@libdir, plenary ? "unece.plenary.xsl" : "unece.recommendation.xsl"))
67
29
  end
68
-
69
- def make_body3(body, docxml)
70
- body.div **{ class: "main-section" } do |div3|
71
- boilerplate docxml, div3
72
- abstract docxml, div3
73
- foreword docxml, div3
74
- introduction docxml, div3
75
- preface docxml, div3
76
- acknowledgements docxml, div3
77
- middle docxml, div3
78
- footnotes div3
79
- comments div3
80
- end
81
- end
82
-
83
- def html_preface(docxml)
84
- super
85
- docxml
86
- end
87
-
88
- def middle(isoxml, out)
89
- clause isoxml, out
90
- annex isoxml, out
91
- bibliography isoxml, out
92
- end
93
-
94
- def clause_parse_title(node, div, c1, out)
95
- if node["inline-header"] == "true"
96
- inline_header_title(out, node, c1)
97
- else
98
- div.send "h#{anchor(node['id'], :level, false) || '1'}" do |h|
99
- lbl = anchor(node['id'], :label, false)
100
- h << "#{lbl}. " if lbl && !@suppressheadingnumbers
101
- insert_tab(h, 1) if lbl && !@suppressheadingnumbers
102
- c1&.children&.each { |c2| parse(c2, h) }
103
- end
104
- end
105
- end
106
-
107
- def introduction(isoxml, out)
108
- f = isoxml.at(ns("//introduction")) || return
109
- page_break(out)
110
- out.div **{ class: "Section3", id: f["id"] } do |div|
111
- div.h1(**{ class: "IntroTitle" }) do |h1|
112
- h1 << @introduction_lbl
113
- end
114
- f.elements.each do |e|
115
- parse(e, div) unless e.name == "title"
116
- end
117
- end
118
- end
119
-
120
- def foreword(isoxml, out)
121
- f = isoxml.at(ns("//foreword")) || return
122
- page_break(out)
123
- out.div **attr_code(id: f["id"]) do |s|
124
- s.h1(**{ class: "ForewordTitle" }) do |h1|
125
- h1 << @foreword_lbl
126
- end
127
- f.elements.each { |e| parse(e, s) unless e.name == "title" }
128
- end
129
- end
130
-
131
- include BaseConvert
132
30
  end
133
31
  end
134
32
  end