Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boilerplate copyright appended content processing: https://github.com… #1229

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Gemfile.devel
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
gem "metanorma-standoc", git: "https://github.com/metanorma/metanorma-standoc", branch: "features/boilerplate-append"



6 changes: 4 additions & 2 deletions lib/isodoc/iso/html/word_iso_intro-dis.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{% if doctype == "Amendment" or doctype == "Technical Corrigendum" %}
{% else %}

<div id="boilerplate-copyright-destination"/>

<div id="boilerplate-copyright-destination">
<div id="boilerplate-copyright-default-destination"/>
<div id="boilerplate-copyright-append-destination"/>
</div>

{% endif %}
5 changes: 4 additions & 1 deletion lib/isodoc/iso/html/word_iso_intro.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<div id="boilerplate-copyright-destination">
<div style='mso-element:para-border-div;border:solid windowtext 1.0pt;
border-bottom-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:
solid windowtext .5pt;mso-border-right-alt:solid windowtext .5pt;padding:1.0pt 4.0pt 0cm 4.0pt;
margin-left:5.1pt;margin-right:5.1pt'>
<div id="boilerplate-copyright-destination"/>
<div id="boilerplate-copyright-default-destination"/>
</div>
<div id="boilerplate-copyright-append-destination"/>
</div>

{% if doctype == "Amendment" or doctype == "Technical Corrigendum" %}
Expand Down
50 changes: 33 additions & 17 deletions lib/isodoc/iso/word_cleanup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,26 +110,44 @@ def authority_hdr_cleanup(docxml)
end

def authority_cleanup(docxml)
insert = docxml.at("//div[@id = 'boilerplate-license-destination']")
auth = docxml.at("//div[@class = 'boilerplate-license']")&.remove
auth&.xpath(".//p[not(@class)]")&.each { |p| p["class"] = "zzWarning" }
auth and insert and insert.children = auth
insert = docxml.at("//div[@id = 'boilerplate-copyright-destination']")
auth = docxml.at("//div[@class = 'boilerplate-copyright']")&.remove
auth&.xpath(".//p[not(@class)]")&.each do |p|
p["class"] = "zzCopyright"
end
auth&.xpath(".//p[@id = 'boilerplate-message']")&.each do |p|
authority_license_cleanup(docxml)
authority_copyright_cleanup(docxml)
coverpage_note_cleanup(docxml)
end

def authority_copyright_cleanup(docxml)
auth = docxml.at("//div[@class = 'boilerplate-copyright']") or return
authority_copyright_style(auth)
authority_copyright_populate(docxml, auth)
end

def authority_copyright_style(auth)
auth.xpath(".//p[not(@class)]").each { |p| p["class"] = "zzCopyright" }
auth.xpath(".//p[@id = 'boilerplate-message']").each do |p|
p["class"] = "zzCopyright1"
end
auth&.xpath(".//p[@id = 'boilerplate-address']")&.each do |p|
auth.xpath(".//p[@id = 'boilerplate-address']").each do |p|
p["class"] = "zzAddress"
end
auth&.xpath(".//p[@id = 'boilerplate-place']")&.each do |p|
auth.xpath(".//p[@id = 'boilerplate-place']").each do |p|
p["class"] = "zzCopyright1"
end
auth and insert and insert.children = auth
coverpage_note_cleanup(docxml)
end

def authority_copyright_populate(doc, auth)
i = doc.at("//div[@id = 'boilerplate-copyright-default-destination']")
j = doc.at("//div[@id = 'boilerplate-copyright-append-destination']")
default = auth.at(".//div[@id = 'boilerplate-copyright-default']")
default and i and i.children = default.remove
j and j.children = auth.remove
end

def authority_license_cleanup(docxml)
dest = docxml.at("//div[@id = 'boilerplate-license-destination']") or
return
auth = docxml.at("//div[@class = 'boilerplate-license']") or return
auth.xpath(".//p[not(@class)]").each { |p| p["class"] = "zzWarning" }
dest.children = auth.remove
end

def word_cleanup(docxml)
Expand All @@ -142,9 +160,7 @@ def word_cleanup(docxml)
# supply missing annex title
def make_WordToC(docxml, level)
toc = ""
if source = docxml.at("//div[@class = 'TOC']")
toc = to_xml(source.children)
end
s = docxml.at("//div[@class = 'TOC']") and toc = to_xml(s.children)
xpath = (1..level).each.map { |i| "//h#{i}" }.join (" | ")
docxml.xpath(xpath).each do |h|
x = ""
Expand Down
4 changes: 4 additions & 0 deletions lib/metanorma/iso/boilerplate-fr.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
== copyright-statement
{% if document_scheme == "1951" %}

