metanorma-iso 1.0.1 → 1.0.2

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
  SHA256:
3
- metadata.gz: 0caf03f673015f17ad2a5d899f064bb7ca93f7b7f4f6609e9d0ddf89e7d9bd3d
4
- data.tar.gz: 0eefdfcf49ae5afb6fe49b5faa79e137e0f87143aa1322bf7069b584dfb54db2
3
+ metadata.gz: fe27e81a226e0eb506a4cf4cc1c80d482e25ef5e9866577a2cd42689852e2b50
4
+ data.tar.gz: 4dd394c88bcf6ff2d1a47c179b20fa957e2fae882aad6fa54b19dfda62b8b8ae
5
5
  SHA512:
6
- metadata.gz: 33047755a13dbc36c5933d7e57bdb66769532214eb1fc121c9457693434c5bbd7a9bad72121332dcb896eebaff5ae864f8b9ee01b07cc5a863ef5a91afe11649
7
- data.tar.gz: eaa1711fe74de20ed22da035e9c8c258e2c4322289ebc37923a5514dd2254c1ac1a7e8ed14b6a28f1b7f229a568cb7ec865b12887412612d7496cd29e9f2770d
6
+ metadata.gz: c7772933f31a12224a87c36f2a520763b664ca6c6aa6f25a7372392fa77487923a8c879d5493b0d3b7bf4e99e65c4b33a6eb31b95e392a5793652339c958990a
7
+ data.tar.gz: 6d287c011e5b7192842ff3b4dbc789a75c68d1b5e4e64ce3082be51aac60f9fcc7579d550c38f7d7cd88fab3d912ec7e1ea7f42dd4dc21a29afb380ad8d5d8f2
@@ -29,6 +29,53 @@ To adapt the schema for your publication set,
29
29
  ** The tool suite expects to validate against a set of schemas expressed in RelaxNG. We have been authoring grammars in RelaxNG Compact, as a more human-readable format, then compiling those grammars to RelaxNG using https://github.com/relaxng/jing-trang[jing-trang]. You can choose to use a different schema language, but you will need to customise the tool chain to validate against that form of schema instead.
30
30
  ** In order to make schema inheritance easier, we have avoided using namespaces for the individual schemas; a namespace is added to the standards-specific schema at the very end of the inheritance chain.
31
31
 
32
+ === Schema customisation
33
+
34
+ For example, the `rsd.rnc` schema, expressed in RelaxNG Compact, is specific to Ribose Standard documents: it inherits from the ISO Standards model, modifying 10 elements, and adding five. As an example of modifying elements, RSD permits preformatted text (Ascii art) in figures, which ISO does not:
35
+
36
+ .ISO
37
+ [source,asciidoctor]
38
+ ----
39
+ figure =
40
+ element figure {
41
+ attribute id { xsd:ID },
42
+ tname?,
43
+ ( image | subfigure+ ),
44
+ fn*, dl?, note*
45
+ }
46
+ ----
47
+
48
+ .RSD
49
+ [source,asciidoctor]
50
+ ----
51
+ figure =
52
+ element figure {
53
+ attribute id { xsd:ID },
54
+ tname?,
55
+ ( image | pre | subfigure+ ),
56
+ fn*, dl?, note*
57
+ }
58
+ ----
59
+
60
+ The preformatted text tag `pre` is an addition to the RSD specification, which is why it lies outside the `include "isostandard.rnc {}"` container:
61
+
62
+ .RSD
63
+ [source,asciidoctor]
64
+ ----
65
+ pre = element pre { text }
66
+ ----
67
+
68
+ As another instance of customisation, the `BibItemType` enumeration of permissible bibliographical item types is extended in RSD to include the document types specific to RSD:
69
+
70
+ .RSD
71
+ [source,asciidoctor]
72
+ ----
73
+ BibItemType |=
74
+ "policy-and-procedures" | "best-practices" | "supporting-document" | "report" | "legal" | "directives" | "proposal" |
75
+ "standard"
76
+ ----
77
+
78
+
32
79
  == How can I adapt the StanDoc toolchain for my own publications?
33
80
 
34
81
  [TIP]
@@ -47,38 +94,411 @@ The tool chains currently available proceed in two steps: map an input markup la
47
94
 
