Skip to content
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
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ gem "rake"
gem "rspec", "~> 3.0"
gem "rspec-command", "~> 1.0.3"
gem "rspec-core", "~> 3.4"
gem "rspec-html", "~> 0.3.0"
gem "simplecov"
gem "vcr"
gem "webmock"
16 changes: 15 additions & 1 deletion lib/relaton/cli/relaton_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ def bibcollection
)
end

# Turn an XML string into a Nokogiri XML document.
#
# @param document [String] XML
# @param file [String, nil] path to file
# @return [Nokogiri::XML::Document]
Expand Down Expand Up @@ -119,7 +121,7 @@ def extract_and_write_to_files # rubocop:disable Metrics/AbcSize, Metrics/Method
elsif (rfc = xml.at("//rfc"))
require "relaton_ietf/bibxml_parser"
ietf = RelatonIetf::BibXMLParser.fetch_rfc rfc
bib = nokogiri_document ietf.to_xml(bibdata: true)
bib = nokogiri_document(ietf.to_xml(bibdata: true))
else
next
end
Expand All @@ -136,6 +138,9 @@ def extract_and_write_to_files # rubocop:disable Metrics/AbcSize, Metrics/Method
end
end

# Map all relevant files to the corresponding bibdata instances
#
# @return [Array<Relaton::Bibdata>]
def concatenate_files
xml_files = [convert_rxl_to_xml, convert_yamls_to_xml, convert_xml_to_xml]

Expand Down Expand Up @@ -188,6 +193,10 @@ def output_type(ext = options[:extension])
end
end

# Create a bibdata instance from the XML document,
# while also adding file paths of related artifacts
# as URI elements to the bibdata instance.
#
# @param document [Nokogiri::XML::Document]
# @param file [String] path to file
# @return [Relaton::Bibdata]
Expand All @@ -199,6 +208,11 @@ def bibdata_instance(document, file)
bibdata
end

