Skip to content

Commit

Permalink
Merge pull request #916 from metanorma/fix/attachment-localdir
Browse files Browse the repository at this point in the history
Fix/attachment localdir
  • Loading branch information
opoudjis authored Aug 15, 2024
2 parents 97323da + ae9cf67 commit 4358e63
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 52 deletions.
10 changes: 6 additions & 4 deletions lib/metanorma/standoc/cleanup_bibitem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,12 @@ def save_attachment(path, bib)
def datauri_attachment(path, doc)
@datauriattachment or return
m = add_misc_container(doc)
f = File.basename(path)
d = Vectory::Utils::datauri(path, @localdir)
m << "<attachment name='#{f}'/>"
m.last_element_child << d
f = File.join(@attachmentsdir, File.basename(path))
f = Pathname.new(File.expand_path(f))
.relative_path_from(Pathname.new(File.expand_path(@localdir)))
e = (m << "<attachment name='#{f}'/>").last_element_child
Vectory::Utils::datauri(path, @localdir).scan(/.{1,60}/)
.each { |dd| e << "#{dd}\n" }
end

def valid_attachment?(path, bib)
Expand Down
1 change: 1 addition & 0 deletions spec/assets/attach.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ Author

* [[[iso123,attachment:(iso.xml)]]]
* [[[iso124,attachment:(iso.xml)]]]
* [[[iso125,attachment:(html.scss)]]]

122 changes: 74 additions & 48 deletions spec/metanorma/refs_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require "spec_helper"
require "relaton_iso"
require "relaton_ietf"
require "relaton_nist"

RSpec.describe Metanorma::Standoc do
it "processes simple ISO reference" do
Expand Down Expand Up @@ -1174,8 +1175,25 @@
end