48
95
  Your adaptation of the toolchain will need to instantiate these three modules. The connection between the two first steps is taken care of in the toolchain, and metanorma explicitly invokes the two steps, feeding the XML output of the first step as input into the second. The metanorma-sample gem outputs both Word and HTML; you can choose to output only Word (as is done in metanorma-m3d), or only HTML (as is done in metanorma-csand), and you can choose to generate PDF from HTML as well (as is done in metanorma-csd).
49
96
 
50
- The modules involve classes which rely on inheritance from other classes; the current gems all use `Asciidoctor::ISO::Converter`, `Isodoc::{Metadata, HtmlConvert, WordConvert}`, and `Metanorma::Processor` as their base classes. This allows the standards-specific classes to be quite succinct, as most of their behaviour is inherited from other classes; but it also means that you need to be familiar with the underlying gems, in order to do most customisation.
97
+ The modules involve classes which rely on inheritance from other classes; the current gems use `Asciidoctor::{Standoc, ISO}::Converter`, `Isodoc::{Metadata, HtmlConvert, WordConvert}`, and `Metanorma::Processor` as their base classes. This allows the standards-specific classes to be quite succinct, as most of their behaviour is inherited from other classes; but it also means that you need to be familiar with the underlying gems, in order to do most customisation.
98
+
99
+ In the case of `Asciidoctor::X` classes, the changes you will need to make involve the intermediate XML representation of your document, which is built up through Nokogiri Builder; e.g. adding different enums, or adding new elements. The adaptations in `Asciidoctor::Sample::Converter` are limited, and most projects can take them across as is.
100
+
101
+ The customisations needed for Metanorma::Sample::Processor are minor, and involve invoking methods specific to the gem for document generation.
102
+
103
+ The customisations needed for Isodoc::Sample are more extensive. Three base classes are involved:
104
+
105
+ * `Isodoc::Metadata` processes the metadata about the document stored in `//bibdata`. This information typically ends up in the document title page, as opposed to the document body. For that reason, metadata is extracted into a hash, which is passed to document output (title page, Word header) via the https://shopify.github.io/liquid/[Liquid template language].
106
+ * `Isodoc::HtmlConvert` converts Standoc XML to HTML.
107
+ * `Isodoc::WordConvert` converts Standoc XML to Word HTML; the https://github.com/riboseinc/html2doc[html2doc] gem then converts this to a .doc document.
51
108
 
52
- In the case of `Asciidoctor::X` classes, the changes you will need to make involve the intermediate XML representation of your document; e.g. adding different enums, or adding new elements. The adaptations in `Asciidoctor::Sample::Converter` are limited, and most projects can take them across as is:
109
+ The `Isodoc::HtmlConvert` and `Isodoc::WordConvert` overlap substantially, as both use variants of HTML. However there is no reason not to make substantially different rendering choices in the HTML and Word branches of the code.
110
+
111
+ === Asciidoctor::Standoc customisation in metanorma-sample
112
+
113
+ Examples from Asciidoctor::Sample in metanorma-sample. In the following snippets, the parameter `node` represents the current node of the Asciidoctor document, and `xml` represents the Nokogiri Builder node of the XML output.
114
+
115
+ * The boilerplate representation of the document's author, publisher and copyright holder names Acme instead of ISO as the responsible organisation.
116
+
117
+ [source,ruby]
118
+ --
119
+ def metadata_author(node, xml)
120
+ xml.contributor do |c|
121
+ c.role **{ type: "author" }
122
+ c.organization do |a|
123
+ a.name "Acme"
124
+ end
125
+ end
126
+ end
127
+ --
128
+
129
+ * The editorial committees are represented as a single element, as opposed to ISO's name plus number. (`node.attr()` recovers Asciidoctor document attribute values.)
130
+
131
+ [source,ruby]
132
+ --
133
+ def metadata_committee(node, xml)
134
+ xml.editorialgroup do |a|
135
+ a.committee node.attr("committee"),
136
+ **attr_code(type: node.attr("committee-type"))
137
+ end
138
+ end
139
+ --
140
+
141
+ * The document title is monolingual, not bilingual. (`asciidoc_sub()` is already defined to apply Asciidoctor text substitutions to its contents, such as smart quotes and em-dashes.)
142
+
143
+ [source,ruby]
144
+ --
145
+ def title(node, xml)
146
+ ["en"].each do |lang|
147
+ xml.title **{ language: lang, format: "plain" } do |t|
148
+ t << asciidoc_sub(node.attr("title"))
149
+ end
150
+ end
151
+ end
152
+ --
53
153
 
