metanorma-mpfd 0.0.2

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.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/.travis.yml +17 -0
  4. data/CODE_OF_CONDUCT.md +74 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE +25 -0
  7. data/README.adoc +1 -0
  8. data/Rakefile +6 -0
  9. data/bin/console +14 -0
  10. data/bin/rspec +18 -0
  11. data/bin/setup +8 -0
  12. data/lib/asciidoctor/mpfd/biblio.rng +836 -0
  13. data/lib/asciidoctor/mpfd/converter.rb +204 -0
  14. data/lib/asciidoctor/mpfd/isodoc.rng +1041 -0
  15. data/lib/asciidoctor/mpfd/isostandard.rng +1001 -0
  16. data/lib/asciidoctor/mpfd/pdf.js +31 -0
  17. data/lib/asciidoctor/mpfd/rsd.rng +212 -0
  18. data/lib/asciidoctor/mpfd/section.rb +94 -0
  19. data/lib/asciidoctor/mpfd/version.rb +5 -0
  20. data/lib/asciidoctor/mpfd.rb +9 -0
  21. data/lib/isodoc/mpfd/html/header.html +184 -0
  22. data/lib/isodoc/mpfd/html/html_rsd_intro.html +8 -0
  23. data/lib/isodoc/mpfd/html/html_rsd_titlepage.html +58 -0
  24. data/lib/isodoc/mpfd/html/htmlstyle.scss +1094 -0
  25. data/lib/isodoc/mpfd/html/logo.jpg +0 -0
  26. data/lib/isodoc/mpfd/html/logo.svg +1 -0
  27. data/lib/isodoc/mpfd/html/mpfa-logo-no-text@4x.png +0 -0
  28. data/lib/isodoc/mpfd/html/mpfa-logo@4x.png +0 -0
  29. data/lib/isodoc/mpfd/html/rsd.scss +564 -0
  30. data/lib/isodoc/mpfd/html/scripts.html +82 -0
  31. data/lib/isodoc/mpfd/html/word_rsd_intro.html +3 -0
  32. data/lib/isodoc/mpfd/html/word_rsd_titlepage.html +42 -0
  33. data/lib/isodoc/mpfd/html/wordstyle.scss +1096 -0
  34. data/lib/isodoc/mpfd/html_convert.rb +370 -0
  35. data/lib/isodoc/mpfd/i18n-en.yaml +1 -0
  36. data/lib/isodoc/mpfd/metadata.rb +98 -0
  37. data/lib/isodoc/mpfd/pdf_convert.rb +367 -0
  38. data/lib/isodoc/mpfd/word_convert.rb +347 -0
  39. data/lib/metanorma/mpfd/processor.rb +43 -0
  40. data/lib/metanorma/mpfd.rb +7 -0
  41. data/lib/metanorma-mpfd.rb +11 -0
  42. data/metanorma-mpfd.gemspec +46 -0
  43. metadata +326 -0