[[boilerplate-copyright-default]]
=== REPRODUCTION INTERDITE

[[boilerplate-message]]
Expand All @@ -20,6 +21,7 @@ nationales de normalisation.

{% elsif document_scheme == "1972" or document_scheme == "1987" %}

[[boilerplate-copyright-default]]
=== {blank}

[[boilerplate-year]]
Expand All @@ -31,6 +33,7 @@ Publié en Suisse

{% elsif document_scheme == "1989" %}

[[boilerplate-copyright-default]]
=== {blank}

[[boilerplate-year]]
Expand All @@ -53,6 +56,7 @@ Imprimé en Suisse


{% else %}
[[boilerplate-copyright-default]]
=== {% if stage_int >= 40 %}DOCUMENT PROTÉGÉ PAR COPYRIGHT{%else%}{blank}{%endif%}

[[boilerplate-year]]
Expand Down
3 changes: 3 additions & 0 deletions lib/metanorma/iso/boilerplate-ru.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

{% if document_scheme == "1972" or document_scheme == "1987" %}

[[boilerplate-copyright-default]]
=== {blank}

[[boilerplate-year]]
Expand All @@ -12,6 +13,7 @@

{% elsif document_scheme == "1989" %}

[[boilerplate-copyright-default]]
=== {blank}

[[boilerplate-year]]
Expand All @@ -34,6 +36,7 @@ X.400&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;c=ch; a=400net;

{% else %}

[[boilerplate-copyright-default]]
=== {% if stage_int >= 40 %}ДОКУМЕНТ, ОХРАНЯЕМЫЙ АВТОРСКИМ ПРАВОМ{% else %}{blank}{% endif %}

[[boilerplate-year]]
Expand Down
4 changes: 4 additions & 0 deletions lib/metanorma/iso/boilerplate.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

{% if document_scheme == "1951" %}

[[boilerplate-copyright-default]]
=== COPYRIGHT RESERVED

[[boilerplate-message]]
Expand All @@ -20,6 +21,7 @@ Also issued in French and Russian. Copies to be obtained through the national st

{% elsif document_scheme == "1972" or document_scheme == "1987" %}

[[boilerplate-copyright-default]]
=== {blank}

[[boilerplate-year]]
Expand All @@ -31,6 +33,7 @@ Printed in Switzerland

{% elsif document_scheme == "1989" %}

[[boilerplate-copyright-default]]
=== {blank}

[[boilerplate-year]]
Expand All @@ -53,6 +56,7 @@ Printed in Switzerland

{% else %}

[[boilerplate-copyright-default]]
=== {% if stage_int >= 40 %}COPYRIGHT PROTECTED DOCUMENT{% else %}{blank}{% endif %}

[[boilerplate-year]]
Expand Down
93 changes: 60 additions & 33 deletions spec/isodoc/postproc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@
</bibdata>
<boilerplate>
<copyright-statement>
<clause>
<clause id="boilerplate-copyright-default">
<p id="boilerplate-year">© ISO 2019, Published in Switzerland</p>
<p id="boilerplate-message">I am the Walrus.</p>
<p id="boilerplate-name">ISO copyright office</p>
Expand All @@ -835,6 +835,9 @@
<br/>
www.iso.org</p>
</clause>
<clause id="added">
<p>Is there anybody out there?</p>
</clause>
</copyright-statement>
<license-statement>
<clause>
Expand Down Expand Up @@ -862,7 +865,7 @@
</bibdata>
<boilerplate>
<copyright-statement>
<clause inline-header="true">
<clause inline-header="true" id="boilerplate-copyright-default">
<p id="boilerplate-year">© ISO 2019, Published in Switzerland
</p>
<p id="boilerplate-message">I am the Walrus.
Expand All @@ -880,6 +883,9 @@
<br/>
www.iso.org</p>
</clause>
<clause id="added" inline-header="true">
<p>Is there anybody out there?</p>
</clause>
</copyright-statement>
<license-statement>
<clause>
Expand All @@ -897,7 +903,8 @@
</iso-standard>
OUTPUT