54
- * The boilerplate representation of the document's author, publisher and copyright holder names Ribose instead of ISO as the responsible organisation.
55
- * The editorial committees are represented as a single element, as opposed to ISO's name plus number.
56
- * The document title is monolingual, not bilingual.
57
154
  * The document status is a single element, as opposed to ISO's two-part code.
155
+
156
+ [source,ruby]
157
+ --
158
+ def metadata_status(node, xml)
159
+ xml.status(**{ format: "plain" }) { |s| s << node.attr("status") }
160
+ end
161
+ --
162
+
58
163
  * The document identifier is a single element.
164
+
165
+ [source,ruby]
166
+ --
167
+ def metadata_id(node, xml)
168
+ xml.docidentifier { |i| i << node.attr("docnumber") }
169
+ end
170
+ --
171
+
172
+ * A security element is added to the document metadata.
173
+
174
+ [source,ruby]
175
+ --
176
+ def metadata_security(node, xml)
177
+ security = node.attr("security") || return
178
+ xml.security security
179
+ end
180
+
181
+ def metadata(node, xml)
182
+ super
183
+ metadata_security(node, xml)
184
+ end
185
+ --
186
+
59
187
  * Title validation and style validation is disabled.
60
- * The root element of the document is changed from `iso-standard` to `rsd-standard`.
188
+
189
+ [source,ruby]
190
+ --
191
+ def title_validate(root)
192
+ nil
193
+ end
194
+ --
195
+
196
+ * The root element of the document is changed from `iso-standard` to `sample-standard`.
197
+
198
+ [source,ruby]
199
+ --
200
+ def makexml(node)
201
+ result = ["<?xml version='1.0' encoding='UTF-8'?>\n<sample-standard>"]
202
+ @draft = node.attributes.has_key?("draft")
203
+ result << noko { |ixml| front node, ixml }
204
+ result << noko { |ixml| middle node, ixml }
205
+ result << "</sample-standard>"
206
+ ....
207
+ end
208
+ --
209
+
61
210
  * The document type attribute is restricted to a prescribed set of options.
62
- * A `literal` element and a `keyword` element is added to the ISO instance of Standoc.
211
+
212
+ [source,ruby]
213
+ --
214
+ def doctype(node)
215
+ d = node.attr("doctype")
216
+ unless %w{policy-and-procedures best-practices
217
+ supporting-document report legal directives proposal
218
+ standard}.include? d
219
+ warn "#{d} is not a legal document type: reverting to 'standard'"
220
+ d = "standard"
221
+ end
222
+ d
223
+ end
224
+ --
225
+
226
+ * The `literal` asciidoctor block is processed as a preformatted tag (`pre`).
227
+ (The code uses the built-in Asciidoctor `literal()` method, and embeds `pre` within a `figure` tag.)
228
+
229
+ [source,ruby]
230
+ --
231
+ def literal(node)
232
+ noko do |xml|
233
+ xml.figure **id_attr(node) do |f|
234
+ figure_title(node, f)
235
+ f.pre node.lines.join("\n")
236
+ end
237
+ end
238
+ end
239
+ --
240
+
241
+ * A `keyword` element is added. (The keyword is encoded through the role attribute of Asciidoc: `[.keyword]#text#`)
242
+
243
+ [source,ruby]
244
+ --
245
+ def inline_quoted(node)
246
+ noko do |xml|
247
+ case node.type
248
+ ...
249
+ else
250
+ case node.role
251
+ ...
252
+ when "keyword" then xml.keyword node.text
253
+ else
254
+ xml << node.text
255
+ end
256
+ end
257
+ end.join
258
+ end
259
+ --
260
+
63
261
  * The inline headers of ISO are ignored.
64
262
 
