metanorma-iso 3.4.8 → 3.4.9
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +9 -0
- data/lib/isodoc/iso/html/style-human.css +5 -0
- data/lib/isodoc/iso/html/style-iso.css +5 -0
- data/lib/isodoc/iso/iso.amendment.xsl +113 -66
- data/lib/isodoc/iso/iso.international-standard.xsl +113 -66
- data/lib/isodoc/iso/presentation_xml_convert.rb +16 -0
- data/lib/metanorma/iso/basicdoc.rng +1 -1
- data/lib/metanorma/iso/cleanup_biblio.rb +28 -24
- data/lib/metanorma/iso/front_id.rb +4 -0
- data/lib/metanorma/iso/{mathml3-content.rng → mathml4-content.rng} +104 -80
- data/lib/metanorma/iso/mathml4-core.rng +1041 -0
- data/lib/metanorma/iso/{mathml3-presentation.rng → mathml4-presentation.rng} +184 -1060
- data/lib/metanorma/iso/{mathml3-strict-content.rng → mathml4-strict-content.rng} +92 -8
- data/lib/metanorma/iso/mathml4.rng +30 -0
- data/lib/metanorma/iso/metanorma-mathml.rng +22 -8
- data/lib/metanorma/iso/processor.rb +32 -2
- data/lib/metanorma/iso/sts/transformer/back_transformer.rb +85 -0
- data/lib/metanorma/iso/sts/transformer/base.rb +118 -0
- data/lib/metanorma/iso/sts/transformer/block_dispatcher.rb +109 -0
- data/lib/metanorma/iso/sts/transformer/body_transformer.rb +39 -0
- data/lib/metanorma/iso/sts/transformer/content_text.rb +40 -0
- data/lib/metanorma/iso/sts/transformer/context.rb +64 -0
- data/lib/metanorma/iso/sts/transformer/def_list_transformer.rb +57 -0
- data/lib/metanorma/iso/sts/transformer/document_transformer.rb +30 -0
- data/lib/metanorma/iso/sts/transformer/example_transformer.rb +41 -0
- data/lib/metanorma/iso/sts/transformer/figure_transformer.rb +44 -0
- data/lib/metanorma/iso/sts/transformer/footnote_collector.rb +82 -0
- data/lib/metanorma/iso/sts/transformer/formula_transformer.rb +38 -0
- data/lib/metanorma/iso/sts/transformer/front_transformer.rb +56 -0
- data/lib/metanorma/iso/sts/transformer/id_generator.rb +181 -0
- data/lib/metanorma/iso/sts/transformer/inline_transformer.rb +293 -0
- data/lib/metanorma/iso/sts/transformer/iso_meta_transformer.rb +374 -0
- data/lib/metanorma/iso/sts/transformer/list_transformer.rb +65 -0
- data/lib/metanorma/iso/sts/transformer/nbsp_processor.rb +43 -0
- data/lib/metanorma/iso/sts/transformer/note_transformer.rb +43 -0
- data/lib/metanorma/iso/sts/transformer/paragraph_transformer.rb +28 -0
- data/lib/metanorma/iso/sts/transformer/quote_transformer.rb +17 -0
- data/lib/metanorma/iso/sts/transformer/reference_transformer.rb +136 -0
- data/lib/metanorma/iso/sts/transformer/section_transformer.rb +102 -0
- data/lib/metanorma/iso/sts/transformer/sourcecode_transformer.rb +18 -0
- data/lib/metanorma/iso/sts/transformer/standard.rb +33 -0
- data/lib/metanorma/iso/sts/transformer/table_transformer.rb +99 -0
- data/lib/metanorma/iso/sts/transformer/term_transformer.rb +227 -0
- data/lib/metanorma/iso/sts/transformer.rb +52 -0
- data/lib/metanorma/iso/sts.rb +38 -0
- data/lib/metanorma/iso/version.rb +1 -1
- data/lib/metanorma-iso.rb +1 -0
- data/metanorma-iso.gemspec +2 -0
- metadata +63 -7
- data/.hound.yml +0 -5
- data/lib/metanorma/iso/mathml3-common.rng +0 -257
- data/lib/metanorma/iso/mathml3.rng +0 -23
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Metanorma
|
|
4
|
+
module Iso
|
|
5
|
+
module Sts
|
|
6
|
+
class Transformer::ListTransformer < Transformer::Base
|
|
7
|
+
OL_TYPE_MAP = {
|
|
8
|
+
"arabic" => "order",
|
|
9
|
+
"loweralpha" => "alpha-lower",
|
|
10
|
+
"upperalpha" => "alpha-upper",
|
|
11
|
+
"lowerroman" => "roman-lower",
|
|
12
|
+
"upperroman" => "roman-upper",
|
|
13
|
+
}.freeze
|
|
14
|
+
|
|
15
|
+
def transform(source)
|
|
16
|
+
build_ordered(::Sts::IsoSts::List) do |list|
|
|
17
|
+
list.id = source.id if source.id && !source.id.start_with?("_")
|
|
18
|
+
list.list_type = list_type_for(source)
|
|
19
|
+
|
|
20
|
+
source.listitem&.each do |li|
|
|
21
|
+
list.list_item transform_list_item(li)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
def list_type_for(source)
|
|
29
|
+
case source
|
|
30
|
+
when Metanorma::Document::Components::Lists::UnorderedList
|
|
31
|
+
"bullet"
|
|
32
|
+
when Metanorma::Document::Components::Lists::OrderedList
|
|
33
|
+
OL_TYPE_MAP[source.type] || "order"
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def transform_list_item(li)
|
|
38
|
+
build_ordered(::Sts::IsoSts::ListItem) do |item|
|
|
39
|
+
item.id = li.id if li.id && !li.id.start_with?("_")
|
|
40
|
+
|
|
41
|
+
if li.content_text && !li.content_text.empty?
|
|
42
|
+
item.p paragraph_transformer.transform(
|
|
43
|
+
build_text_paragraph(li.content_text),
|
|
44
|
+
)
|
|
45
|
+
elsif li.paragraphs && !li.paragraphs.empty?
|
|
46
|
+
li.paragraphs.each do |para|
|
|
47
|
+
item.p paragraph_transformer.transform(para)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
li.unordered_lists&.each { |ul| item.list transform(ul) }
|
|
52
|
+
li.ordered_lists&.each { |ol| item.list transform(ol) }
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def build_text_paragraph(text_array)
|
|
57
|
+
text = text_array.is_a?(Array) ? text_array.join : text_array.to_s
|
|
58
|
+
para = Metanorma::Document::Components::Paragraphs::ParagraphBlock.new
|
|
59
|
+
para.text = [text]
|
|
60
|
+
para
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Metanorma
|
|
4
|
+
module Iso
|
|
5
|
+
module Sts
|
|
6
|
+
class Transformer::NbspProcessor
|
|
7
|
+
NBSP = " "
|
|
8
|
+
|
|
9
|
+
RULES = [
|
|
10
|
+
[/(Part) (\d)/i, "\\1#{NBSP}\\2"],
|
|
11
|
+
[/(\d) (%)/, "\\1#{NBSP}\\2"],
|
|
12
|
+
[/(ISO[\/&]?(?:TC|IEC)?) (\d)/i, "\\1#{NBSP}\\2"],
|
|
13
|
+
[/(NOTE) (\d)/i, "\\1#{NBSP}\\2"],
|
|
14
|
+
[/(Note)\s(\d)\s(to entry)/i, "\\1#{NBSP}\\2#{NBSP}\\3"],
|
|
15
|
+
[/(Table|Figure|Clause|Volume) (([A-Za-z]\.)?\d)/i,
|
|
16
|
+
"\\1#{NBSP}\\2"],
|
|
17
|
+
[/(Formula) (\()/i, "\\1#{NBSP}\\2"],
|
|
18
|
+
[/(Annex) ([A-Za-z])/i, "\\1#{NBSP}\\2"],
|
|
19
|
+
[/ (— [A-Z])/, "#{NBSP}\\1"],
|
|
20
|
+
].freeze
|
|
21
|
+
|
|
22
|
+
def self.process(text)
|
|
23
|
+
return text unless text.is_a?(String)
|
|
24
|
+
|
|
25
|
+
RULES.reduce(text) do |t, (pattern, replacement)|
|
|
26
|
+
t.gsub(pattern, replacement)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Apply the NBSP rules to every text node of a serialised XML string
|
|
31
|
+
# (walks each +>text<+ run). Used as the metanorma-core
|
|
32
|
+
# +document_transformers+ +:post_process+ hook, replacing the
|
|
33
|
+
# previously-private DocumentTransformer#apply_nbsp_to_text.
|
|
34
|
+
#
|
|
35
|
+
# @param xml [String] serialised STS XML.
|
|
36
|
+
# @return [String] XML with NBSP rules applied to text content.
|
|
37
|
+
def self.apply_to_text(xml)
|
|
38
|
+
xml.gsub(/>([^<]+)</) { ">#{process(Regexp.last_match(1))}<" }
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Metanorma
|
|
4
|
+
module Iso
|
|
5
|
+
module Sts
|
|
6
|
+
class Transformer::NoteTransformer < Transformer::Base
|
|
7
|
+
def transform(source)
|
|
8
|
+
build_ordered(::Sts::IsoSts::NonNormativeNote) do |note|
|
|
9
|
+
note.id = source.id if source.id && !source.id.start_with?("_")
|
|
10
|
+
|
|
11
|
+
transform_note_content(source, note)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
def transform_note_content(source, note)
|
|
18
|
+
source.each_mixed_content do |node|
|
|
19
|
+
next if node.is_a?(String)
|
|
20
|
+
|
|
21
|
+
dispatch_block(node, note)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def dispatch_block(node, target)
|
|
26
|
+
case node
|
|
27
|
+
when Metanorma::Document::Components::Paragraphs::ParagraphBlock
|
|
28
|
+
target.p paragraph_transformer.transform(node)
|
|
29
|
+
when Metanorma::Document::Components::Lists::UnorderedList,
|
|
30
|
+
Metanorma::Document::Components::Lists::OrderedList
|
|
31
|
+
target.list list_transformer.transform(node)
|
|
32
|
+
when Metanorma::Document::Components::Lists::DefinitionList
|
|
33
|
+
target.def_list def_list_transformer.transform(node)
|
|
34
|
+
when Metanorma::Document::Components::Blocks::NoteBlock
|
|
35
|
+
target.non_normative_note note_transformer.transform(node)
|
|
36
|
+
when Metanorma::Document::Components::AncillaryBlocks::ExampleBlock
|
|
37
|
+
target.non_normative_example example_transformer.transform(node)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Metanorma
|
|
4
|
+
module Iso
|
|
5
|
+
module Sts
|
|
6
|
+
class Transformer::ParagraphTransformer < Transformer::Base
|
|
7
|
+
def transform(source)
|
|
8
|
+
::Sts::IsoSts::Paragraph.new do |p|
|
|
9
|
+
p.id = paragraph_id(source)
|
|
10
|
+
p.content_type = source.type_attr if source.type_attr
|
|
11
|
+
p.content_type = source.class_attr if source.class_attr && !p.content_type
|
|
12
|
+
|
|
13
|
+
inline_transformer.apply_inline_content(source, p)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
def paragraph_id(source)
|
|
20
|
+
id = source.id
|
|
21
|
+
return nil unless id && !id.start_with?("_")
|
|
22
|
+
|
|
23
|
+
remap_id(id)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Metanorma
|
|
4
|
+
module Iso
|
|
5
|
+
module Sts
|
|
6
|
+
class Transformer::QuoteTransformer < Transformer::Base
|
|
7
|
+
def transform(quote)
|
|
8
|
+
build_ordered(::Sts::NisoSts::DispQuote) do |dq|
|
|
9
|
+
quote.paragraphs&.each do |para|
|
|
10
|
+
dq.p paragraph_transformer.transform(para)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Metanorma
|
|
4
|
+
module Iso
|
|
5
|
+
module Sts
|
|
6
|
+
class Transformer::ReferenceTransformer < Transformer::Base
|
|
7
|
+
def transform_list(ref_section)
|
|
8
|
+
normative = ref_section.normative == "true"
|
|
9
|
+
|
|
10
|
+
build_ordered(::Sts::IsoSts::RefList) do |rl|
|
|
11
|
+
rl.id = id_for(ref_section)
|
|
12
|
+
rl.content_type = normative ? "norm-refs" : "bibl"
|
|
13
|
+
|
|
14
|
+
if ref_section.title
|
|
15
|
+
rl.title transform_title(ref_section.title)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
if ref_section.p && !ref_section.p.empty?
|
|
19
|
+
ref_section.p.each do |para|
|
|
20
|
+
rl.p paragraph_transformer.transform(para)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
if ref_section.references && !ref_section.references.empty?
|
|
25
|
+
ref_section.references.each_with_index do |bibitem, idx|
|
|
26
|
+
rl.ref transform_bibitem(bibitem, idx + 1)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def transform_bibitem(bibitem, index)
|
|
33
|
+
build_ordered(::Sts::IsoSts::Ref) do |ref|
|
|
34
|
+
ref.id = "biblref_#{index}"
|
|
35
|
+
|
|
36
|
+
lbl = ::Sts::IsoSts::Label.new(content: ["[#{index}]"])
|
|
37
|
+
ref.label lbl
|
|
38
|
+
|
|
39
|
+
mc = build_mixed_citation(bibitem)
|
|
40
|
+
ref.mixed_citation mc if mc
|
|
41
|
+
|
|
42
|
+
std = build_std_for(bibitem)
|
|
43
|
+
ref.std std if std
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
private
|
|
48
|
+
|
|
49
|
+
def build_mixed_citation(bibitem)
|
|
50
|
+
mc = ::Sts::IsoSts::MixedCitation.new
|
|
51
|
+
|
|
52
|
+
doc_id = primary_docidentifier(bibitem)
|
|
53
|
+
title_text = reference_title(bibitem)
|
|
54
|
+
|
|
55
|
+
if doc_id
|
|
56
|
+
mc.content doc_id
|
|
57
|
+
if title_text
|
|
58
|
+
mc.content ", "
|
|
59
|
+
italic = ::Sts::IsoSts::Italic.new
|
|
60
|
+
italic.content title_text
|
|
61
|
+
mc.italic italic
|
|
62
|
+
end
|
|
63
|
+
elsif title_text
|
|
64
|
+
mc.content title_text
|
|
65
|
+
else
|
|
66
|
+
return nil
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
mc
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def build_std_for(bibitem)
|
|
73
|
+
doc_id = primary_docidentifier(bibitem)
|
|
74
|
+
return nil unless doc_id
|
|
75
|
+
|
|
76
|
+
std = ::Sts::IsoSts::Std.new
|
|
77
|
+
std.type = "dated"
|
|
78
|
+
|
|
79
|
+
dated_ref = ::Sts::IsoSts::StdRef.new
|
|
80
|
+
dated_ref.type = "dated"
|
|
81
|
+
dated_ref.content = [doc_id]
|
|
82
|
+
std.std_ref dated_ref
|
|
83
|
+
|
|
84
|
+
undated = undated_identifier(doc_id)
|
|
85
|
+
if undated && undated != doc_id
|
|
86
|
+
undated_ref = ::Sts::IsoSts::StdRef.new
|
|
87
|
+
undated_ref.type = "undated"
|
|
88
|
+
undated_ref.content = [undated]
|
|
89
|
+
std.std_ref undated_ref
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
std
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def primary_docidentifier(bibitem)
|
|
96
|
+
return nil unless bibitem.docidentifier
|
|
97
|
+
|
|
98
|
+
ids = Array(bibitem.docidentifier)
|
|
99
|
+
|
|
100
|
+
primary = ids.find { |d| d.primary == true }
|
|
101
|
+
return primary.id.to_s if primary&.id
|
|
102
|
+
|
|
103
|
+
iso_id = ids.find { |d| d.type == "ISO" }
|
|
104
|
+
return iso_id.id.to_s if iso_id&.id
|
|
105
|
+
|
|
106
|
+
ids.first&.id&.to_s
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def reference_title(bibitem)
|
|
110
|
+
return nil unless bibitem.title
|
|
111
|
+
|
|
112
|
+
titles = Array(bibitem.title)
|
|
113
|
+
|
|
114
|
+
main_title = titles.find { |t| t.type == "title-main" }
|
|
115
|
+
return extract_title_text(main_title) if main_title
|
|
116
|
+
|
|
117
|
+
extract_title_text(titles.first) if titles.first
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def extract_title_text(title)
|
|
121
|
+
return nil unless title
|
|
122
|
+
|
|
123
|
+
if title.content && !title.content.empty?
|
|
124
|
+
Array(title.content).join
|
|
125
|
+
elsif title.element_order && !title.element_order.empty?
|
|
126
|
+
inline_transformer.extract_text(title)
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def undated_identifier(doc_id)
|
|
131
|
+
doc_id.sub(/:\d{4}$/, "")
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Metanorma
|
|
4
|
+
module Iso
|
|
5
|
+
module Sts
|
|
6
|
+
class Transformer::SectionTransformer < Transformer::Base
|
|
7
|
+
SEC_TYPE_MAP = {
|
|
8
|
+
"intro" => "intro",
|
|
9
|
+
"scope" => "scope",
|
|
10
|
+
"overview" => "scope",
|
|
11
|
+
}.freeze
|
|
12
|
+
|
|
13
|
+
def transform(clause)
|
|
14
|
+
build_ordered(::Sts::IsoSts::Sec) do |sec|
|
|
15
|
+
sec.id = id_for(clause)
|
|
16
|
+
sec.sec_type = sec_type_for(clause)
|
|
17
|
+
|
|
18
|
+
label_text = label_for(clause)
|
|
19
|
+
sec.label = ::Sts::IsoSts::Label.new(content: [label_text]) if label_text
|
|
20
|
+
|
|
21
|
+
if title_for(clause)
|
|
22
|
+
sec.title transform_title(title_for(clause))
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
dispatch_content(clause, sec)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def transform_foreword(foreword)
|
|
30
|
+
build_ordered(::Sts::IsoSts::Sec) do |sec|
|
|
31
|
+
sec.id = "sec_foreword"
|
|
32
|
+
sec.sec_type = "foreword"
|
|
33
|
+
sec.title transform_title(foreword.title) if foreword.title
|
|
34
|
+
|
|
35
|
+
dispatch_content(foreword, sec, skip_title: true)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def transform_abstract(abstract)
|
|
40
|
+
build_ordered(::Sts::IsoSts::Sec) do |sec|
|
|
41
|
+
sec.id = "sec_abstract"
|
|
42
|
+
sec.sec_type = "abstract"
|
|
43
|
+
sec.title transform_title(abstract.title) if abstract.title
|
|
44
|
+
|
|
45
|
+
dispatch_content(abstract, sec)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def transform_introduction(intro)
|
|
50
|
+
build_ordered(::Sts::IsoSts::Sec) do |sec|
|
|
51
|
+
sec.id = "sec_intro"
|
|
52
|
+
sec.sec_type = "intro"
|
|
53
|
+
sec.title transform_title(intro.title) if intro.title
|
|
54
|
+
|
|
55
|
+
dispatch_content(intro, sec, skip_title: true)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def transform_annex(annex)
|
|
60
|
+
build_ordered(::Sts::IsoSts::Sec) do |sec|
|
|
61
|
+
sec.id = id_for(annex)
|
|
62
|
+
|
|
63
|
+
if annex.number && !annex.number.empty?
|
|
64
|
+
sec.label = ::Sts::IsoSts::Label.new(content: ["Annex #{annex.number}"])
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
sec.title transform_title(annex.title) if annex.title
|
|
68
|
+
|
|
69
|
+
dispatch_content(annex, sec, skip_title: true)
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
private
|
|
74
|
+
|
|
75
|
+
def dispatch_content(source, target, skip_title: false)
|
|
76
|
+
dispatcher = block_dispatcher
|
|
77
|
+
title_node = skip_title ? source.title : nil
|
|
78
|
+
|
|
79
|
+
source.each_mixed_content do |node|
|
|
80
|
+
next if node.is_a?(String)
|
|
81
|
+
next if node == title_node
|
|
82
|
+
next if skip_node?(node)
|
|
83
|
+
|
|
84
|
+
dispatcher.dispatch(node, target)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def sec_type_for(clause)
|
|
89
|
+
SEC_TYPE_MAP[clause.type]
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def label_for(clause)
|
|
93
|
+
clause.number if clause.number && !clause.number.empty?
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def title_for(clause)
|
|
97
|
+
clause.title
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Metanorma
|
|
4
|
+
module Iso
|
|
5
|
+
module Sts
|
|
6
|
+
class Transformer::SourcecodeTransformer < Transformer::Base
|
|
7
|
+
def transform(source)
|
|
8
|
+
::Sts::IsoSts::Preformat.new do |pre|
|
|
9
|
+
pre.id = source.id if source.id && !source.id.start_with?("_")
|
|
10
|
+
pre.preformat_type = source.lang if source.lang
|
|
11
|
+
|
|
12
|
+
inline_transformer.apply_inline_content(source, pre)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Metanorma
|
|
4
|
+
module Iso
|
|
5
|
+
module Sts
|
|
6
|
+
module Transformer
|
|
7
|
+
# Adapter conforming the STS transformer to the metanorma-core
|
|
8
|
+
# +document_transformers+ contract: +.new(model, options)+ plus
|
|
9
|
+
# +#transform+ returning a target (+::Sts::IsoSts::Standard+) that
|
|
10
|
+
# responds to +#to_xml+. It hides the +Context+ construction behind
|
|
11
|
+
# the (model, options) signature, so the metanorma-core driver treats
|
|
12
|
+
# STS exactly like any other document-model transformer.
|
|
13
|
+
class Standard
|
|
14
|
+
# @param model [Object] a metanorma-document model
|
|
15
|
+
# (+Metanorma::IsoDocument::Root+), as returned by the reader's
|
|
16
|
+
# +.from_xml+.
|
|
17
|
+
# @param options [Hash] processor options (accepted for interface
|
|
18
|
+
# conformance; not yet consumed).
|
|
19
|
+
def initialize(model, options = {})
|
|
20
|
+
@model = model
|
|
21
|
+
@options = options
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# @return [::Sts::IsoSts::Standard] the STS output model, which
|
|
25
|
+
# responds to +#to_xml+.
|
|
26
|
+
def transform
|
|
27
|
+
Transformer.transform(@model)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Metanorma
|
|
4
|
+
module Iso
|
|
5
|
+
module Sts
|
|
6
|
+
class Transformer::TableTransformer < Transformer::Base
|
|
7
|
+
def transform_wrap(table)
|
|
8
|
+
build_ordered(::Sts::TbxIsoTml::TableWrap) do |tw|
|
|
9
|
+
tw.id = id_for(table)
|
|
10
|
+
|
|
11
|
+
table_label = label_for(table)
|
|
12
|
+
tw.label table_label if table_label
|
|
13
|
+
|
|
14
|
+
if table.name
|
|
15
|
+
caption = build_ordered(::Sts::NisoSts::Caption) do |c|
|
|
16
|
+
inline_transformer.apply_inline_content(table.name, c)
|
|
17
|
+
end
|
|
18
|
+
tw.caption caption
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
tw.table transform(table)
|
|
22
|
+
|
|
23
|
+
if table.note && !table.note.empty?
|
|
24
|
+
table.note.each do |n|
|
|
25
|
+
tw.non_normative_note note_transformer.transform(n)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def transform(table)
|
|
32
|
+
build_ordered(::Sts::TbxIsoTml::Table) do |t|
|
|
33
|
+
t.width = table.width if table.width
|
|
34
|
+
t.summary = table.summary if table.summary
|
|
35
|
+
|
|
36
|
+
if table.colgroup
|
|
37
|
+
cg = build_ordered(::Sts::TbxIsoTml::Colgroup) do |colgroup|
|
|
38
|
+
Array(table.colgroup.col).each do |col|
|
|
39
|
+
c = ::Sts::TbxIsoTml::Col.new
|
|
40
|
+
c.width = col.width if col.width
|
|
41
|
+
colgroup.col c
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
t.colgroup cg
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
if table.thead
|
|
48
|
+
t.thead transform_section(table.thead,
|
|
49
|
+
::Sts::TbxIsoTml::Thead)
|
|
50
|
+
end
|
|
51
|
+
if table.tbody
|
|
52
|
+
t.tbody transform_section(table.tbody,
|
|
53
|
+
::Sts::TbxIsoTml::Tbody)
|
|
54
|
+
end
|
|
55
|
+
if table.tfoot
|
|
56
|
+
t.tfoot transform_section(table.tfoot,
|
|
57
|
+
::Sts::TbxIsoTml::Tfoot)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
private
|
|
63
|
+
|
|
64
|
+
def transform_section(section, klass)
|
|
65
|
+
inst = klass.new
|
|
66
|
+
Array(section.tr).each do |tr|
|
|
67
|
+
row = build_ordered(::Sts::TbxIsoTml::Tr) do |r|
|
|
68
|
+
Array(tr.th).each { |th| r.th transform_cell(th, ::Sts::TbxIsoTml::Th) }
|
|
69
|
+
Array(tr.td).each { |td| r.td transform_cell(td, ::Sts::TbxIsoTml::Td) }
|
|
70
|
+
end
|
|
71
|
+
inst.tr row
|
|
72
|
+
end
|
|
73
|
+
inst
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def transform_cell(cell, klass)
|
|
77
|
+
c = klass.new
|
|
78
|
+
c.id = cell.id if cell.id && !cell.id.start_with?("_")
|
|
79
|
+
c.colspan = cell.colspan.to_s if cell.colspan
|
|
80
|
+
c.rowspan = cell.rowspan.to_s if cell.rowspan
|
|
81
|
+
c.align = cell.align if cell.align
|
|
82
|
+
c.valign = cell.valign if cell.valign
|
|
83
|
+
|
|
84
|
+
if cell.element_order && !cell.element_order.empty?
|
|
85
|
+
inline_transformer.apply_inline_content(cell, c)
|
|
86
|
+
elsif cell.text && !cell.text.empty?
|
|
87
|
+
c.content Array(cell.text).join
|
|
88
|
+
end
|
|
89
|
+
c
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def label_for(table)
|
|
93
|
+
autonum = table.autonum if table.class.method_defined?(:autonum)
|
|
94
|
+
autonum && !autonum.to_s.empty? ? ::Sts::IsoSts::Label.new(content: [autonum.to_s]) : nil
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|