expect(Xml::C14n.format(IsoDoc::Iso::PresentationXMLConvert.new(WORD_HTML_CSS.dup
expect(Xml::C14n.format(IsoDoc::Iso::PresentationXMLConvert
.new(WORD_HTML_CSS.dup
.merge(presxml_options))
.convert("test", input, true))
.sub(%r{<localized-strings>.*</localized-strings>}m, ""))
Expand All @@ -909,45 +916,65 @@
.convert("test", presxml, false)

word = File.read("test.html", encoding: "UTF-8")
expect(strip_guid(word)).to include('<h1 class="IntroTitle">Warning for Stuff</h1>')
expect(strip_guid(word))
.to include('<h1 class="IntroTitle">Warning for Stuff</h1>')
expect(word).to include("I am the Walrus.")

FileUtils.rm_rf "test.doc"
IsoDoc::Iso::WordConvert.new(WORD_HTML_CSS.dup)
.convert("test", presxml, false)
word = File.read("test.doc", encoding: "UTF-8")
expect(Xml::C14n.format(word
.sub(%r{^.*<div class="boilerplate-copyright">}m,
'<div class="boilerplate-copyright">')
.sub(%r{</div>.*$}m, "</div></div>")))
contents = word.sub(%r{^.*<body}m, "<body").sub(%r{</body>.*$}m, "</body>")
contents = Nokogiri::XML(contents)
.at("//div[a/@id = 'boilerplate-copyright-destination']")
expect(Xml::C14n.format(contents.to_xml))
.to be_equivalent_to Xml::C14n.format(<<~"OUTPUT")
<div class="boilerplate-copyright">
<div>
<a name="boilerplate-copyright-destination" id="boilerplate-copyright-destination"/>
<div style="mso-element:para-border-div;border:solid windowtext 1.0pt; border-bottom-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt: solid windowtext .5pt;mso-border-right-alt:solid windowtext .5pt;padding:1.0pt 4.0pt 0cm 4.0pt; margin-left:5.1pt;margin-right:5.1pt">
<div>
<a name="boilerplate-copyright-default-destination" id="boilerplate-copyright-default-destination"/>
<div>
<a name="boilerplate-copyright-default" id="boilerplate-copyright-default"/>
<p class="zzCopyright">
<a name="boilerplate-year" id="boilerplate-year"/>
© ISO 2019, Published in Switzerland
</p>
<p class="zzCopyright1">
<a name="boilerplate-message" id="boilerplate-message"/>
I am the Walrus.
</p>
<p class="zzCopyright">
<a name="boilerplate-name" id="boilerplate-name"/>
ISO copyright office
</p>
<p style="text-align:left;" align="left" class="zzAddress">
<a name="boilerplate-address" id="boilerplate-address"/>
ISO copyright office
<br/>
Ch. de Blandonnet 8 ?~@? CP 401
<br/>
CH-1214 Vernier, Geneva, Switzerland
<br/>
Phone: +41 22 749 01 11
<br/>
Email: [email protected]
<br/>
www.iso.org
</p>
</div>
</div>
</div>
<div>
<p class="zzCopyright">
<a id="boilerplate-year" name="boilerplate-year"/>© ISO 2019, Published in Switzerland#{' '}</p>
<p class="zzCopyright1">
<a id="boilerplate-message" name="boilerplate-message"/>I am the Walrus.#{' '}</p>
<p class="zzCopyright">
<a id="boilerplate-name" name="boilerplate-name"/>ISO copyright office</p>
<p align="left" class="zzAddress" style="text-align:left;">
<a id="boilerplate-address" name="boilerplate-address"/>ISO copyright office

<br/>
Ch. de Blandonnet 8 ?~@? CP 401

<br/>
CH-1214 Vernier, Geneva, Switzerland

<br/>
Phone: +41 22 749 01 11

<br/>
Email: [email protected]

<br/>
www.iso.org#{' '}</p>
<a name="boilerplate-copyright-append-destination" id="boilerplate-copyright-append-destination"/>
<div class="boilerplate-copyright">
<div>
<a name="added" id="added"/>
<p class="zzCopyright">Is there anybody out there?</p>
</div>
</div>
</div>
</div>
</div>
OUTPUT
expect(word).to include('<p class="zzWarning">This document is not ' \
"an ISO International Standard")
Expand Down
Loading
Loading