# For each file type, add to the bibdata:
# - a URI element that points to the file of that file type
#
# The URI element generation is skipped if the file does not exist.
#
# @param bibdata [Relaton::Bibdata]
# @param file [String] path to file
def build_bibdata_relaton(bibdata, file)
Expand Down
96 changes: 96 additions & 0 deletions spec/assets/with-collections.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<relaton-collection xmlns="https://open.ribose.com/relaton-xml"><title>ZZZ examples</title><contributor><role type='author'/><organization><name>Zzz Zzz Zzz</name></organization></contributor><relation type='partOf'><bibdata type="standard" schema-version="v1.2.9">
<title type="main" format="text/plain" language="en">ZZZ Document</title>
<uri type="xml">./documents/doc-1/document.xml</uri>
<uri type="pdf">./documents/doc-1/document.pdf</uri>
<uri type="doc">./documents/doc-1/document.doc</uri>
<uri type="html">./documents/doc-1/document.html</uri>
<uri type="rxl">./documents/doc-1/document.rxl</uri>
<docidentifier type="ZZZ" primary="true">SG 1-A80</docidentifier>
<docidentifier type="ZZZ-lang">SG 1-A80-E</docidentifier>
<docnumber>80</docnumber>
<date type="published">
<on>2133-07-07</on>
</date>
<contributor>
<role type="author"/>
<organization>
<name>Zzz Zzz Zzz</name>
<abbreviation>ZZZ</abbreviation>
</organization>
</contributor>
<version>
<draft>2</draft>
</version>
<language>en</language>
<script>Latn</script>
<abstract/>
<status>
<stage>draft</stage>
</status>
<copyright>
<from>2025</from>
<owner>
<organization>
<name>Zzz Zzz Zzz</name>
<abbreviation>ZZZ</abbreviation>
</organization>
</owner>
</copyright>
<keyword>Authoring</keyword>
<keyword>metanorma</keyword>
<keyword>technical-report</keyword>
<keyword>template</keyword>
<ext schema-version="v1.0.0">
<doctype>contribution</doctype>
<editorialgroup>
<bureau>A</bureau>
<group type="study-group">
<name>Sample Group 1</name>
<acronym>SG 1</acronym>
<period>
<start>2020</start>
<end>2025</end>
</period>
</group>
</editorialgroup>
<structuredidentifier>
<bureau>A</bureau>
<docnumber>80</docnumber>
</structuredidentifier>
</ext>
</bibdata></relation>
<relation type='partOf'><bibdata type="collection" schema-version="v1.2.9">
<title format="text/plain" language="en">Sample ZZZ Collection 1</title>
<uri type="xml">./documents/collections/collection-1/collection.xml</uri>
<uri type="pdf">./documents/collections/collection-1/collection.pdf</uri>
<uri type="doc">./documents/collections/collection-1/collection.doc</uri>
<uri type="rxl">./documents/collections/collection-1/collection.rxl</uri>
<docidentifier type="ZZZ">SG1-0001</docidentifier>
<copyright>
<from>2019</from>
<owner>
<organization>
<name>Zzz Zzz Zzz</name>
<abbreviation>ZZZ</abbreviation>
</organization>
</owner>
</copyright>
</bibdata></relation>
<relation type='partOf'><bibdata type="collection" schema-version="v1.2.9">
<title format="text/plain" language="en">Sample ZZZ Collection 2</title>
<uri type="xml">./documents/collections/collection-2/collection.xml</uri>
<uri type="pdf">./documents/collections/collection-2/collection.pdf</uri>
<uri type="doc">./documents/collections/collection-2/collection.doc</uri>
<uri type="rxl">./documents/collections/collection-2/collection.rxl</uri>
<docidentifier type="ZZZ">SG1-0002</docidentifier>
<copyright>
<from>2020</from>
<owner>
<organization>
<name>Zzz Zzz Zzz</name>
<abbreviation>ZZZ</abbreviation>
</organization>
</owner>
</copyright>
</bibdata></relation>
</relaton-collection>
2 changes: 1 addition & 1 deletion spec/relaton/cli/xml_convertor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
Relaton::Cli::XMLConvertor.to_html(file)
expect(buffer).to include '<a href="spec/fixtures/documents/example.html">1149</a>'
expect(buffer).to include '<a href="spec/fixtures/documents/example.rxl">Relaton XML</a>'
expect(buffer).to include '<a href="">draft-camelot-holy-grenade-01</a>'
expect(buffer).to include '<a href="spec/fixtures/documents/antioch.rfc.xml">draft-camelot-holy-grenade-01</a>'
expect(buffer).to include '<a href="spec/fixtures/documents/antioch.rxl">Relaton XML</a>'
end
end
Expand Down
88 changes: 67 additions & 21 deletions spec/relaton/cli/xml_to_html_renderer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,78 @@
RSpec.describe Relaton::Cli::XmlToHtmlRenderer do

let(:document) do
parse_html(html)
end

let(:renderer) do
Relaton::Cli::XmlToHtmlRenderer.new(
liquid_dir: "templates",
stylesheet: "spec/assets/index-style.css",
)
end

describe ".render" do
it "generates the HTML output" do
html = Relaton::Cli::XmlToHtmlRenderer.new(
liquid_dir: "templates",
stylesheet: "spec/assets/index-style.css",
).render(File.read("spec/assets/index.xml"))

expect(html).to include("<html")
expect(html).to include("<div class=\"document\"")
expect(html).to include("CC/Amd 86003")
expect(html).to include("CalConnect Inc\.")
expect(html).to include("I AM A SAMPLE STYLESHEET")
expect(html).to include("CalConnect Standards Registry")
expect(html).to match(/<h3>[^{]+Date and time -- Timezone -- Timezone Manageme[^}]+</)
expect(html).to match(/<h3>[^{]+Date and time -- Calendars -- Gregorian calendar[^}]+</)
expect(html).to match(/<div class="doc-stage proposal">[\R\s]+proposal[\R\s]+<\/div>/)
expect(html).to include("http://calconnect.org/pubdocs/CD0507%20CalDAV")
context "with a document containing a stylesheet" do
let(:html) do
renderer.render(File.read("spec/assets/index.xml"))
end

