Skip to content

Commit

Permalink
modspec update for Presentation XML caption refactoring: metanorma/is…
Browse files Browse the repository at this point in the history
  • Loading branch information
opoudjis committed Nov 19, 2024
1 parent 3f72f8f commit 089296a
Show file tree
Hide file tree
Showing 11 changed files with 2,776 additions and 1,223 deletions.
33 changes: 23 additions & 10 deletions lib/isodoc/iso/presentation_xml_convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,14 @@ def figure1(node)
prefix_name(node, { caption: conn }, l10n(s&.strip), "name")
end

=begin
def example1(node)
n = @xrefs.get[node["id"]]
lbl = if n.nil? || blank?(n[:label]) then @i18n.example
else l10n("#{@i18n.example} #{n[:label]}")
end
prefix_name(node, block_delim, lbl, "name")
end
=end
# def example1(node)
# n = @xrefs.get[node["id"]]
# lbl = if n.nil? || blank?(n[:label]) then @i18n.example
# else l10n("#{@i18n.example} #{n[:label]}")
# end
# prefix_name(node, block_delim, lbl, "name")
# end

def example_span_label(_node, div, name)
name.nil? and return
div.span class: "example_label" do |_p|
Expand All @@ -95,6 +94,7 @@ def clause1(node)
end
end

=begin
def clause(docxml)
docxml.xpath(ns("//clause[not(ancestor::annex)] | " \
"//terms | //definitions | //references | " \
Expand All @@ -104,6 +104,7 @@ def clause(docxml)
clause1(f)
end
end
=end

def admonition1(elem)
super
Expand Down Expand Up @@ -158,10 +159,22 @@ def formula_where_one(dlist)
end

def table1(elem)
table1_key(elem)
if elem["class"] == "modspec"
n = elem.at(ns(".//fmt-name")).remove
n.name = "name"
elem.add_first_child(n)
elem.at(ns("./thead"))&.remove
super
elem.at(ns("./name")).remove
else super
end
end

def table1_key(elem)
elem.xpath(ns(".//dl[@key = 'true'][not(./name)]")).each do |dl|
dl.add_first_child "<name>#{@i18n.key}</name>"
end
super
end

def toc_title(docxml)
Expand Down
7 changes: 6 additions & 1 deletion lib/isodoc/iso/xref.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,12 @@ def xref_to_modspec(id, table_label)
(@anchors[id] && !@anchors[id][:has_modspec]) or return
@anchors[id][:has_modspec] = true
x = @anchors_previous[id][:xref_bare] || @anchors_previous[id][:xref]
@anchors[id][:xref] = l10n("#{table_label}, #{x}")
#@anchors[id][:xref] = l10n("#{table_label}<span class='fmt-comma'>,</span> #{x}")

@anchors[id][:xref] = l10n(@klass.connectives_spans(@i18n.nested_xref
.sub("%1", table_label).sub("%2", x)))


@anchors[id][:modspec] = @anchors_previous[id][:modspec]
@anchors[id][:subtype] = "modspec" # prevents citetbl style from beign applied
true
Expand Down
16 changes: 10 additions & 6 deletions lib/metanorma/requirements/modspec.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
module Metanorma
class Requirements
class Modspec
# Don't want to inherit from Metanorma::Requirements::Modspec
class Iso < ::Metanorma::Requirements::Modspec
=begin
def recommendation_label(elem, type, xrefs)
lbl = super
title = elem.at(ns("./title"))
return lbl unless title &&
elem.ancestors("requirement, recommendation, permission").empty?
lbl += ": " if lbl
lbl += title.children.to_xml
lbl += "<span class='fmt-caption-delim'>: </span>" if lbl
lbl += "<semx element='title' source='#{elem['id']}'>#{title.children.to_xml}</semx>"
require "debug"; binding.b
l10n(lbl)
end
# ISO labels modspec reqt as table, with reqt label as title
def recommendation_header(reqt, out)
n = reqt.at(ns("./name")) and out << n
n = reqt.at(ns("./fmt-name")) and out << n
out
end
=end

def requirement_table_nested_cleanup(node, table)
table["type"] == "recommendclass" or return table
Expand All @@ -40,7 +42,7 @@ def requirement_table_cleanup_nested_replacement(node, table)
def nested_tables_names(table)
table.xpath(ns("./tbody/tr/td/table"))
.each_with_object([]) do |t, m|
m << t.at(ns("./name")).children.to_xml
m << t.at(ns(".//fmt-name")).children.to_xml
end
end

Expand All @@ -49,8 +51,10 @@ def postprocess_anchor_struct(block, anchor)
anchor[:modspec] = anchor[:xref_bare]
if l = block.at(ns("./title"))
anchor[:modspec] =
l10n("#{anchor[:modspec]}: #{l.children.to_xml.strip}")
l10n("#{anchor[:modspec]}<span class='fmt-caption-delim'>: </span><semx element='title' source='#{block['id']}'>#{l.children.to_xml.strip}</semx>")
end
/<xref/.match?(anchor[:modspec]) or
anchor[:modspec] = "<xref target='#{block['id']}'>#{anchor[:modspec]}</xref>"
anchor
end
end
Expand Down
14 changes: 8 additions & 6 deletions spec/isodoc/inline_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,8 @@
expect(Xml::C14n.format(strip_guid(pres_output)))
.to be_equivalent_to Xml::C14n.format(presxml)
expect(Xml::C14n.format(IsoDoc::Iso::HtmlConvert.new({})
.convert("test", pres_output, true))).to be_equivalent_to Xml::C14n.format(output)
.convert("test", pres_output, true)))
.to be_equivalent_to Xml::C14n.format(output)
end

