Skip to content

Commit

Permalink
use displayorder attribute to order clauses in HTML/DOC: metanorma/me…
Browse files Browse the repository at this point in the history
  • Loading branch information
opoudjis committed Jul 28, 2023
1 parent efabcb3 commit 354997a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
1 change: 1 addition & 0 deletions Gemfile.devel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gem "isodoc", git: "https://github.com/metanorma/isodoc", branch: "features/displayorder"
36 changes: 16 additions & 20 deletions spec/isodoc/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
RSpec.describe Metanorma::CC do
it "processes default metadata" do
csdc = IsoDoc::CC::HtmlConvert.new({})
docxml, = csdc.convert_init(<<~"INPUT", "test", true)
docxml, = csdc.convert_init(<<~INPUT, "test", true)
<csd-standard xmlns="https://www.calconnect.org/standards/csd">
<bibdata type="standard">
<title language="en" format="plain">Main Title</title>
Expand Down Expand Up @@ -71,7 +71,7 @@
</csd-standard>
INPUT
expect(htmlencode(metadata(csdc.info(docxml, nil)).to_s
.gsub(/, :/, ",\n:"))).to be_equivalent_to <<~"OUTPUT"
.gsub(", :", ",\n:"))).to be_equivalent_to <<~OUTPUT
{:accesseddate=>"XXX",
:agency=>"CalConnect",
:authors=>["Fred Flintstone", "Barney Rubble"],
Expand Down Expand Up @@ -115,10 +115,10 @@
end

it "processes pre" do
input = <<~"INPUT"
input = <<~INPUT
<csd-standard xmlns="https://www.calconnect.org/standards/csd">
<preface>
<foreword>
<foreword displayorder="1">
<pre>ABC</pre>
</foreword>
</preface>
Expand All @@ -134,16 +134,15 @@
<h1 class="ForewordTitle">Foreword</h1>
<pre>ABC</pre>
</div>
<p class="zzSTDTitle1"/>
</div>
</body>
OUTPUT
end

it "processes keyword" do
input = <<~"INPUT"
input = <<~INPUT
<csd-standard xmlns="https://www.calconnect.org/standards/csd">
<preface><foreword>
<preface><foreword displayorder="1">
<keyword>ABC</keyword>
</foreword></preface>
</csd-standard>
Expand All @@ -158,17 +157,17 @@
<h1 class="ForewordTitle">Foreword</h1>
<span class="keyword">ABC</span>
</div>
<p class="zzSTDTitle1"/>
</div>
</body>
OUTPUT
end

it "processes simple terms & definitions" do
input = <<~"INPUT"
input = <<~INPUT
<csd-standard xmlns="http://riboseinc.com/isoxml">
<sections>
<terms id="H" obligation="normative"><title>1.<tab/>Terms, Definitions, Symbols and Abbreviated Terms</title>
<terms id="H" obligation="normative" displayorder="1">
<title>1.<tab/>Terms, Definitions, Symbols and Abbreviated Terms</title>
<term id="J">
<name>1.1.</name>
<preferred><strong>Term2</strong></preferred>
Expand All @@ -182,7 +181,6 @@
.gsub(%r{^.*<body}m, "<body")
.gsub(%r{</body>.*$}m, "</body>"))).to be_equivalent_to xmlpp(<<~"OUTPUT")
#{HTML_HDR}
<p class="zzSTDTitle1"/>
<div id="H">
<h1>1.&#160; Terms, Definitions, Symbols and Abbreviated Terms</h1>
<p class="TermNum" id="J">1.1.</p>
Expand All @@ -194,7 +192,7 @@
end

it "rearranges term headers" do
input = <<~"INPUT"
input = <<~INPUT
<html>
<body lang="EN-US" link="blue" vlink="#954F72" xml:lang="EN-US" class="container">
<div class="title-section">
Expand All @@ -206,7 +204,6 @@
</div>
<br/>
<div class="WordSection3">
<p class="zzSTDTitle1"/>
<div id="H"><h1>1.&#160; Terms and definitions</h1><p>For the purposes of this document,
the following terms and definitions apply.</p>
<p class="TermNum" id="J">1.1.</p>
Expand All @@ -218,7 +215,7 @@
INPUT
expect(xmlpp(IsoDoc::CC::HtmlConvert.new({})
.cleanup(Nokogiri::XML(input)).to_s))
.to be_equivalent_to xmlpp(<<~"OUTPUT")
.to be_equivalent_to xmlpp(<<~OUTPUT)
<?xml version="1.0"?>
<html>
<body lang="EN-US" link="blue" vlink="#954F72" xml:lang="EN-US" class="container">
Expand All @@ -231,7 +228,6 @@
</div>
<br/>
<div class="WordSection3">
<p class="zzSTDTitle1"/>
<div id="H"><h1>1.&#xA0; Terms and definitions</h1>
<p>For the purposes of this document, the following terms and definitions apply.</p>
<p class='Terms' style='text-align:left;' id='J'><strong>1.1.</strong>&#xa0;Term2</p>
Expand All @@ -243,7 +239,7 @@
end