65
- The customisations needed for Metanorma::Sample::Processor are minor:
263
+ [source,ruby]
264
+ --
265
+ def sections_cleanup(x)
266
+ super
267
+ x.xpath("//*[@inline-header]").each do |h|
268
+ h.delete("inline-header")
269
+ end
270
+ end
271
+ --
272
+
273
+ === Metanorma::Processor customisation in metanorma-sample
66
274
 
67
275
  * `initialize` names the token by which Asciidoctor registers the standard
276
+
277
+ [source,ruby]
278
+ --
279
+ def initialize
280
+ @short = :sample
281
+ @input_format = :asciidoc
282
+ @asciidoctor_backend = :sample
283
+ end
284
+ --
285
+
68
286
  * `output_formats` names the available output formats (including XML, which is inherited from the parent class)
287
+
288
+ [source,ruby]
289
+ --
290
+ def output_formats
291
+ super.merge(
292
+ html: "html",
293
+ doc: "doc",
294
+ pdf: "pdf"
295
+ )
296
+ end
297
+ --
298
+
69
299
  * `version` gives the current version string for the gem
70
- * `input_to_isodoc` is the call which converts Asciidoctor input into IsoDoc XML
71
- * `output` is the call which converts IsoDoc XML into various nominated output formats
72
300
 
73
- The customisations needed for Isodoc::Sample are more extensive. Three base classes are involved:
301
+ [source,ruby]
302
+ --
303
+ def version
304
+ "Asciidoctor::Sample #{Asciidoctor::Sample::VERSION}"
305
+ end
306
+ --
74
307
 
75
- * `Isodoc::Metadata` processes the metadata about the document stored in `//bibdata`. This information typically ends up in the document title page, as opposed to the document body. For that reason, metadata is extracted into a hash, which is passed to document output (title page, Word header) via the https://shopify.github.io/liquid/[Liquid template language].
76
- * `Isodoc::HtmlConvert` converts Standoc XML to HTML.
77
- * `Isodoc::WordConvert` converts Standoc XML to Word HTML; the https://github.com/riboseinc/html2doc[html2doc] gem then converts this to a .doc document.
308
+ * `input_to_isodoc` is the call which converts Asciidoctor input into IsoDoc XML
78
309
 
79
- The `Isodoc::HtmlConvert` and `Isodoc::WordConvert` overlap substantially, as both use variants of HTML; in fact the files `samplehtmlrender.rb` and `samplewordrender.rb` are deliberately identical, apart from the class their code belongs to. However there is no reason not to make substantially different rendering choices in the HTML and Word branches of the code.
310
+ [source,ruby]
311
+ --
312
+ def input_to_isodoc(file)
313
+ Metanorma::Input::Asciidoc.new.process(file, @asciidoctor_backend)
314
+ end
315
+ --
80
316
 