@@ -0,0 +1,204 @@
1
+ require "asciidoctor"
2
+ require "asciidoctor/mpfd"
3
+ require "asciidoctor/iso/converter"
4
+ require "isodoc/mpfd/html_convert"
5
+ require "isodoc/mpfd/word_convert"
6
+ require_relative "section"
7
+
8
+ module Asciidoctor
9
+ module Mpfd
10
+
11
+ # A {Converter} implementation that generates MPFD output, and a document
12
+ # schema encapsulation of the document for validation
13
+ #
14
+ class Converter < ISO::Converter
15
+
16
+ register_for "mpfd"
17
+
18
+ def metadata_author(node, xml)
19
+ xml.contributor do |c|
20
+ c.role **{ type: "author" }
21
+ c.organization do |a|
22
+ a.name "Mandatory Provident Fund Schemes Authority"
23
+ a.abbreviation "MPFA"
24
+ end
25
+ end
26
+ end
27
+
28
+ def metadata_publisher(node, xml)
29
+ xml.contributor do |c|
30
+ c.role **{ type: "publisher" }
31
+ c.organization do |a|
32
+ a.name "Mandatory Provident Fund Schemes Authority"
33
+ a.abbreviation "MPFA"
34
+ end
35
+ end
36
+ end
37
+
38
+ def metadata_committee(node, xml)
39
+ xml.editorialgroup do |a|
40
+ a.committee node.attr("committee"),
41
+ **attr_code(type: node.attr("committee-type"))
42
+ end
43
+ end
44
+
45
+ def title(node, xml)
46
+ ["en"].each do |lang|
47
+ xml.title **{ language: lang, format: "plain" } do |t|
48
+ t << asciidoc_sub(node.attr("title"))
49
+ end
50
+ end
51
+ end
52
+
53
+ def metadata_status(node, xml)
54
+ xml.status(**{ format: "plain" }) { |s| s << node.attr("status") }
55
+ end
56
+
57
+ def metadata_id(node, xml)
58
+ xml.docidentifier { |i| i << node.attr("docnumber") }
59
+ end
60
+
61
+ def metadata_copyright(node, xml)
62
+ from = node.attr("copyright-year") || Date.today.year
63
+ xml.copyright do |c|
64
+ c.from from
65
+ c.owner do |owner|
66
+ owner.organization do |o|
67
+ o.name "Mandatory Provident Fund Schemes Authority"
68
+ o.abbreviation "MPFA"
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+ def title_validate(root)
75
+ nil
76
+ end
77
+
78
+ def makexml(node)
79
+ result = ["<?xml version='1.0' encoding='UTF-8'?>\n<mpfd-standard>"]
80
+ @draft = node.attributes.has_key?("draft")
81
+ result << noko { |ixml| front node, ixml }
82
+ result << noko { |ixml| middle node, ixml }
83
+ result << "</mpfd-standard>"
84
+ result = textcleanup(result.flatten * "\n")
85
+ ret1 = cleanup(Nokogiri::XML(result))
86
+ validate(ret1)
87
+ ret1.root.add_namespace(nil, MPFD_NAMESPACE)
88
+ ret1
89
+ end
90
+
91
+ def doctype(node)
92
+ d = node.attr("doctype")
93
+ =begin
94
+ unless %w{policy-and-procedures best-practices supporting-document report legal directives proposal standard}.include? d
95
+ warn "#{d} is not a legal document type: reverting to 'standard'"
96
+ d = "standard"
97
+ end
98
+ =end
99
+ d
100
+ end
101
+
102
+ def pdf_convert(filename)
103
+ url = "#{Dir.pwd}/#{filename}.html"
104
+ pdfjs = File.join(File.dirname(__FILE__), 'pdf.js')
105
+ system "export NODE_PATH=$(npm root --quiet -g);
106
+ node #{pdfjs} file://#{url} #{filename}.pdf"
107
+ end
108
+
109
+ def document(node)
110
+ init(node)
111
+ ret1 = makexml(node)
112
+ ret = ret1.to_xml(indent: 2)
113
+ unless node.attr("nodoc") || !node.attr("docfile")
114
+ filename = node.attr("docfile").gsub(/\.adoc/, ".xml").
115
+ gsub(%r{^.*/}, "")
116
+ File.open(filename, "w") { |f| f.write(ret) }
117
+ html_converter(node).convert filename unless node.attr("nodoc")
118
+ word_converter(node).convert filename unless node.attr("nodoc")
119
+ pdf_convert(filename.sub(/\.xml$/, "")) unless node.attr("nodoc")
120
+ end
121
+ @files_to_delete.each { |f| system "rm #{f}" }
122
+ ret
123
+ end
124
+
125
+ def validate(doc)
126
+ content_validate(doc)
127
+ schema_validate(formattedstr_strip(doc.dup),
128
+ File.join(File.dirname(__FILE__), "rsd.rng"))
129
+ end
130
+
131
+ def rsd_html_path(file)
132
+ File.join(File.dirname(__FILE__), File.join("html", file))
133
+ end
134
+
135
+ def literal(node)
136
+ noko do |xml|
137
+ xml.figure **id_attr(node) do |f|
138
+ figure_title(node, f)
139
+ f.pre node.lines.join("\n")
140
+ end
141
+ end
142
+ end
143
+
144
+ def sections_cleanup(x)
145
+ super
146
+ x.xpath("//*[@inline-header]").each do |h|
147
+ h.delete("inline-header")
148
+ end
149
+ end
150
+
151
+ def style(n, t)
152
+ return
153
+ end
154
+
155
+ def html_converter(node)
156
+ IsoDoc::Mpfd::HtmlConvert.new(
157
+ script: node.attr("script"),
158
+ bodyfont: node.attr("body-font"),
159
+ headerfont: node.attr("header-font"),
160
+ monospacefont: node.attr("monospace-font"),
161
+ titlefont: node.attr("title-font"),
162
+ i18nyaml: node.attr("i18nyaml"),
163
+ scope: node.attr("scope"),
164
+ )
165
+ end
166
+
167
+ def word_converter(node)
168
+ IsoDoc::Mpfd::WordConvert.new(
169
+ script: node.attr("script"),
170
+ bodyfont: node.attr("body-font"),
171
+ headerfont: node.attr("header-font"),
172
+ monospacefont: node.attr("monospace-font"),
173
+ titlefont: node.attr("title-font"),
174
+ i18nyaml: node.attr("i18nyaml"),
175
+ scope: node.attr("scope"),
176
+ )
177
+ end
178
+
179
+ def inline_quoted(node)
180
+ noko do |xml|
181
+ case node.type
182
+ when :emphasis then xml.em node.text
183
+ when :strong then xml.strong node.text
184
+ when :monospaced then xml.tt node.text
185
+ when :double then xml << "\"#{node.text}\""
186
+ when :single then xml << "'#{node.text}'"
187
+ when :superscript then xml.sup node.text
188
+ when :subscript then xml.sub node.text
189
+ when :asciimath then stem_parse(node.text, xml)
190
+ else
191
+ case node.role
192
+ when "strike" then xml.strike node.text
193
+ when "smallcap" then xml.smallcap node.text
194
+ when "keyword" then xml.keyword node.text
195
+ else
196
+ xml << node.text
197
+ end
198
+ end
199
+ end.join
200
+ end
201
+
202
+ end
203
+ end
204
+ end