metanorma-iso 3.5.38 → 3.5.39
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/Gemfile +1 -1
- data/README.adoc +13 -0
- data/docs/validation.md +137 -0
- data/lib/isodoc/iso/docx/middle_title_renderer.rb +1 -1
- data/lib/isodoc/iso/iso.amendment.xsl +9 -2
- data/lib/isodoc/iso/iso.international-standard.xsl +9 -2
- data/lib/metanorma/iso/html/renderer.rb +505 -508
- data/lib/metanorma/iso/themes/iso/theme.yaml +9 -2
- data/lib/metanorma/iso/themes/iso-legacy/theme.yaml +9 -2
- data/lib/metanorma/iso/validation/model_validator.rb +13 -0
- data/lib/metanorma/iso/validation/rules/base.rb +34 -0
- data/lib/metanorma/iso/validation/rules/doctype_rule.rb +4 -0
- data/lib/metanorma/iso/validation/rules/foreword_presence_rule.rb +4 -0
- data/lib/metanorma/iso/validation/rules/foreword_structure_rule.rb +4 -0
- data/lib/metanorma/iso/validation/rules/iteration_rule.rb +4 -0
- data/lib/metanorma/iso/validation/rules/normative_references_presence_rule.rb +4 -0
- data/lib/metanorma/iso/validation/rules/only_child_clause_rule.rb +4 -0
- data/lib/metanorma/iso/validation/rules/scope_presence_rule.rb +4 -0
- data/lib/metanorma/iso/validation/rules/scope_subclauses_rule.rb +4 -0
- data/lib/metanorma/iso/validation/rules/section_sequence_rule.rb +4 -0
- data/lib/metanorma/iso/validation/rules/style_abbrev_articles_rule.rb +5 -2
- data/lib/metanorma/iso/validation/rules/style_empty_clause_rule.rb +4 -0
- data/lib/metanorma/iso/validation/rules/subcommittee_type_rule.rb +4 -0
- data/lib/metanorma/iso/validation/rules/subpart_iec_rule.rb +4 -0
- data/lib/metanorma/iso/validation/rules/symbols_section_content_rule.rb +4 -0
- data/lib/metanorma/iso/validation/rules/symbols_section_count_rule.rb +4 -0
- data/lib/metanorma/iso/validation/rules/technical_committee_type_rule.rb +4 -0
- data/lib/metanorma/iso/validation/rules/termdef_style_rule.rb +4 -0
- data/lib/metanorma/iso/validation/rules/terms_presence_rule.rb +4 -0
- data/lib/metanorma/iso/validation/rules/title_first_level_rule.rb +4 -0
- data/lib/metanorma/iso/validation/rules/title_names_doctype_rule.rb +4 -0
- data/lib/metanorma/iso/validation/rules/title_pairing_rule.rb +4 -0
- data/lib/metanorma/iso/validation/rules/title_siblings_consistency_rule.rb +4 -0
- data/lib/metanorma/iso/version.rb +1 -1
- data/script/migrate-logo-records.rb +92 -0
- metadata +4 -2
|
@@ -9,560 +9,557 @@ module Metanorma
|
|
|
9
9
|
# boilerplate, foreword, annex formatting, and ISO term entries,
|
|
10
10
|
# on top of the harness's Standoc renderer. Registered with the
|
|
11
11
|
# harness (Metanorma::Html.register_flavor) from iso/document.rb.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
end
|
|
82
|
-
nil
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
def extract_stage(bibdata)
|
|
86
|
-
stages = Array(safe_attr(safe_attr(bibdata, :status), :stage))
|
|
87
|
-
return nil if stages.empty?
|
|
88
|
-
|
|
89
|
-
en_stage = stages.find do |s|
|
|
90
|
-
lang = safe_attr(s, :language)
|
|
91
|
-
lang == "en" if lang
|
|
92
|
-
end
|
|
93
|
-
return Array(en_stage.value).join.strip if en_stage&.value
|
|
94
|
-
|
|
95
|
-
seen = Set.new
|
|
96
|
-
stage_text = stages.filter_map do |s|
|
|
97
|
-
val = Array(s.value).join.strip
|
|
98
|
-
down = val.downcase
|
|
99
|
-
next if seen.include?(down)
|
|
100
|
-
|
|
101
|
-
seen << down
|
|
102
|
-
val.empty? ? nil : val
|
|
103
|
-
end.compact.join(" ")
|
|
104
|
-
stage_text.empty? ? nil : stage_text
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
# ISO unpublished stages are 00-59 (front_id: /^[0-5]/); the first
|
|
108
|
-
# numeric stage element decides.
|
|
109
|
-
def cover_draft_stage?(bibdata)
|
|
110
|
-
stages = Array(safe_attr(safe_attr(bibdata, :status), :stage))
|
|
111
|
-
code = stages.filter_map { |s| Array(s.value).join.strip }
|
|
112
|
-
.find { |val| /\A\d/.match?(val) }
|
|
113
|
-
!code.nil? && /^[0-5]/.match?(code)
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
def extract_doctype(bibdata)
|
|
117
|
-
return nil unless bibdata.is_a?(Metanorma::Iso::Document::Metadata::IsoBibliographicItem)
|
|
118
|
-
|
|
119
|
-
ext = bibdata.ext
|
|
120
|
-
return nil unless ext
|
|
121
|
-
|
|
122
|
-
doctypes = ext.doctype_element
|
|
123
|
-
return nil unless doctypes && !doctypes.empty?
|
|
124
|
-
|
|
125
|
-
en_dt = doctypes.find do |d|
|
|
126
|
-
lang = safe_attr(d, :language)
|
|
127
|
-
lang == "en" if lang
|
|
128
|
-
end
|
|
129
|
-
return en_dt.value.to_s if en_dt&.value
|
|
130
|
-
|
|
131
|
-
dt = doctypes.first
|
|
132
|
-
val = dt&.value.to_s
|
|
133
|
-
val.strip.empty? ? nil : val
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
# --- Top-level document rendering ---
|
|
137
|
-
|
|
138
|
-
def render_document(doc, **_opts)
|
|
139
|
-
parts = []
|
|
140
|
-
parts << (render_coverpage(doc) || "")
|
|
141
|
-
parts << (render_boilerplate_section(doc) || "")
|
|
142
|
-
|
|
143
|
-
parts << (render(doc.preface) || "") if doc.preface
|
|
144
|
-
parts << (render_doc_title(doc) || "")
|
|
145
|
-
|
|
146
|
-
all_items = collect_document_children(doc)
|
|
147
|
-
all_items.each do |node|
|
|
148
|
-
next if node.is_a?(String)
|
|
149
|
-
next if is_title_element?(node, doc.sections)
|
|
150
|
-
|
|
151
|
-
parts << (render(node) || "")
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
parts << (render_footnotes_section || "")
|
|
155
|
-
|
|
156
|
-
render_liquid("_main_content.html.liquid", {
|
|
157
|
-
"content" => parts.join,
|
|
158
|
-
})
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
# --- Cover page ---
|
|
162
|
-
|
|
163
|
-
def render_coverpage(doc)
|
|
164
|
-
bibdata = doc.bibdata
|
|
165
|
-
return "" unless bibdata
|
|
166
|
-
|
|
167
|
-
logos = publisher_logos_html(doc) || []
|
|
168
|
-
doctype = extract_doctype(bibdata)
|
|
169
|
-
title_text = cover_title(bibdata, "en")
|
|
170
|
-
title_fr = cover_title(bibdata, "fr")
|
|
171
|
-
# Amendments carry their own title line ("AMENDMENT 1: …") under
|
|
172
|
-
# each language's title on the isodoc titlepage.
|
|
173
|
-
title_text = [title_text, amendment_title_line(bibdata, "en")].compact.join(" ")
|
|
174
|
-
title_fr = [title_fr, amendment_title_line(bibdata, "fr")].compact.join(" ")
|
|
12
|
+
# Renders IsoDocument components to HTML.
|
|
13
|
+
# Extends StandardRenderer with ISO-specific cover page, boilerplate,
|
|
14
|
+
# foreword, introduction, annex formatting, and ISO term entries.
|
|
15
|
+
class Renderer < Metanorma::Html::StandardRenderer
|
|
16
|
+
# --- Flavor theme wiring ---
|
|
17
|
+
|
|
18
|
+
# Per-class flavor theme dir: each renderer subclass declares its
|
|
19
|
+
# own — ISO's renderer reads this gem's themes/iso; a derived
|
|
20
|
+
# flavor declares its gem's dir, or leaves it unset to resolve
|
|
21
|
+
# through the theme registry at the flavor's current canonical
|
|
22
|
+
# home. Deliberately a class-level ivar: subclasses do NOT
|
|
23
|
+
# inherit ISO's dir (the hardwired constant this replaces sent
|
|
24
|
+
# every derived flavor — m3aawg surfaced it — to ISO's theme).
|
|
25
|
+
@theme_dir = THEME_DIR
|
|
26
|
+
|
|
27
|
+
class << self
|
|
28
|
+
attr_accessor :theme_dir
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# The flavor's own theme dir, loaded through the same
|
|
32
|
+
# Theme.from_theme_dir path the harness's theme_override seam uses
|
|
33
|
+
# (BaseRenderer#load_theme_override): ISO rendering reads this
|
|
34
|
+
# gem's theme.yaml + custom.css + assets/ + templates/ directly
|
|
35
|
+
# and never falls back to the engine's data/themes copies. An
|
|
36
|
+
# explicit `theme:` passed to Generator.generate still wins.
|
|
37
|
+
def resolve_theme
|
|
38
|
+
return load_theme_override(@theme_override) if @theme_override
|
|
39
|
+
|
|
40
|
+
if (dir = self.class.theme_dir)
|
|
41
|
+
Metanorma::Html::Theme.from_theme_dir(dir)
|
|
42
|
+
else
|
|
43
|
+
Metanorma::Html::Theme.load(flavor_name)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# --- Public hooks for flavor customization ---
|
|
48
|
+
|
|
49
|
+
register_render "Metanorma::Iso::Document::Root", :render_document
|
|
50
|
+
register_render "Metanorma::Iso::Document::Sections::IsoPreface",
|
|
51
|
+
:render_preface
|
|
52
|
+
register_render "Metanorma::Iso::Document::Sections::IsoSections",
|
|
53
|
+
:render_sections
|
|
54
|
+
register_render "Metanorma::Iso::Document::Sections::IsoClauseSection",
|
|
55
|
+
:render_clause
|
|
56
|
+
register_render "Metanorma::Iso::Document::Sections::IsoAnnexSection",
|
|
57
|
+
:render_annex
|
|
58
|
+
register_render "Metanorma::Iso::Document::Sections::IsoTermsSection",
|
|
59
|
+
:render_terms_section
|
|
60
|
+
register_render "Metanorma::Iso::Document::Sections::IsoForewordSection",
|
|
61
|
+
:render_foreword
|
|
62
|
+
register_render "Metanorma::Iso::Document::Sections::IsoAbstractSection",
|
|
63
|
+
:render_abstract
|
|
64
|
+
register_render "Metanorma::Iso::Document::Terms::IsoTerm", :render_term
|
|
65
|
+
register_render "Metanorma::Iso::Document::Terms::TermNote", :render_term_note
|
|
66
|
+
register_render "Metanorma::Iso::Document::Terms::TermExample",
|
|
67
|
+
:render_term_example
|
|
68
|
+
register_render "Metanorma::Iso::Document::Boilerplate", :render_boilerplate
|
|
69
|
+
|
|
70
|
+
register_inline_render "Metanorma::Iso::Document::Terms::TermOrigin",
|
|
71
|
+
:render_term_origin
|
|
72
|
+
|
|
73
|
+
def render_term_origin(element)
|
|
74
|
+
text = extract_text_value(element)
|
|
75
|
+
return nil unless text
|
|
76
|
+
|
|
77
|
+
render_liquid("_inline_span.html.liquid", {
|
|
78
|
+
"attrs" => " class=\"term-source\"",
|
|
79
|
+
"content" => escape_html(text),
|
|
80
|
+
})
|
|
81
|
+
end
|
|
175
82
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
83
|
+
def extract_display_title(bibdata)
|
|
84
|
+
titles = safe_attr(bibdata, :titles)
|
|
85
|
+
return nil unless titles
|
|
86
|
+
|
|
87
|
+
en_title = if titles.is_a?(Metanorma::Iso::Document::Metadata::TitleCollection)
|
|
88
|
+
bibdata.title_for("en")
|
|
182
89
|
end
|
|
90
|
+
result = en_title&.to_s
|
|
91
|
+
return result if result && !result.empty?
|
|
92
|
+
|
|
93
|
+
if titles.is_a?(Metanorma::Iso::Document::Metadata::TitleCollection) && !titles.items.empty?
|
|
94
|
+
raw = titles.items.find do |t|
|
|
95
|
+
t.language == "en"
|
|
96
|
+
end || titles.items.first
|
|
97
|
+
return raw.value.to_s if raw&.value
|
|
98
|
+
end
|
|
99
|
+
nil
|
|
100
|
+
end
|
|
183
101
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
prefix.empty? ? amd : "#{prefix}: #{amd}"
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
def cover_title(bibdata, language)
|
|
209
|
-
titles = safe_attr(bibdata, :titles)
|
|
210
|
-
return nil unless titles.is_a?(Metanorma::Iso::Document::Metadata::TitleCollection)
|
|
211
|
-
|
|
212
|
-
title = bibdata.title_for(language)
|
|
213
|
-
return nil unless title
|
|
214
|
-
|
|
215
|
-
if title.is_a?(Metanorma::Iso::Document::Metadata::AbstractTitle) && title.value
|
|
216
|
-
title.value.to_s
|
|
217
|
-
else
|
|
218
|
-
title.to_s
|
|
219
|
-
end
|
|
220
|
-
end
|
|
221
|
-
|
|
222
|
-
def render_doc_title(doc)
|
|
223
|
-
bibdata = doc.bibdata
|
|
224
|
-
return nil unless bibdata
|
|
225
|
-
|
|
226
|
-
titles = safe_attr(bibdata, :titles)
|
|
227
|
-
return nil unless titles.is_a?(Metanorma::Iso::Document::Metadata::TitleCollection)
|
|
228
|
-
|
|
229
|
-
en_title = bibdata.title_for("en")
|
|
230
|
-
return nil unless en_title
|
|
231
|
-
|
|
232
|
-
render_liquid("_standard_doc_title.html.liquid", {
|
|
233
|
-
"title" => en_title.to_s,
|
|
234
|
-
})
|
|
235
|
-
end
|
|
236
|
-
|
|
237
|
-
def render_boilerplate_section(doc)
|
|
238
|
-
return nil unless doc.boilerplate
|
|
239
|
-
|
|
240
|
-
content = render(doc.boilerplate)
|
|
241
|
-
render_liquid("_prefatory_section.html.liquid", {
|
|
242
|
-
"content" => content,
|
|
243
|
-
})
|
|
244
|
-
end
|
|
245
|
-
|
|
246
|
-
def render_foreword(fw, level: 1, **_opts)
|
|
247
|
-
attrs = element_attrs(id: safe_attr(fw, :id))
|
|
248
|
-
title = safe_attr(fw, :fmt_title) || safe_attr(fw, :title)
|
|
249
|
-
parts = []
|
|
250
|
-
if title
|
|
251
|
-
fw_id = safe_attr(fw, :id)
|
|
252
|
-
title_content = render_mixed_inline(title)
|
|
253
|
-
register_toc_entry(id: fw_id, level: level,
|
|
254
|
-
text: extract_plain_text(title))
|
|
255
|
-
parts << render_liquid("_heading.html.liquid", {
|
|
256
|
-
"tag" => "h1",
|
|
257
|
-
"class_attr" => " class=\"foreword-title\"",
|
|
258
|
-
"content" => title_content,
|
|
259
|
-
})
|
|
260
|
-
end
|
|
261
|
-
parts << (render_ordered_content(fw) || "")
|
|
262
|
-
render_liquid("_element.html.liquid", "tag" => "div",
|
|
263
|
-
"extra_attrs" => attrs, "content" => parts.join)
|
|
264
|
-
end
|
|
265
|
-
|
|
266
|
-
def render_abstract(section, level: 1, **_opts)
|
|
267
|
-
attrs = element_attrs(id: safe_attr(section, :id))
|
|
268
|
-
title = safe_attr(section, :fmt_title) || safe_attr(section, :title)
|
|
269
|
-
parts = []
|
|
270
|
-
if title
|
|
271
|
-
sec_id = safe_attr(section, :id)
|
|
272
|
-
title_content = render_mixed_inline(title)
|
|
273
|
-
register_toc_entry(id: sec_id, level: level,
|
|
274
|
-
text: extract_plain_text(title))
|
|
275
|
-
parts << render_liquid("_heading.html.liquid", {
|
|
276
|
-
"tag" => "h1",
|
|
277
|
-
"class_attr" => " class=\"intro-title\"",
|
|
278
|
-
"content" => title_content,
|
|
279
|
-
})
|
|
280
|
-
end
|
|
281
|
-
parts << (render_ordered_content(section) || "")
|
|
282
|
-
render_liquid("_element.html.liquid", "tag" => "div",
|
|
283
|
-
"extra_attrs" => attrs, "content" => parts.join)
|
|
284
|
-
end
|
|
285
|
-
|
|
286
|
-
# --- Main sections rendering ---
|
|
287
|
-
|
|
288
|
-
def render_sections(sections, **_opts)
|
|
289
|
-
children = collect_ordered_children(sections)
|
|
290
|
-
parts = []
|
|
291
|
-
children.each do |node|
|
|
292
|
-
next if node.is_a?(String)
|
|
293
|
-
next if is_title_element?(node, sections)
|
|
294
|
-
|
|
295
|
-
parts << (render(node, level: 1) || "")
|
|
296
|
-
end
|
|
297
|
-
parts.join
|
|
298
|
-
end
|
|
299
|
-
|
|
300
|
-
# --- Clause rendering ---
|
|
301
|
-
|
|
302
|
-
def render_clause(clause, level: 1, **_opts)
|
|
303
|
-
attrs = element_attrs(id: safe_attr(clause, :id))
|
|
304
|
-
title = render_title(clause, level)
|
|
305
|
-
content = render_ordered_content(clause, level)
|
|
306
|
-
render_liquid("_element.html.liquid", "tag" => "div",
|
|
307
|
-
"extra_attrs" => attrs, "content" => "#{title}#{content}")
|
|
308
|
-
end
|
|
309
|
-
|
|
310
|
-
# --- Annex rendering ---
|
|
311
|
-
|
|
312
|
-
def render_annex(annex, level: 1, **_opts)
|
|
313
|
-
attrs = element_attrs(id: safe_attr(annex, :id), class: "section-sub")
|
|
314
|
-
title = render_annex_title(annex, level)
|
|
315
|
-
content = render_ordered_content(annex, level)
|
|
316
|
-
render_liquid("_element.html.liquid", "tag" => "div",
|
|
317
|
-
"extra_attrs" => attrs, "content" => "#{title}#{content}")
|
|
318
|
-
end
|
|
319
|
-
|
|
320
|
-
def render_annex_title(annex, level)
|
|
321
|
-
title_element = safe_attr(annex, :fmt_title) || safe_attr(annex, :title)
|
|
322
|
-
return nil unless title_element
|
|
323
|
-
|
|
324
|
-
annex_id = safe_attr(annex, :id)
|
|
325
|
-
title_content = render_mixed_inline(title_element)
|
|
326
|
-
register_toc_entry(id: annex_id, level: level,
|
|
327
|
-
text: extract_plain_text(title_element))
|
|
328
|
-
|
|
329
|
-
h = "h#{[[level, 6].min, 1].max}"
|
|
330
|
-
render_liquid("_heading.html.liquid", {
|
|
331
|
-
"tag" => h,
|
|
332
|
-
"class_attr" => " class=\"annex-title\"",
|
|
333
|
-
"content" => title_content,
|
|
334
|
-
})
|
|
335
|
-
end
|
|
336
|
-
|
|
337
|
-
# --- Terms section rendering ---
|
|
338
|
-
|
|
339
|
-
def render_terms_section(terms, level: 1, **_opts)
|
|
340
|
-
attrs = element_attrs(id: safe_attr(terms, :id))
|
|
341
|
-
title = render_title(terms, level)
|
|
342
|
-
content = render_ordered_content(terms, level)
|
|
343
|
-
render_liquid("_element.html.liquid", "tag" => "div",
|
|
344
|
-
"extra_attrs" => attrs, "content" => "#{title}#{content}")
|
|
345
|
-
end
|
|
346
|
-
|
|
347
|
-
# --- ISO Term rendering ---
|
|
348
|
-
|
|
349
|
-
def render_term_designation(designation, type)
|
|
350
|
-
css_class = type == "deprecated" ? "term-deprecated" : "term-name"
|
|
351
|
-
name = extract_designation_name(designation)
|
|
352
|
-
inner = if name
|
|
353
|
-
escape_html(name)
|
|
354
|
-
else
|
|
355
|
-
render_mixed_inline(designation) || ""
|
|
356
|
-
end
|
|
357
|
-
|
|
358
|
-
dfn_content = render_liquid("_element.html.liquid",
|
|
359
|
-
{ "tag" => "dfn", "extra_attrs" => "",
|
|
360
|
-
"content" => inner })
|
|
361
|
-
b_content = render_liquid("_element.html.liquid",
|
|
362
|
-
{ "tag" => "b", "extra_attrs" => "",
|
|
363
|
-
"content" => dfn_content })
|
|
364
|
-
|
|
365
|
-
if type == "deprecated"
|
|
366
|
-
b_content = render_liquid("_element.html.liquid",
|
|
367
|
-
{ "tag" => "del", "extra_attrs" => "",
|
|
368
|
-
"content" => b_content })
|
|
102
|
+
def extract_stage(bibdata)
|
|
103
|
+
stages = Array(safe_attr(safe_attr(bibdata, :status), :stage))
|
|
104
|
+
return nil if stages.empty?
|
|
105
|
+
|
|
106
|
+
en_stage = stages.find do |s|
|
|
107
|
+
lang = safe_attr(s, :language)
|
|
108
|
+
lang == "en" if lang
|
|
109
|
+
end
|
|
110
|
+
return Array(en_stage.value).join.strip if en_stage&.value
|
|
111
|
+
|
|
112
|
+
seen = Set.new
|
|
113
|
+
stage_text = stages.filter_map do |s|
|
|
114
|
+
val = Array(s.value).join.strip
|
|
115
|
+
down = val.downcase
|
|
116
|
+
next if seen.include?(down)
|
|
117
|
+
|
|
118
|
+
seen << down
|
|
119
|
+
val.empty? ? nil : val
|
|
120
|
+
end.compact.join(" ")
|
|
121
|
+
stage_text.empty? ? nil : stage_text
|
|
369
122
|
end
|
|
370
123
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
124
|
+
# ISO unpublished stages are 00-59 (front_id: /^[0-5]/); the first
|
|
125
|
+
# numeric stage element decides.
|
|
126
|
+
def cover_draft_stage?(bibdata)
|
|
127
|
+
stages = Array(safe_attr(safe_attr(bibdata, :status), :stage))
|
|
128
|
+
code = stages.filter_map { |s| Array(s.value).join.strip }
|
|
129
|
+
.find { |val| /\A\d/.match?(val) }
|
|
130
|
+
!code.nil? && /^[0-5]/.match?(code)
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def extract_doctype(bibdata)
|
|
134
|
+
return nil unless bibdata.is_a?(Metanorma::Iso::Document::Metadata::IsoBibliographicItem)
|
|
135
|
+
|
|
136
|
+
ext = bibdata.ext
|
|
137
|
+
return nil unless ext
|
|
138
|
+
|
|
139
|
+
doctypes = ext.doctype_element
|
|
140
|
+
return nil unless doctypes && !doctypes.empty?
|
|
141
|
+
|
|
142
|
+
en_dt = doctypes.find do |d|
|
|
143
|
+
lang = safe_attr(d, :language)
|
|
144
|
+
lang == "en" if lang
|
|
145
|
+
end
|
|
146
|
+
return en_dt.value.to_s if en_dt&.value
|
|
377
147
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
names = Array(expr.name)
|
|
382
|
-
text = names.map { |n| extract_name_text(n) }.join
|
|
383
|
-
return text unless text.strip.empty?
|
|
148
|
+
dt = doctypes.first
|
|
149
|
+
val = dt&.value.to_s
|
|
150
|
+
val.strip.empty? ? nil : val
|
|
384
151
|
end
|
|
385
152
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
153
|
+
# --- Top-level document rendering ---
|
|
154
|
+
|
|
155
|
+
def render_document(doc, **_opts)
|
|
156
|
+
parts = []
|
|
157
|
+
parts << (render_coverpage(doc) || "")
|
|
158
|
+
parts << (render_boilerplate_section(doc) || "")
|
|
159
|
+
|
|
160
|
+
parts << (render(doc.preface) || "") if doc.preface
|
|
161
|
+
parts << (render_doc_title(doc) || "")
|
|
162
|
+
|
|
163
|
+
all_items = collect_document_children(doc)
|
|
164
|
+
all_items.each do |node|
|
|
165
|
+
next if node.is_a?(String)
|
|
166
|
+
next if is_title_element?(node, doc.sections)
|
|
167
|
+
|
|
168
|
+
parts << (render(node) || "")
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
parts << (render_footnotes_section || "")
|
|
172
|
+
|
|
173
|
+
render_liquid("_main_content.html.liquid", {
|
|
174
|
+
"content" => parts.join,
|
|
175
|
+
})
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
# --- Cover page ---
|
|
179
|
+
|
|
180
|
+
def render_coverpage(doc)
|
|
181
|
+
bibdata = doc.bibdata
|
|
182
|
+
return "" unless bibdata
|
|
183
|
+
|
|
184
|
+
logos = publisher_logos_html(doc) || []
|
|
185
|
+
doctype = extract_doctype(bibdata)
|
|
186
|
+
title_text = cover_title(bibdata, "en")
|
|
187
|
+
title_fr = cover_title(bibdata, "fr")
|
|
188
|
+
# Amendments carry their own title line ("AMENDMENT 1: …") under
|
|
189
|
+
# each language's title on the isodoc titlepage.
|
|
190
|
+
title_text = [title_text, amendment_title_line(bibdata, "en")].compact.join(" ")
|
|
191
|
+
title_fr = [title_fr, amendment_title_line(bibdata, "fr")].compact.join(" ")
|
|
192
|
+
|
|
193
|
+
# isodoc titlepage parity: the "<abbr> stage" cover line is
|
|
194
|
+
# draft-only — a published document (stage 60 and above) carries
|
|
195
|
+
# no stage line on the cover.
|
|
196
|
+
stage_text = if cover_draft_stage?(bibdata)
|
|
197
|
+
stage_abbr = bibdata.cover_stage_abbreviation.to_s
|
|
198
|
+
stage_abbr.empty? ? extract_stage(bibdata) : "#{stage_abbr} stage"
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
# The bibdata model itself: its lutaml-model auto-Drop (with the
|
|
202
|
+
# model's `liquid` mappings) serves every cover identity fact.
|
|
203
|
+
render_liquid("_standard_cover.html.liquid", {
|
|
204
|
+
"publisher_logos" => logos,
|
|
205
|
+
"cover" => bibdata,
|
|
206
|
+
"doctype" => doctype,
|
|
207
|
+
"title" => title_text,
|
|
208
|
+
"title_fr" => title_fr,
|
|
209
|
+
"stage" => stage_text,
|
|
210
|
+
})
|
|
390
211
|
end
|
|
391
212
|
|
|
392
|
-
|
|
393
|
-
|
|
213
|
+
def amendment_title_line(bibdata, language)
|
|
214
|
+
localized = bibdata.title_for(language)
|
|
215
|
+
return nil unless localized.is_a?(Metanorma::Iso::Document::Metadata::IsoLocalizedTitle)
|
|
394
216
|
|
|
395
|
-
|
|
396
|
-
|
|
217
|
+
amd = localized.title_amd&.value.to_s
|
|
218
|
+
return nil if amd.strip.empty?
|
|
397
219
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
joined = texts.is_a?(Array) ? texts.join : texts.to_s
|
|
401
|
-
return joined unless joined.strip.empty?
|
|
220
|
+
prefix = localized.title_amendment_prefix&.value.to_s
|
|
221
|
+
prefix.empty? ? amd : "#{prefix}: #{amd}"
|
|
402
222
|
end
|
|
403
223
|
|
|
404
|
-
|
|
405
|
-
|
|
224
|
+
def cover_title(bibdata, language)
|
|
225
|
+
titles = safe_attr(bibdata, :titles)
|
|
226
|
+
return nil unless titles.is_a?(Metanorma::Iso::Document::Metadata::TitleCollection)
|
|
227
|
+
|
|
228
|
+
title = bibdata.title_for(language)
|
|
229
|
+
return nil unless title
|
|
230
|
+
|
|
231
|
+
if title.is_a?(Metanorma::Iso::Document::Metadata::AbstractTitle) && title.value
|
|
232
|
+
title.value.to_s
|
|
233
|
+
else
|
|
234
|
+
title.to_s
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
def render_doc_title(doc)
|
|
239
|
+
bibdata = doc.bibdata
|
|
240
|
+
return nil unless bibdata
|
|
241
|
+
|
|
242
|
+
titles = safe_attr(bibdata, :titles)
|
|
243
|
+
return nil unless titles.is_a?(Metanorma::Iso::Document::Metadata::TitleCollection)
|
|
244
|
+
|
|
245
|
+
en_title = bibdata.title_for("en")
|
|
246
|
+
return nil unless en_title
|
|
406
247
|
|
|
407
|
-
|
|
408
|
-
|
|
248
|
+
render_liquid("_standard_doc_title.html.liquid", {
|
|
249
|
+
"title" => en_title.to_s,
|
|
250
|
+
})
|
|
251
|
+
end
|
|
409
252
|
|
|
410
|
-
|
|
411
|
-
|
|
253
|
+
def render_boilerplate_section(doc)
|
|
254
|
+
return nil unless doc.boilerplate
|
|
412
255
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
vd_p = safe_attr(vd, :p) || safe_attr(vd, :paragraph)
|
|
418
|
-
vd_p&.each { |para| parts << (render_paragraph(para) || "") }
|
|
419
|
-
vd.ul&.each { |ul| parts << (render_unordered_list(ul) || "") }
|
|
420
|
-
vd.ol&.each { |ol| parts << (render_ordered_list(ol) || "") }
|
|
421
|
-
rendered = true
|
|
256
|
+
content = render(doc.boilerplate)
|
|
257
|
+
render_liquid("_prefatory_section.html.liquid", {
|
|
258
|
+
"content" => content,
|
|
259
|
+
})
|
|
422
260
|
end
|
|
423
261
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
262
|
+
def render_foreword(fw, level: 1, **_opts)
|
|
263
|
+
attrs = element_attrs(id: safe_attr(fw, :id))
|
|
264
|
+
title = safe_attr(fw, :fmt_title) || safe_attr(fw, :title)
|
|
265
|
+
parts = []
|
|
266
|
+
if title
|
|
267
|
+
fw_id = safe_attr(fw, :id)
|
|
268
|
+
title_content = render_mixed_inline(title)
|
|
269
|
+
register_toc_entry(id: fw_id, level: level,
|
|
270
|
+
text: extract_plain_text(title))
|
|
271
|
+
parts << render_liquid("_heading.html.liquid", {
|
|
272
|
+
"tag" => "h1",
|
|
273
|
+
"class_attr" => " class=\"foreword-title\"",
|
|
274
|
+
"content" => title_content,
|
|
275
|
+
})
|
|
276
|
+
end
|
|
277
|
+
parts << (render_ordered_content(fw) || "")
|
|
278
|
+
render_liquid("_element.html.liquid", "tag" => "div",
|
|
279
|
+
"extra_attrs" => attrs, "content" => parts.join)
|
|
428
280
|
end
|
|
429
281
|
|
|
430
|
-
|
|
431
|
-
|
|
282
|
+
def render_abstract(section, level: 1, **_opts)
|
|
283
|
+
attrs = element_attrs(id: safe_attr(section, :id))
|
|
284
|
+
title = safe_attr(section, :fmt_title) || safe_attr(section, :title)
|
|
285
|
+
parts = []
|
|
286
|
+
if title
|
|
287
|
+
sec_id = safe_attr(section, :id)
|
|
288
|
+
title_content = render_mixed_inline(title)
|
|
289
|
+
register_toc_entry(id: sec_id, level: level,
|
|
290
|
+
text: extract_plain_text(title))
|
|
291
|
+
parts << render_liquid("_heading.html.liquid", {
|
|
292
|
+
"tag" => "h1",
|
|
293
|
+
"class_attr" => " class=\"intro-title\"",
|
|
294
|
+
"content" => title_content,
|
|
295
|
+
})
|
|
296
|
+
end
|
|
297
|
+
parts << (render_ordered_content(section) || "")
|
|
298
|
+
render_liquid("_element.html.liquid", "tag" => "div",
|
|
299
|
+
"extra_attrs" => attrs, "content" => parts.join)
|
|
432
300
|
end
|
|
433
|
-
parts.join
|
|
434
|
-
end
|
|
435
301
|
|
|
436
|
-
|
|
302
|
+
# --- Main sections rendering ---
|
|
437
303
|
|
|
438
|
-
|
|
439
|
-
|
|
304
|
+
def render_sections(sections, **_opts)
|
|
305
|
+
children = collect_ordered_children(sections)
|
|
306
|
+
parts = []
|
|
307
|
+
children.each do |node|
|
|
308
|
+
next if node.is_a?(String)
|
|
309
|
+
next if is_title_element?(node, sections)
|
|
310
|
+
|
|
311
|
+
parts << (render(node, level: 1) || "")
|
|
312
|
+
end
|
|
313
|
+
parts.join
|
|
314
|
+
end
|
|
440
315
|
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
316
|
+
# --- Clause rendering ---
|
|
317
|
+
|
|
318
|
+
def render_clause(clause, level: 1, **_opts)
|
|
319
|
+
attrs = element_attrs(id: safe_attr(clause, :id))
|
|
320
|
+
title = render_title(clause, level)
|
|
321
|
+
content = render_ordered_content(clause, level)
|
|
322
|
+
render_liquid("_element.html.liquid", "tag" => "div",
|
|
323
|
+
"extra_attrs" => attrs, "content" => "#{title}#{content}")
|
|
324
|
+
end
|
|
325
|
+
|
|
326
|
+
# --- Annex rendering ---
|
|
327
|
+
|
|
328
|
+
def render_annex(annex, level: 1, **_opts)
|
|
329
|
+
attrs = element_attrs(id: safe_attr(annex, :id), class: "section-sub")
|
|
330
|
+
title = render_annex_title(annex, level)
|
|
331
|
+
content = render_ordered_content(annex, level)
|
|
332
|
+
render_liquid("_element.html.liquid", "tag" => "div",
|
|
333
|
+
"extra_attrs" => attrs, "content" => "#{title}#{content}")
|
|
334
|
+
end
|
|
447
335
|
|
|
448
|
-
|
|
449
|
-
|
|
336
|
+
def render_annex_title(annex, level)
|
|
337
|
+
title_element = safe_attr(annex, :fmt_title) || safe_attr(annex, :title)
|
|
338
|
+
return nil unless title_element
|
|
339
|
+
|
|
340
|
+
annex_id = safe_attr(annex, :id)
|
|
341
|
+
title_content = render_mixed_inline(title_element)
|
|
342
|
+
register_toc_entry(id: annex_id, level: level,
|
|
343
|
+
text: extract_plain_text(title_element))
|
|
344
|
+
|
|
345
|
+
h = "h#{[[level, 6].min, 1].max}"
|
|
346
|
+
render_liquid("_heading.html.liquid", {
|
|
347
|
+
"tag" => h,
|
|
348
|
+
"class_attr" => " class=\"annex-title\"",
|
|
349
|
+
"content" => title_content,
|
|
350
|
+
})
|
|
351
|
+
end
|
|
450
352
|
|
|
451
|
-
|
|
452
|
-
return nil unless items
|
|
353
|
+
# --- Terms section rendering ---
|
|
453
354
|
|
|
454
|
-
|
|
455
|
-
|
|
355
|
+
def render_terms_section(terms, level: 1, **_opts)
|
|
356
|
+
attrs = element_attrs(id: safe_attr(terms, :id))
|
|
357
|
+
title = render_title(terms, level)
|
|
358
|
+
content = render_ordered_content(terms, level)
|
|
359
|
+
render_liquid("_element.html.liquid", "tag" => "div",
|
|
360
|
+
"extra_attrs" => attrs, "content" => "#{title}#{content}")
|
|
361
|
+
end
|
|
456
362
|
|
|
457
|
-
|
|
458
|
-
return nil unless item
|
|
459
|
-
return nil unless item.is_a?(Lutaml::Model::Serializable)
|
|
363
|
+
# --- ISO Term rendering ---
|
|
460
364
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
365
|
+
def render_term_designation(designation, type)
|
|
366
|
+
css_class = type == "deprecated" ? "term-deprecated" : "term-name"
|
|
367
|
+
name = extract_designation_name(designation)
|
|
368
|
+
inner = if name
|
|
369
|
+
escape_html(name)
|
|
464
370
|
else
|
|
465
|
-
|
|
371
|
+
render_mixed_inline(designation) || ""
|
|
466
372
|
end
|
|
467
373
|
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
# (not through render_title) so it stays out of the TOC.
|
|
480
|
-
title = safe_attr(section, :fmt_title) || safe_attr(section, :title)
|
|
481
|
-
if title && !Array(title).empty?
|
|
482
|
-
parts << render_liquid("_heading.html.liquid", tag: "h1",
|
|
483
|
-
class_attr: "",
|
|
484
|
-
content: render_mixed_inline(title))
|
|
485
|
-
end
|
|
486
|
-
section.each_mixed_content do |child|
|
|
487
|
-
next if child.is_a?(String)
|
|
488
|
-
next if is_title_element?(child, section)
|
|
489
|
-
next if child.equal?(fmt_title)
|
|
490
|
-
|
|
491
|
-
parts << (render(child) || "")
|
|
492
|
-
end
|
|
493
|
-
parts.join
|
|
494
|
-
end
|
|
495
|
-
|
|
496
|
-
# --- Helpers ---
|
|
497
|
-
|
|
498
|
-
def render_title(section, level)
|
|
499
|
-
title_element = safe_attr(section,
|
|
500
|
-
:fmt_title) || safe_attr(section, :title)
|
|
501
|
-
return nil unless title_element
|
|
502
|
-
|
|
503
|
-
section_id = safe_attr(section, :id)
|
|
504
|
-
title_content = render_mixed_inline(title_element)
|
|
505
|
-
register_toc_entry(id: section_id, level: level,
|
|
506
|
-
text: extract_plain_text(title_element))
|
|
507
|
-
|
|
508
|
-
h = "h#{[[level, 6].min, 1].max}"
|
|
509
|
-
render_liquid("_heading.html.liquid", tag: h, class_attr: "",
|
|
510
|
-
content: title_content)
|
|
511
|
-
end
|
|
512
|
-
|
|
513
|
-
def collect_document_children(doc)
|
|
514
|
-
items = []
|
|
515
|
-
|
|
516
|
-
if doc.sections
|
|
517
|
-
section_children = collect_ordered_children(doc.sections)
|
|
518
|
-
title_rendered = !render_doc_title(doc).to_s.empty?
|
|
519
|
-
section_children.reject! do |node|
|
|
520
|
-
next false unless node.is_a?(Metanorma::Document::Components::Paragraphs::ParagraphBlock)
|
|
521
|
-
|
|
522
|
-
title_rendered || !title_paragraph?(node)
|
|
374
|
+
dfn_content = render_liquid("_element.html.liquid",
|
|
375
|
+
{ "tag" => "dfn", "extra_attrs" => "",
|
|
376
|
+
"content" => inner })
|
|
377
|
+
b_content = render_liquid("_element.html.liquid",
|
|
378
|
+
{ "tag" => "b", "extra_attrs" => "",
|
|
379
|
+
"content" => dfn_content })
|
|
380
|
+
|
|
381
|
+
if type == "deprecated"
|
|
382
|
+
b_content = render_liquid("_element.html.liquid",
|
|
383
|
+
{ "tag" => "del", "extra_attrs" => "",
|
|
384
|
+
"content" => b_content })
|
|
523
385
|
end
|
|
524
|
-
|
|
386
|
+
|
|
387
|
+
render_liquid("_element.html.liquid", {
|
|
388
|
+
"tag" => "p",
|
|
389
|
+
"extra_attrs" => " class=\"#{css_class}\" style=\"text-align:left;\"",
|
|
390
|
+
"content" => b_content,
|
|
391
|
+
})
|
|
525
392
|
end
|
|
526
393
|
|
|
527
|
-
|
|
528
|
-
|
|
394
|
+
def extract_designation_name(designation)
|
|
395
|
+
expr = designation.expression
|
|
396
|
+
if expr.is_a?(Metanorma::Iso::Document::Terms::TermExpression) && expr.name
|
|
397
|
+
names = Array(expr.name)
|
|
398
|
+
text = names.map { |n| extract_name_text(n) }.join
|
|
399
|
+
return text unless text.strip.empty?
|
|
400
|
+
end
|
|
529
401
|
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
402
|
+
texts = safe_attr(designation, :text)
|
|
403
|
+
if texts
|
|
404
|
+
joined = texts.is_a?(Array) ? texts.join : texts.to_s
|
|
405
|
+
return joined unless joined.strip.empty?
|
|
406
|
+
end
|
|
533
407
|
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
end
|
|
408
|
+
nil
|
|
409
|
+
end
|
|
537
410
|
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
logo_map = publisher_logo_map
|
|
541
|
-
return [] if publishers.empty? && logo_map.empty?
|
|
411
|
+
def extract_name_text(name_el)
|
|
412
|
+
return name_el.to_s unless name_el.is_a?(Lutaml::Model::Serializable)
|
|
542
413
|
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
414
|
+
texts = safe_attr(name_el, :text)
|
|
415
|
+
if texts
|
|
416
|
+
joined = texts.is_a?(Array) ? texts.join : texts.to_s
|
|
417
|
+
return joined unless joined.strip.empty?
|
|
418
|
+
end
|
|
548
419
|
|
|
549
|
-
|
|
550
|
-
|
|
420
|
+
""
|
|
421
|
+
end
|
|
551
422
|
|
|
552
|
-
|
|
423
|
+
def render_term_definition(definition)
|
|
424
|
+
return nil unless definition
|
|
425
|
+
|
|
426
|
+
parts = []
|
|
427
|
+
rendered = false
|
|
428
|
+
|
|
429
|
+
vd = safe_attr(definition,
|
|
430
|
+
:verbal_definition) || safe_attr(definition,
|
|
431
|
+
:verbalexpression)
|
|
432
|
+
if vd
|
|
433
|
+
vd_p = safe_attr(vd, :p) || safe_attr(vd, :paragraph)
|
|
434
|
+
vd_p&.each { |para| parts << (render_paragraph(para) || "") }
|
|
435
|
+
vd.ul&.each { |ul| parts << (render_unordered_list(ul) || "") }
|
|
436
|
+
vd.ol&.each { |ol| parts << (render_ordered_list(ol) || "") }
|
|
437
|
+
rendered = true
|
|
438
|
+
end
|
|
553
439
|
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
440
|
+
p_children = safe_attr(definition, :p)
|
|
441
|
+
if !rendered && p_children && !p_children.empty?
|
|
442
|
+
p_children.each { |para| parts << (render_paragraph(para) || "") }
|
|
443
|
+
rendered = true
|
|
444
|
+
end
|
|
445
|
+
|
|
446
|
+
unless rendered
|
|
447
|
+
parts << (render_ordered_content(definition) || "")
|
|
448
|
+
end
|
|
449
|
+
parts.join
|
|
450
|
+
end
|
|
451
|
+
|
|
452
|
+
# --- Boilerplate rendering ---
|
|
453
|
+
|
|
454
|
+
def render_boilerplate(boilerplate, **_opts)
|
|
455
|
+
return nil unless boilerplate
|
|
456
|
+
|
|
457
|
+
parts = []
|
|
458
|
+
parts << (render_boilerplate_items(boilerplate.copyright_statement) || "")
|
|
459
|
+
parts << (render_boilerplate_items(boilerplate.license_statement) || "")
|
|
460
|
+
parts << (render_boilerplate_items(boilerplate.legal_statement) || "")
|
|
461
|
+
parts << (render_boilerplate_items(boilerplate.feedback_statement) || "")
|
|
462
|
+
parts << (render_boilerplate_items(boilerplate.clause) || "")
|
|
463
|
+
|
|
464
|
+
render_liquid("_boilerplate.html.liquid", content: parts.join)
|
|
465
|
+
end
|
|
466
|
+
|
|
467
|
+
def render_boilerplate_items(items)
|
|
468
|
+
return nil unless items
|
|
469
|
+
|
|
470
|
+
Array(items).filter_map { |item| render_boilerplate_clause(item) }.join
|
|
471
|
+
end
|
|
472
|
+
|
|
473
|
+
def render_boilerplate_clause(item)
|
|
474
|
+
return nil unless item
|
|
475
|
+
return nil unless item.is_a?(Lutaml::Model::Serializable)
|
|
476
|
+
|
|
477
|
+
inner = safe_attr(item, :subsection)
|
|
478
|
+
targets = if inner && !Array(inner).empty?
|
|
479
|
+
Array(inner)
|
|
480
|
+
else
|
|
481
|
+
[item]
|
|
482
|
+
end
|
|
483
|
+
|
|
484
|
+
targets.filter_map do |section|
|
|
485
|
+
render_boilerplate_clause_content(section)
|
|
486
|
+
end.join
|
|
487
|
+
end
|
|
488
|
+
|
|
489
|
+
def render_boilerplate_clause_content(section)
|
|
490
|
+
fmt_title = safe_attr(section, :fmt_title)
|
|
491
|
+
parts = []
|
|
492
|
+
# The copyright statement's title ("COPYRIGHT PROTECTED DOCUMENT")
|
|
493
|
+
# is visible text in the native render — headings are the one
|
|
494
|
+
# boilerplate child that must not be skipped. Rendered directly
|
|
495
|
+
# (not through render_title) so it stays out of the TOC.
|
|
496
|
+
title = safe_attr(section, :fmt_title) || safe_attr(section, :title)
|
|
497
|
+
if title && !Array(title).empty?
|
|
498
|
+
parts << render_liquid("_heading.html.liquid", tag: "h1",
|
|
499
|
+
class_attr: "",
|
|
500
|
+
content: render_mixed_inline(title))
|
|
501
|
+
end
|
|
502
|
+
section.each_mixed_content do |child|
|
|
503
|
+
next if child.is_a?(String)
|
|
504
|
+
next if is_title_element?(child, section)
|
|
505
|
+
next if child.equal?(fmt_title)
|
|
506
|
+
|
|
507
|
+
parts << (render(child) || "")
|
|
508
|
+
end
|
|
509
|
+
parts.join
|
|
510
|
+
end
|
|
511
|
+
|
|
512
|
+
# --- Helpers ---
|
|
513
|
+
|
|
514
|
+
def render_title(section, level)
|
|
515
|
+
title_element = safe_attr(section,
|
|
516
|
+
:fmt_title) || safe_attr(section, :title)
|
|
517
|
+
return nil unless title_element
|
|
518
|
+
|
|
519
|
+
section_id = safe_attr(section, :id)
|
|
520
|
+
title_content = render_mixed_inline(title_element)
|
|
521
|
+
register_toc_entry(id: section_id, level: level,
|
|
522
|
+
text: extract_plain_text(title_element))
|
|
523
|
+
|
|
524
|
+
h = "h#{[[level, 6].min, 1].max}"
|
|
525
|
+
render_liquid("_heading.html.liquid", tag: h, class_attr: "",
|
|
526
|
+
content: title_content)
|
|
527
|
+
end
|
|
528
|
+
|
|
529
|
+
def collect_document_children(doc)
|
|
530
|
+
items = []
|
|
531
|
+
|
|
532
|
+
if doc.sections
|
|
533
|
+
section_children = collect_ordered_children(doc.sections)
|
|
534
|
+
title_rendered = !render_doc_title(doc).to_s.empty?
|
|
535
|
+
section_children.reject! do |node|
|
|
536
|
+
next false unless node.is_a?(Metanorma::Document::Components::Paragraphs::ParagraphBlock)
|
|
537
|
+
|
|
538
|
+
title_rendered || !title_paragraph?(node)
|
|
560
539
|
end
|
|
540
|
+
items.concat(section_children)
|
|
561
541
|
end
|
|
562
542
|
|
|
563
|
-
|
|
543
|
+
doc.bibliography&.references&.each { |r| items << r }
|
|
544
|
+
doc.annex&.each { |a| items << a }
|
|
545
|
+
|
|
546
|
+
items.compact!
|
|
547
|
+
sort_by_displayorder(items)
|
|
548
|
+
end
|
|
549
|
+
|
|
550
|
+
def title_paragraph?(node)
|
|
551
|
+
safe_attr(node, :class_attr).to_s.start_with?("zzSTDTitle")
|
|
552
|
+
end
|
|
553
|
+
|
|
554
|
+
def publisher_logos_html(_doc)
|
|
555
|
+
# Cover marks resolve through the shared records engine: the slot
|
|
556
|
+
# draws exactly the (use × style) combos the theme's logo_slots
|
|
557
|
+
# declare, every style emitted as a tagged span for CSS to select.
|
|
558
|
+
# Misses skip the slot with a typed diagnostic.
|
|
559
|
+
publisher_logo_spans(slot: "cover", height: 48,
|
|
560
|
+
span_class: "cover-logo")
|
|
564
561
|
end
|
|
565
|
-
end
|
|
566
|
-
end
|
|
562
|
+
end
|
|
563
|
+
end
|
|
567
564
|
end
|
|
568
565
|
end
|