81
- = How can I style the resulting HTML output?
317
+ * `output` is the call which converts IsoDoc XML into various nominated output formats
318
+
319
+ [source,ruby]
320
+ --
321
+ def output(isodoc_node, outname, format, options={})
322
+ case format
323
+ when :html
324
+ IsoDoc::Sample::HtmlConvert.new(options).convert(outname, isodoc_node)
325
+ when :doc
326
+ IsoDoc::Sample::WordConvert.new(options).convert(outname, isodoc_node)
327
+ when :pdf
328
+ IsoDoc::Sample::PdfConvert.new(options).convert(outname, isodoc_node)
329
+ else
330
+ super
331
+ end
332
+ end
333
+ --
334
+
335
+ === Isodoc::Standoc customisation in metanorma-sample
336
+
337
+ * Setting the document title (`:doctitle`) in metadata, as a single element in ISO XML; ignore any document subtitle.
338
+
339
+ [source,ruby]
340
+ --
341
+ def title(isoxml, _out)
342
+ main = isoxml&.at(ns("//title[@language='en']"))&.text
343
+ set(:doctitle, main)
344
+ end
345
+
346
+ def subtitle(_isoxml, _out)
347
+ nil
348
+ end
349
+ --
350
+
351
+ * Add to version metadata a metadata element for the revision date (already stored as `:revdate`), expressed as month+year (`:revdate_monthyear`)/
352
+
353
+ [source,ruby]
354
+ --
355
+ def version(isoxml, _out)
356
+ super
357
+ revdate = get[:revdate]
358
+ set(:revdate_monthyear, monthyr(revdate))
359
+ end
360
+
361
+ def monthyr(isodate)
362
+ m = /(?<yr>\d\d\d\d)-(?<mo>\d\d)/.match isodate
363
+ return isodate unless m && m[:yr] && m[:mo]
364
+ return "#{MONTHS[m[:mo].to_sym]} #{m[:yr]}"
365
+ end
366
+ --
367
+
368
+ * Initialise the HTML Converter:
369
+ ** Set `@libdir`, the current directory of the HTML converter, and the basis of the `html_doc_path()` method for accessing HTML assets (the `html` subdirectory of the current directory).
370
+ ** Copy the logo JPG from the HTML asset directory to the working directory, so that it can be access by the HTML template; flag the copy for deletion at the end of processing.
371
+
372
+ [source,ruby]
373
+ --
374
+ def initialize(options)
375
+ @libdir = File.dirname(__FILE__)
376
+ super
377
+ FileUtils.cp html_doc_path('logo.jpg'), "logo.jpg"
378
+ @files_to_delete << "logo.jpg"
379
+ end
380
+ --
381
+
382
+ * Set the default fonts for the HTML rendering, which will be used to populate the HTML CSS stylesheet.
383
+
384
+ [source,ruby]
385
+ --
386
+ class HtmlConvert < IsoDoc::HtmlConvert
387
+ def default_fonts(options)
388
+ {
389
+ bodyfont: (options[:script] == "Hans" ? '"SimSun",serif' : '"Overpass",sans-serif'),
390
+ headerfont: (options[:script] == "Hans" ? '"SimHei",sans-serif' : '"Overpass",sans-serif'),
391
+ monospacefont: '"Space Mono",monospace'
392
+ }
393
+ end
394
+ --
395
+
396
+ * Set the default HTML assets for the HTML rendering.
397
+
398
+ [source,ruby]
399
+ --
400
+ class HtmlConvert < IsoDoc::HtmlConvert
401
+ def default_file_locations(_options)
402
+ {
403
+ htmlstylesheet: html_doc_path("htmlstyle.scss"),
404
+ htmlcoverpage: html_doc_path("html_sample_titlepage.html"),
405
+ htmlintropage: html_doc_path("html_sample_intro.html"),
406
+ scripts: html_doc_path("scripts.html"),
407
+ }
408
+ end
409
+ --
410
+
411
+ * Set distinct default fonts and HTML assets for the Word rendering.
412
+
413
+ [source,ruby]
414
+ --
415
+ class WordConvert < IsoDoc::WordConvert
416
+ def default_fonts(options)
417
+ {
418
+ bodyfont: (options[:script] == "Hans" ? '"SimSun",serif' : '"Arial",sans-serif'),
419
+ headerfont: (options[:script] == "Hans" ? '"SimHei",sans-serif' : '"Arial",sans-serif'),
420
+ monospacefont: '"Courier New",monospace'
421
+ }
422
+ end
423
+
424
+ def default_file_locations(_options)
425
+ {
426
+ wordstylesheet: html_doc_path("wordstyle.scss"),
427
+ standardstylesheet: html_doc_path("sample.scss"),
428
+ header: html_doc_path("header.html"),
429
+ wordcoverpage: html_doc_path("word_sample_titlepage.html"),
430
+ wordintropage: html_doc_path("word_sample_intro.html"),
431
+ ulstyle: "l3",
432
+ olstyle: "l2",
433
+ }
434
+ end
435
+ --
436
+
437
+
438
+ * Set the content of the HTML head, other than the CSS stylesheets. Note that the head title is given as a Liquid Template reference to metadata ()`{{ doctitle }}`, which we have seen populated above.)
439
+
440
+ [source,ruby]
441
+ --
442
+ def html_head
443
+ <<~HEAD.freeze
444
+ <title>{{ doctitle }}</title>
445
+ <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
446
+ <!--TOC script import-->
447
+ <script type="text/javascript" src="https://cdn.rawgit.com/jgallen23/toc/0.3.2/dist/toc.min.js"></script>
448
+ <!--Google fonts-->
449
+ ....
450
+ <style class="anchorjs"></style>
451
+ HEAD
452
+ end
453
+ --
454
+
455
+ * Change the default label for annexes from "Annex" to "Appendix".
456
+
457
+ [source,ruby]
458
+ --
459
+ def i18n_init(lang, script)
460
+ super
461
+ @annex_lbl = "Appendix"
462
+ end
463
+ --
464
+
465
+ * Define rendering for the `pre` and `keyword` preformatted text tags.
466
+
467
+ [source,ruby]
468
+ --
469
+ def pre_parse(node, out)
470
+ out.pre node.text # content.gsub(/</, "&lt;").gsub(/>/, "&gt;")
471
+ end
472
+
473
+ def error_parse(node, out)
474
+ # catch elements not defined in ISO
475
+ case node.name
476
+ when "pre"
477
+ pre_parse(node, out)
478
+ when "keyword"
479
+ out.span node.text, **{ class: "keyword" }
480
+ else
481
+ super
482
+ end
483
+ end
484
+ --
485
+
486
+ * Render term headings in the same paragraph as the term heading number
487
+
488
+ [source,ruby]
489
+ --
490
+ def term_cleanup(docxml)
491
+ docxml.xpath("//p[@class = 'Terms']").each do |d|
492
+ h2 = d.at("./preceding-sibling::*[@class = 'TermNum'][1]")
493
+ h2.add_child("&nbsp;")
494
+ h2.add_child(d.remove)
495
+ end
496
+ docxml
497
+ end
498
+ --
499
+
500
+
501
+ == How can I style the resulting HTML output?
82
502
 
