metanorma-plateau 0.1.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.
@@ -0,0 +1,41 @@
1
+ module Metanorma
2
+ module Plateau
3
+ class Converter < JIS::Converter
4
+ def bibdata_cleanup(xmldoc)
5
+ super
6
+ coverpage_images(xmldoc)
7
+ end
8
+
9
+ def coverpage_images(xmldoc)
10
+ %w(coverpage-image).each do |n|
11
+ xmldoc.xpath("//bibdata/ext/#{n}").each do |x|
12
+ ins = add_misc_container(xmldoc)
13
+ ins << "<presentation-metadata><name>#{n}</name>" \
14
+ "<value>#{x.remove.children.to_xml}</value>" \
15
+ "</presentation-metadata>"
16
+ end
17
+ end
18
+ end
19
+
20
+ def blocksource_cleanup(xmldoc)
21
+ xmldoc.xpath("//termsource").each do |s|
22
+ p = s.previous_element or next
23
+ %w[p ol ul dl].include? p.name or next
24
+ s.name = "source"
25
+ s.delete("type")
26
+ s.parent = p
27
+ end
28
+ super
29
+ end
30
+
31
+ def pub_class(bib)
32
+ return 1 if bib.at("#{PUBLISHER}[name = '#{pub_hash['en']}']") ||
33
+ bib.at("#{PUBLISHER}[name = '#{pub_hash['ja']}']") ||
34
+ bib.at("#{PUBLISHER}[abbreviation = 'MLIT']")
35
+ return 2 if bib["type"] == "standard"
36
+
37
+ 3
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,120 @@
1
+ require "metanorma-jis"
2
+ require_relative "cleanup"
3
+
4
+ module Metanorma
5
+ module Plateau
6
+ class Converter < JIS::Converter
7
+ register_for "plateau"
8
+
9
+ XML_ROOT_TAG = "plateau-standard".freeze
10
+ XML_NAMESPACE = "https://www.metanorma.org/ns/plateau".freeze
11
+
12
+ def default_requirement_model
13
+ "ogc"
14
+ end
15
+
16
+ def validate(doc)
17
+ content_validate(doc)
18
+ schema_validate(formattedstr_strip(doc.dup),
19
+ File.join(File.dirname(__FILE__), "plateau.rng"))
20
+ end
21
+
22
+ def org_abbrev
23
+ super.merge(pub_hash["en"] => "MLIT")
24
+ end
25
+
26
+ def default_publisher
27
+ "MLIT"
28
+ end
29
+
30
+ def init_misc(node)
31
+ super
32
+ @default_doctype = "technical-report"
33
+ end
34
+
35
+ # Plateau reuse of the JIS publisher default setting
36
+ def pub_hash
37
+ { "ja" => "国土交通省",
38
+ "en" => "Ministry of Land, Infrastructure, Transport and Tourism" }
39
+ end
40
+
41
+ def doctype_validate(_xmldoc)
42
+ %w(handbook technical-report annex).include? @doctype or
43
+ @log.add("Document Attributes", nil,
44
+ "#{@doctype} is not a recognised document type")
45
+ end
46
+
47
+ def metadata_ext(node, xml)
48
+ super
49
+ metadata_coverpage_images(node, xml)
50
+ end
51
+
52
+ def metadata_coverpage_images(node, xml)
53
+ %w(coverpage-image).each do |n|
54
+ if a = node.attr(n)
55
+ xml.send n do |c|
56
+ a.split(",").each do |x|
57
+ c.image src: x
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ def metadata_id(node, xml)
65
+ if id = node.attr("docidentifier")
66
+ xml.docidentifier "PLATEAU #{id.sub(/^PLATEAU /, '')}",
67
+ **attr_code(type: "PLATEAU", primary: "true")
68
+ else iso_id(node, xml)
69
+ end
70
+ end
71
+
72
+ # do not use pubid
73
+ def iso_id(node, xml)
74
+ id = node.attr("docnumber") or return
75
+ xml.docidentifier "PLATEAU #{id.sub(/^PLATEAU /, '')}",
76
+ **attr_code(type: "PLATEAU", primary: "true")
77
+ end
78
+
79
+ # do not use pubid
80
+ def metadata_status(node, xml)
81
+ stage = get_stage(node)
82
+ xml.status do |s|
83
+ s.stage stage
84
+ i = node.attr("iteration") and s.iteration i
85
+ end
86
+ end
87
+
88
+ def metadata_stage(node, xml); end
89
+
90
+ def html_converter(node)
91
+ if node.nil?
92
+ IsoDoc::Plateau::HtmlConvert.new({})
93
+ else
94
+ IsoDoc::Plateau::HtmlConvert.new(html_extract_attributes(node))
95
+ end
96
+ end
97
+
98
+ def pdf_converter(node)
99
+ return if node.attr("no-pdf")
100
+
101
+ if node.nil?
102
+ IsoDoc::Plateau::PdfConvert.new({})
103
+ else
104
+ IsoDoc::Plateau::PdfConvert.new(pdf_extract_attributes(node))
105
+ end
106
+ end
107
+
108
+ def presentation_xml_converter(node)
109
+ if node.nil?
110
+ IsoDoc::Plateau::PresentationXMLConvert.new({})
111
+ else
112
+ IsoDoc::Plateau::PresentationXMLConvert
113
+ .new(doc_extract_attributes(node)
114
+ .merge(output_formats: ::Metanorma::Plateau::Processor.new
115
+ .output_formats))
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end