it "processes concept markup by context" do
Expand Down Expand Up @@ -1254,14 +1255,15 @@
output = <<~OUTPUT
<itu-standard xmlns="https://www.calconnect.org/standards/itu" type="presentation">
<p id="_">
<eref type="inline" bibitemid="ref1" citeas="ITU" droploc=""><localityStack connective="from"><locality type="clause"><referenceFrom>3</referenceFrom></locality></localityStack><localityStack connective="to"><locality type="clause"><referenceFrom>5</referenceFrom></locality></localityStack><span class="stdpublisher">ITU</span>, <span class="citesec">Clauses <span class="citesec">3</span> to <span class="citesec">5</span></span></eref>
<eref type="inline" bibitemid="ref1" citeas="ITU" droploc=""><localityStack connective="from"><locality type="clause"><referenceFrom>3.1</referenceFrom></locality></localityStack><localityStack connective="to"><locality type="clause"><referenceFrom>5.1</referenceFrom></locality></localityStack><span class="stdpublisher">ITU</span>, <span class="citesec">3.1</span> to <span class="citesec">5.1</span></eref>
<eref type="inline" bibitemid="ref1" citeas="ITU"><localityStack connective="from"><locality type="clause"><referenceFrom>3.1</referenceFrom></locality></localityStack><localityStack connective="to"><locality type="clause"><referenceFrom>5</referenceFrom></locality></localityStack><span class="stdpublisher">ITU</span>, <span class="citesec">3.1</span> to <span class="citesec">Clause 5</span></eref>
<eref type="inline" bibitemid="ref1" citeas="ITU"><localityStack connective="from"><locality type="clause"><referenceFrom>3.1</referenceFrom></locality></localityStack><localityStack connective="to"><locality type="table"><referenceFrom>5</referenceFrom></locality></localityStack><span class="stdpublisher">ITU</span>, <span class="citesec">3.1</span> to <span class="citetbl">Table 5</span></eref>
<eref type="inline" bibitemid="ref1" citeas="ITU" droploc=""><localityStack connective="from"><locality type="clause"><referenceFrom>3</referenceFrom></locality></localityStack><localityStack connective="to"><locality type="clause"><referenceFrom>5</referenceFrom></locality></localityStack><span class="stdpublisher">ITU</span>, <span class="citesec">Clauses <span class="citesec">3</span> <span class="fmt-conn">to</span> <span class="citesec">5</span></span></eref>
<eref type="inline" bibitemid="ref1" citeas="ITU" droploc=""><localityStack connective="from"><locality type="clause"><referenceFrom>3.1</referenceFrom></locality></localityStack><localityStack connective="to"><locality type="clause"><referenceFrom>5.1</referenceFrom></locality></localityStack><span class="stdpublisher">ITU</span>, <span class="citesec">3.1</span> <span class="fmt-conn">to</span> <span class="citesec">5.1</span></eref>
<eref type="inline" bibitemid="ref1" citeas="ITU"><localityStack connective="from"><locality type="clause"><referenceFrom>3.1</referenceFrom></locality></localityStack><localityStack connective="to"><locality type="clause"><referenceFrom>5</referenceFrom></locality></localityStack><span class="stdpublisher">ITU</span>, <span class="citesec">3.1</span> <span class="fmt-conn">to</span> <span class="citesec">Clause 5</span></eref>
<eref type="inline" bibitemid="ref1" citeas="ITU"><localityStack connective="from"><locality type="clause"><referenceFrom>3.1</referenceFrom></locality></localityStack><localityStack connective="to"><locality type="table"><referenceFrom>5</referenceFrom></locality></localityStack><span class="stdpublisher">ITU</span>, <span class="citesec">3.1</span> <span class="fmt-conn">to</span> <span class="citetbl">Table 5</span></eref>
</p>
</itu-standard>
OUTPUT
expect(Xml::C14n.format(IsoDoc::Iso::PresentationXMLConvert.new(presxml_options)
.convert("test", input, true))).to be_equivalent_to Xml::C14n.format(output)
.convert("test", input, true)))
.to be_equivalent_to Xml::C14n.format(output)
end
end
6 changes: 3 additions & 3 deletions spec/isodoc/iso_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
.convert("test", <<~INPUT, true)
<iso-standard xmlns="http://riboseinc.com/isoxml">
<preface>
<foreword>
<foreword id="A"><title>Foreword</title>
<p id="_f06fd0d1-a203-4f3d-a515-0bdba0f8d83f">
<eref bibitemid="IEV">IEV</eref>
<eref bibitemid="ISO20483">ISO 20483</eref>
Expand All @@ -125,7 +125,7 @@
</preface>
<bibliography>
<references id="_normative_references" normative="true" obligation="informative">
<fmt-title>Normative References</fmt-title>
<title>Normative References</title>
<bibitem id="IEV" type="standard">
<title format="text/plain" language="en" script="Latn">Electropedia: The World's Online Electrotechnical Vocabulary</title>
<uri type="src">http://www.electropedia.org</uri>
Expand Down Expand Up @@ -181,7 +181,7 @@
.to be_equivalent_to Xml::C14n.format(strip_guid(<<~"OUTPUT"))
#{HTML_HDR}
<br/>
<div>
<div id="A">
<h1 class="ForewordTitle">Foreword</h1>
<p id="_f06fd0d1-a203-4f3d-a515-0bdba0f8d83f">
<a href="http://www.electropedia.org">IEV</a>
Expand Down
14 changes: 12 additions & 2 deletions spec/isodoc/metadata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,12 @@
<span class="boldtitle">Specifications and test methods</span>
</p>
<clause displayorder='3'>
<title depth='1'>Clause 1</title>
<title id="_">Clause 1</title>
<fmt-title depth="1">
<span class="fmt-caption-label">
<semx element="title" source="_">Clause 1</semx>
</span>
</fmt-title>
</clause>
</sections>
OUTPUT
Expand Down Expand Up @@ -701,7 +706,12 @@
<span class="boldtitle">Specifications and test methods</span>
</p>
<clause displayorder='3'>
<title depth='1'>Clause 1</title>
<title id="_">Clause 1</title>
<fmt-title depth="1">
<span class="fmt-caption-label">
<semx element="title" source="_">Clause 1</semx>
</span>
</fmt-title>
</clause>
</sections>
OUTPUT
Expand Down
2 changes: 1 addition & 1 deletion spec/isodoc/postproc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
<tab/>
Terms and Definitions</fmt-title>
<term id="paddy1">
<name>1.1</name>
<fmt-name>1.1</fmt-name>
<preferred>paddy</preferred>
<definition>
<p id="_eb29b35e-123e-4d1c-b50b-2714d41e747f">rice retaining its husk after threshing</p>
Expand Down
2 changes: 1 addition & 1 deletion spec/isodoc/section_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@
xml.at("//xmlns:localized-strings")&.remove
xml.at("//xmlns:boilerplate")&.remove
xml.at("//xmlns:metanorma-extension")&.remove
expect(strip_guid(xml.to_xml))
expect(Xml::C14n.formatstrip_guid(xml.to_xml))
.to be_equivalent_to Xml::C14n.format(presxml)
expect(Xml::C14n.format(IsoDoc::Iso::HtmlConvert.new({})
.convert("test", pres_output, true)))
Expand Down
Loading

0 comments on commit 089296a

Please sign in to comment.