83
503
  [TIP]
84
504
  ====
@@ -99,18 +519,19 @@ Styling of output is intended to be configurable. HTML stylesheets are expressed
99
519
  * The SCSS stylesheets treat fonts as variables. Those variables are set in `default_fonts()`, which generates variable assignments for SCSS. Stylesheets normally recognise three fonts: `$bodyfont` for body text, `$headerfont` for headers and captions (which may be the same font as `$bodyfont`), and `$monospacefont` for monospace text. Note that `default_fonts()` takes the options passed to initialise `HtmlConvert` as a paremeter; the document language and script can be used to make different font choices for different document scripts. (The existing gems refer to `Latn`, Latin script, and `Hans`, Simplified Chinese script.)
100
520
  * Javascript scripts are populated in `scripts.html`; the scripts already in place in any gem you modify are in live use, and you should work out what they do before removing them. The AnchorJS script, for example, is used to generate navigable anchors in the document.
101
521
  * Additional scripts and fonts may be loaded in the document head through the `html_head()` method of `IsoDoc::...::HtmlConvert`. The existing gems use the document head to load Jquery, the Table of Contents generation script, Google Fonts, and Font Awesome.
102
- * An HTML document is populated as follows:
103
- ** HTML Head wrapper (in `IsoDoc::HtmlConvert`)
104
- *** `html_head()` content
105
- *** `@htmlstylesheet` CSS stylesheet (expected to be in SCSS, generated from SCSS in the `generate_css()` method of `Isodoc::HtmlConvert`).
106
- ** HTML Body
107
- *** `@htmlcoverpage` HTML template (optional, corresponds to `html_..._titlepage.html`)
108
- *** `@htmlintropage` HTML template (optional, corresponds to `html_..._intro.html`)
109
- *** Document proper (converted from Standoc XML)
110
- *** `@scripts` Javascript Scripts (optional, corresponds to `scripts.html`)
111
522
  * The classes in the SCSS stylesheet correspond to static HTML content in the HTML templates, and dynamic HTML content in the `IsoDoc::...::HtmlConvert` class, and its superclasses `IsoDoc::HtmlConvert` and `IsoDoc::Common` in the isodoc gem.
112
523
 