it "processes attachments" do
attachment =
if RUBY_PLATFORM.include?('mingw') || RUBY_PLATFORM.include?('mswin')
<<~OUTPUT
DQpwIHsNCiAgZm9udC1mYW1
pbHk6ICRib2R5Zm9udDsNCn0NCg0KaDEgew0KICBmb250LWZhbWlseTogJGh
lYWRlcmZvbnQ7DQp9DQoNCnByZSB7DQogIGZvbnQtZmFtaWx5OiAkbW9ub3N
wYWNlZm9udDsNCn0NCg0K
OUTPUT
else
<<~OUTPUT
CnAgewogIGZvbnQtZmFtaWx
5OiAkYm9keWZvbnQ7Cn0KCmgxIHsKICBmb250LWZhbWlseTogJGhlYWRlcmZ
vbnQ7Cn0KCnByZSB7CiAgZm9udC1mYW1pbHk6ICRtb25vc3BhY2Vmb250Owp
9Cgo=
OUTPUT
end
input = File.read("spec/assets/attach.adoc")
.gsub("iso.xml", "spec/assets/iso.xml")
.gsub("html.scss", "spec/assets/html.scss")
output = <<~OUTPUT
<standard-document xmlns="https://www.metanorma.org/ns/standoc" type="semantic" version="#{Metanorma::Standoc::VERSION}">
<bibdata type="standard">
Expand All @@ -1192,52 +1210,59 @@
<doctype>standard</doctype>
</ext>
</bibdata>
<metanorma-extension>
<attachment name="iso.xml">data:application/octet-stream;base64,ICAgIC...</attachment>
<attachment name="iso.xml_">data:application/octet-stream;base64,ICAgIC...</attachment>
<presentation-metadata>
<name>TOC Heading Levels</name>
<value>2</value>
</presentation-metadata>
<presentation-metadata>
<name>HTML TOC Heading Levels</name>
<value>2</value>
</presentation-metadata>
<presentation-metadata>
<name>DOC TOC Heading Levels</name>
<value>2</value>
</presentation-metadata>
<presentation-metadata>
<name>PDF TOC Heading Levels</name>
<value>2</value>
</presentation-metadata>
</metanorma-extension>
<sections>
<clause id="_" inline-header="false" obligation="normative">
<title>Clause</title>
<p id="_">
<eref type="inline" bibitemid="iso123" citeas="[spec/assets/iso.xml]"/>
</p>
</clause>
</sections>
<bibliography>
<references id="_" normative="true" obligation="informative">
<title>Normative references</title>
<p id="_">The following documents are referred to in the text in such a way that some or all of their content constitutes requirements of this document. For dated references, only the edition cited applies. For undated references, the latest edition of the referenced document (including any amendments) applies.</p>
<bibitem id="iso123" hidden="true">
<formattedref format="application/x-isodoc+xml">[NO INFORMATION AVAILABLE]</formattedref>
<uri type="attachment">_attach_attachments/iso.xml</uri>
<uri type="citation">_attach_attachments/iso.xml</uri>
<docidentifier type="metanorma">[spec/assets/iso.xml]</docidentifier>
</bibitem>
<bibitem id="iso124" hidden="true">
<formattedref format="application/x-isodoc+xml">[NO INFORMATION AVAILABLE]</formattedref>
<uri type="attachment">_attach_attachments/iso.xml_</uri>
<uri type="citation">_attach_attachments/iso.xml_</uri>
<docidentifier type="metanorma">[spec/assets/iso.xml]</docidentifier>
</bibitem>
</references>
</bibliography>
<metanorma-extension>
<attachment name="_attach_attachments/iso.xml">data:application/octet-stream;base64,ICAgIC...</attachment>
<attachment name="_attach_attachments/iso.xml_">data:application/octet-stream;base64,ICAgIC...</attachment>
<attachment name="_attach_attachments/html.scss">data:application/octet-stream;base64,#{attachment}</attachment>
<presentation-metadata>
<name>TOC Heading Levels</name>
<value>2</value>
</presentation-metadata>
<presentation-metadata>
<name>HTML TOC Heading Levels</name>
<value>2</value>
</presentation-metadata>
<presentation-metadata>
<name>DOC TOC Heading Levels</name>
<value>2</value>
</presentation-metadata>
<presentation-metadata>
<name>PDF TOC Heading Levels</name>
<value>2</value>
</presentation-metadata>
</metanorma-extension>
<sections>
<clause id="_" inline-header="false" obligation="normative">
<title>Clause</title>
<p id="_">
<eref type="inline" bibitemid="iso123" citeas="[spec/assets/iso.xml]"/>
</p>
</clause>
</sections>
<bibliography>
<references id="_" normative="true" obligation="informative">
<title>Normative references</title>
<p id="_">The following documents are referred to in the text in such a way that some or all of their content constitutes requirements of this document. For dated references, only the edition cited applies. For undated references, the latest edition of the referenced document (including any amendments) applies.</p>
<bibitem id="iso123" hidden="true">
<formattedref format="application/x-isodoc+xml">[NO INFORMATION AVAILABLE]</formattedref>
<uri type="attachment">_attach_attachments/iso.xml</uri>
<uri type="citation">_attach_attachments/iso.xml</uri>
<docidentifier type="metanorma">[spec/assets/iso.xml]</docidentifier>
</bibitem>
<bibitem id="iso124" hidden="true">
<formattedref format="application/x-isodoc+xml">[NO INFORMATION AVAILABLE]</formattedref>
<uri type="attachment">_attach_attachments/iso.xml_</uri>
<uri type="citation">_attach_attachments/iso.xml_</uri>
<docidentifier type="metanorma">[spec/assets/iso.xml]</docidentifier>
</bibitem>
<bibitem id="iso125" hidden="true">
<formattedref format="application/x-isodoc+xml">[NO INFORMATION AVAILABLE]</formattedref>
<uri type="attachment">_attach_attachments/html.scss</uri>
<uri type="citation">_attach_attachments/html.scss</uri>
<docidentifier type="metanorma">[spec/assets/html.scss]</docidentifier>
</bibitem>
</references>
</bibliography>
</standard-document>
OUTPUT

Expand All @@ -1251,15 +1276,16 @@
.gsub(/iso.xml_[a-f0-9-]+/, "iso.xml_")
.gsub(/ICAgIC[^<]+/, "ICAgIC..."))))
.to be_equivalent_to Xml::C14n.format(output
.gsub(%r{<attachment .+?</attachment>}, ""))
.gsub(%r{<attachment .+?</attachment>}m, ""))

FileUtils.rm_rf "spec/assets/attach.xml"
system "bundle exec asciidoctor -b standoc -r metanorma-standoc spec/assets/attach.adoc"
expect(Xml::C14n.format(strip_guid(File.read("spec/assets/attach.xml")
.gsub(/iso.xml_[a-f0-9-]+/, "iso.xml_")
.gsub(/ICAgIC[^<]+/, "ICAgIC..."))))
.to be_equivalent_to Xml::C14n.format(output
.gsub("spec/assets/iso.xml", "iso.xml"))
.gsub("spec/assets/iso.xml", "iso.xml")
.gsub("spec/assets/html.scss", "html.scss"))
end

private
Expand Down

0 comments on commit 4358e63

Please sign in to comment.