it "generates the HTML output" do
expect(html).to include("<html")
expect(html).to include("<div class=\"document\"")
expect(html).to include("CC/Amd 86003")
expect(html).to include("CalConnect Inc\.")
expect(html).to include("I AM A SAMPLE STYLESHEET")
expect(html).to include("CalConnect Standards Registry")
expect(html).to match(/<h3>[^{]+Date and time -- Timezone -- Timezone Manageme[^}]+</)
expect(html).to match(/<h3>[^{]+Date and time -- Calendars -- Gregorian calendar[^}]+</)
expect(html).to match(/<div class="doc-stage proposal">[\R\s]+proposal[\R\s]+<\/div>/)
expect(html).to include("http://calconnect.org/pubdocs/CD0507%20CalDAV")
end
end

context "with a document containing other collections" do
let(:html) do
renderer.render(File.read("spec/assets/with-collections.xml"))
end

it "renders links with relative paths" do
document.div(class: "document").a.all.each do |a|
expect(Pathname.new(a[:href])).to be_relative
end
end

context "for the only rendered document" do
subject(:section) do
document.div(class: 'document')[1]
end

it "renders with stage" do
expect(section).to have_css(".doc-stage")
expect(section.div(class: "doc-info")[:class]).to match 'draft'
expect(section.div(class: "doc-stage")[:class]).to match 'draft'
end
end

context "for the rendered collections" do
it "renders without stage" do
(2..3).map do |i|
document.div(class: 'document')[i]
end.each do |e|
expect(e).to_not have_css(".doc-info")
expect(e).to_not have_css(".doc-stage")
end
end
end

end

end

describe "#uri_for_extension" do
it "replace file extension with the provided one" do
xmltohtml = Relaton::Cli::XmlToHtmlRenderer.new(
stylesheet: "spec/assets/index-style.css", liquid_dir: "templates",
)

expect(
xmltohtml.uri_for_extension("index.xml", "html"),
renderer.uri_for_extension("index.xml", "html"),
).to eq("index.html")
end
end
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Dir["./spec/support/**/*.rb"].sort.each { |f| require f }

require "relaton/cli"
require "rspec/html"

RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
Expand Down
28 changes: 21 additions & 7 deletions templates/_document.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,25 @@
<div class="document">
{%- endif -%}

{%- if document.html != blank and document.html != nil -%}
{%- assign default_link = document.html -%}
{%- elsif document.pdf != blank and document.pdf != nil -%}
{%- assign default_link = document.pdf -%}
{%- elsif document.doc != blank and document.doc != nil -%}
{%- assign default_link = document.doc -%}
{%- elsif document.xml != blank and document.xml != nil -%}
{%- assign default_link = document.xml -%}
{%- else -%}
{%- assign default_link = nil -%}
{%- endif -%}

<div class="doc-line">
<div class="doc-identifier">
<h{{ depth }}>
{% if document.html == "" %}
{{ document.docid.id }}
{% if default_link %}
<a href="{{ default_link }}">{{ document.docid.id }}</a>
{% else %}
<a href="{{ document.html }}">{{ document.docid.id }}</a>
{{ document.docid.id }}
{% endif %}
</h{{ depth }}>
</div>
Expand All @@ -25,19 +37,20 @@
<div class="doc-identifier">
Edition: {{ document.edition.content }}
</div>
{% endif %}
{% endif %}
</div>

<div class="doc-title">
<h{{ depth | plus: 1 }}>
{% if document.html == blank or document.html == nil %}
{{ document.title }}
{% if default_link %}
<a href="{{ default_link }}">{{ document.title }}</a>
{% else %}
<a href="{{ document.html }}">{{ document.title }}</a>
{{ document.title }}
{% endif %}
</h{{ depth | plus: 1 }}>
</div>

{% if document.docstatus %}
<div class="doc-info {{ document.docstatus.stage.value | downcase }}">
<div class="doc-stage {{ document.docstatus.stage.value | downcase }}">
{{ document.docstatus.stage.abbreviation }}
Expand All @@ -57,6 +70,7 @@
</div>
</div>
</div>
{% endif %}

<div class="doc-bib">
<div class="doc-bib-relaton">
Expand Down
Loading