113
- = How can I style the resulting Word output?
524
+ An HTML document is populated as follows:
525
+ * HTML Head wrapper (in `IsoDoc::HtmlConvert`)
526
+ ** `html_head()` content
527
+ ** `@htmlstylesheet` CSS stylesheet (expected to be in SCSS, generated from SCSS in the `generate_css()` method of `Isodoc::HtmlConvert`).
528
+ * HTML Body
529
+ ** `@htmlcoverpage` HTML template (optional, corresponds to `html_..._titlepage.html`)
530
+ ** `@htmlintropage` HTML template (optional, corresponds to `html_..._intro.html`)
531
+ ** Document proper (converted from Standoc XML)
532
+ ** `@scripts` Javascript Scripts (optional, corresponds to `scripts.html`)
533
+
534
+ == How can I style the resulting Word output?
114
535
 
115
536
  [TIP]
116
537
  ====
@@ -138,17 +559,18 @@ The process for generating Word output is fairly similar to that for generating
138
559
  * As with HTML output, the HTML templates are populated through Liquid Templates: variables in `{{` correspond to the hash keys for metadata extracted in `IsoDoc::...::Metadata`, and its superclass `IsoDoc::Metadata` in the isodoc gem.
139
560
  * As with HTML, the SCSS stylesheets treat fonts as variables, and are set in the `default_fonts()` method of `IsoDoc::...::WordConvert`.
140
561
  * Document headers and footers are set in the `header.html` file. This is also an HTML template, which is populated with metadata attributes through Liquid Template. The structure of `header.html` is determined by Word, and elements of `header.html` need to be crossreferenced from the Word stylesheet. To inspect Word `header.html` files, save a Word document as HTML, and look inside the `{document_name}.fld` folder generated alongside the HTML output.
141
- * A Word HTML document is populated as follows:
142
- ** HTML Head wrapper (in `IsoDoc::WordConvert`)
143
- *** `@wordstylesheet` CSS stylesheet (generated from SCSS through the `generate_css()` method of `Isodoc::WordConvert`); corresponds to `wordstyle.scss`.
144
- *** `@standstylesheet` CSS stylesheet (generated from SCSS through the `generate_css()` method of `Isodoc::WordConvert`); intended to override any generic CSS in `@wordstylesheet`. Optional, corresponds to `{name_of_standard}.scss`.
145
- ** HTML Body
146
- *** `@wordcoverpage` HTML template (optional, corresponds to `word_..._titlepage.html`). Included in `<div class=WordSection1>`.
147
- *** `@htmlintropage` HTML template (optional, corresponds to `word_..._intro.html`). Included in `<div class=WordSection2>`. In the existing gems, WordSection2 is paginated with roman numerals.
148
- *** Document proper (converted from Standoc XML). Included in `<div class=WordSection2>` (prefatory material) and `<div class=WordSection3>` (main document). In the existing gems, WordSection3 is paginated with roman numerals.
149
562
  * The classes in the SCSS stylesheet correspond to static HTML content in the HTML templates, and dynamic HTML content in the `IsoDoc::...::WordConvert` class, and its superclasses `IsoDoc::WordConvert` and `IsoDoc::Common` in the isodoc gem.
150
563
 
151
- = How can I localize the resulting output?
564
+ A Word HTML document is populated as follows:
565
+ * HTML Head wrapper (in `IsoDoc::WordConvert`)
566
+ ** `@wordstylesheet` CSS stylesheet (generated from SCSS through the `generate_css()` method of `Isodoc::WordConvert`); corresponds to `wordstyle.scss`.
567
+ ** `@standstylesheet` CSS stylesheet (generated from SCSS through the `generate_css()` method of `Isodoc::WordConvert`); intended to override any generic CSS in `@wordstylesheet`. Optional, corresponds to `{name_of_standard}.scss`.
568
+ * HTML Body
569
+ ** `@wordcoverpage` HTML template (optional, corresponds to `word_..._titlepage.html`). Included in `<div class=WordSection1>`.
570
+ ** `@htmlintropage` HTML template (optional, corresponds to `word_..._intro.html`). Included in `<div class=WordSection2>`. In the existing gems, WordSection2 is paginated with roman numerals.
571
+ ** Document proper (converted from Standoc XML). Included in `<div class=WordSection2>` (prefatory material) and `<div class=WordSection3>` (main document). In the existing gems, WordSection3 is paginated with roman numerals.
572
+
573
+ == How can I localize the resulting output?
152
574
 
153
575
  [TIP]