it "processes section names" do
input = <<~"INPUT"
input = <<~INPUT
<csd-standard xmlns="http://riboseinc.com/isoxml">
<preface>
<foreword obligation="informative">
Expand Down Expand Up @@ -319,7 +315,7 @@
expect(xmlpp(strip_guid(IsoDoc::CC::PresentationXMLConvert.new(presxml_options)
.convert("test", input, true)
.gsub(%r{^.*<body}m, "<body")
.gsub(%r{</body>.*$}m, "</body>")))).to be_equivalent_to xmlpp(<<~"OUTPUT")
.gsub(%r{</body>.*$}m, "</body>")))).to be_equivalent_to xmlpp(<<~OUTPUT)
<csd-standard xmlns="http://riboseinc.com/isoxml" type="presentation">
<preface>
<clause type="toc" id="_" displayorder="1">
Expand Down Expand Up @@ -371,6 +367,9 @@
<title depth="2">5.2.<tab/>Clause 4.2</title>
</clause>
</clause>
<references id="R" normative="true" obligation="informative" displayorder="4">
<title depth="1">1.<tab/>Normative References</title>
</references>
</sections>
<annex id="P" inline-header="false" obligation="normative" displayorder="9">
<title><strong>Appendix A</strong><br/>(normative)<br/><strong>Annex</strong></title>
Expand All @@ -382,9 +381,6 @@
</clause>
</annex>
<bibliography>
<references id="R" normative="true" obligation="informative" displayorder="4">
<title depth="1">1.<tab/>Normative References</title>
</references>
<clause id="S" obligation="informative" displayorder="10">
<title depth="1">Bibliography</title>
<references id="T" normative="false" obligation="informative">
Expand Down
9 changes: 4 additions & 5 deletions spec/metanorma/processor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
end

it "registers output formats against metanorma" do
expect(processor.output_formats.sort.to_s).to be_equivalent_to <<~"OUTPUT"
expect(processor.output_formats.sort.to_s).to be_equivalent_to <<~OUTPUT
[[:doc, "doc"], [:html, "html"], [:pdf, "pdf"], [:presentation, "presentation.xml"], [:rxl, "rxl"], [:xml, "xml"]]
OUTPUT
end
Expand All @@ -34,10 +34,10 @@
end

it "generates HTML from IsoDoc XML" do
processor.output(<<~"INPUT", "test.xml", "test.html", :html)
processor.output(<<~INPUT, "test.xml", "test.html", :html)
<csd-standard xmlns="http://riboseinc.com/isoxml">
<sections>
<terms id="H" obligation="normative">
<terms id="H" obligation="normative" displayorder="1">
<title>1.<tab/>Terms, Definitions, Symbols and Abbreviated Terms</title>
<term id="J">
<name>1.1.</name>
Expand All @@ -50,9 +50,8 @@
expect(xmlpp(strip_guid(File.read("test.html", encoding: "utf-8")
.gsub(%r{^.*<main}m, "<main")
.gsub(%r{</main>.*}m, "</main>"))))
.to be_equivalent_to xmlpp(strip_guid(<<~"OUTPUT"))
.to be_equivalent_to xmlpp(strip_guid(<<~OUTPUT))
<main class="main-section"><button onclick="topFunction()" id="myBtn" title="Go to top">Top</button>
<p class="zzSTDTitle1"></p>
<div id="H">
<h1 id="_">1.&#xA0; Terms, Definitions, Symbols and Abbreviated Terms</h1>
<p class='Terms' style='text-align:left;' id='J'><strong>1.1.</strong>&#xa0;Term2</p>
Expand Down

0 comments on commit 354997a

Please sign in to comment.