154
576
  ====
@@ -161,7 +583,7 @@ Every piece of text generated by the toolset instead of the author is looked up
161
583
 
162
584
  The localisation files are http://yaml.org[YAML] files stores in `lib/isodoc/`, named `i18n-{languagecode}.yaml`. (In the case of Chinese, the script code is added to the filename: `i18n-zh-Hans.yaml`.) Most localised text are direct mappings from English metalanguage to the target language (including English itself); there are also instances of hashes in the YAML files. Most localisation text consists of one- or two-word labels, such as "Figure" or "Annex"; some boilerplate text is also included in the localisation text, such as the ISO text describing the use of external sources in Terms and Definitions.
163
585
 
164
- Localisation is mostly used for translation purposes, but they can also be used to customise the rendering of particular labels in English. For example, the default English label for a first-level supplementary section is "Annex", reflecting ISO practice; but in the metanorma-csd gem, this label is overruled in code to be "Appendix" instead.
586
+ Localisation is mostly used for translation purposes, but they can also be used to customise the rendering of particular labels in English. For example, the default English label for a first-level supplementary section is "Annex", reflecting ISO practice; but in the metanorma-sample gem, as seen above, this label is overruled in code to be "Appendix" instead.
165
587
 
166
588
  The YAML files are read into the `IsoDoc` classes through the `i18n_init()` method of `IsoDoc::...::HtmlConvert` and `Isodoc::...::WordConvert`. The localisation equivalents for the nominated language are read from the corresponding YAML file into the `@labels` hash. The base Isodoc instance of `i18n_init()` also assigns an instance variable for each label (e.g. `@annex_lbl` for English "Annex"). These instance variables are used to generate all automated text in the Isodoc classes.
167
589
 
@@ -169,7 +591,44 @@ All current gems inherit their localisation files from the base isodoc gem. The
169
591
 
170
592
  The foregoing describes how to incorporate localisation into your gem on a permanent basis; but the toolset also allows you to nominate a YAML localisation file just for the current document. In Asciidoc, the YAML file is nominated as the i18nyaml document attribute; for IsoDoc, it is passed in as the `i18nyaml` hash attribute to the initialisation method. You will still need to access the base IsoDoc YAML instances, to make sure that all necessary labels are given in your YAML document.
171
593
 
172
- = I can translate my specifications into IsoDoc XML myself (i.e. I don't like AsciiDoc, or I already have my own toolchain). Can I only use IsoDoc XML to produce pretty output?
594
+ === Example internationalisation code
595
+
596
+ * metanorma-mpfd/lib/isodoc/mpfd/i18n-en.yaml: customisation of clause label in YAML
597
+
598
+ [source]
599
+ --
600
+ clause: Paragraph
601
+ --
602
+
603
+ * metanorma-m3d/lib/isodoc/m3d/m3dhtmlconvert.rb: customisation of annex label as class variable
604
+
605
+ [source,ruby]
606
+ --
607
+ def i18n_init(lang, script)
608
+ super
609
+ @annex_lbl = "Appendix"
610
+ end
611
+ --
612
+
613
+ * metanorma-gb/lib/isodoc/gb/gbhtmlconvert.rb: code to read in internationalisation YAML templates (merges superclass `@labels` map, derived from the parent Isodoc::HtmlConvert class, with the labels read in from the GB-specific YAML templates.)
614
+
615
+ [source,ruby]
616
+ --
617
+ def i18n_init(lang, script)
618
+ super
619
+ y = if lang == "en"
620
+ YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml"))
621
+ elsif lang == "zh" && script == "Hans"
622
+ YAML.load_file(File.join(File.dirname(__FILE__),
623
+ "i18n-zh-Hans.yaml"))
624
+ else
625
+ YAML.load_file(File.join(File.dirname(__FILE__), "i18n-zh-Hans.yaml"))
626
+ end
627
+ @labels = @labels.merge(y)
628
+ end
629
+ --
630
+
631
+ == I can translate my specifications into IsoDoc XML myself (i.e. I don't like AsciiDoc, or I already have my own toolchain). Can I only use IsoDoc XML to produce pretty output?
173
632
 
174
633
  [TIP]
175
634
  ====