diff --git a/Gemfile b/Gemfile index f893ab3..ccfd993 100644 --- a/Gemfile +++ b/Gemfile @@ -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" diff --git a/lib/relaton/cli/relaton_file.rb b/lib/relaton/cli/relaton_file.rb index 35d87b1..3add3be 100644 --- a/lib/relaton/cli/relaton_file.rb +++ b/lib/relaton/cli/relaton_file.rb @@ -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] @@ -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 @@ -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] def concatenate_files xml_files = [convert_rxl_to_xml, convert_yamls_to_xml, convert_xml_to_xml] @@ -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] @@ -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) diff --git a/spec/assets/with-collections.xml b/spec/assets/with-collections.xml new file mode 100644 index 0000000..7d7305b --- /dev/null +++ b/spec/assets/with-collections.xml @@ -0,0 +1,96 @@ +ZZZ examplesZzz Zzz Zzz + ZZZ Document + ./documents/doc-1/document.xml + ./documents/doc-1/document.pdf + ./documents/doc-1/document.doc + ./documents/doc-1/document.html + ./documents/doc-1/document.rxl + SG 1-A80 + SG 1-A80-E + 80 + + 2133-07-07 + + + + + Zzz Zzz Zzz + ZZZ + + + + 2 + + en + + + + draft + + + 2025 + + + Zzz Zzz Zzz + ZZZ + + + + Authoring + metanorma + technical-report + template + + contribution + + A + + Sample Group 1 + SG 1 + + 2020 + 2025 + + + + + A + 80 + + + + + Sample ZZZ Collection 1 + ./documents/collections/collection-1/collection.xml + ./documents/collections/collection-1/collection.pdf + ./documents/collections/collection-1/collection.doc + ./documents/collections/collection-1/collection.rxl + SG1-0001 + + 2019 + + + Zzz Zzz Zzz + ZZZ + + + + + + Sample ZZZ Collection 2 + ./documents/collections/collection-2/collection.xml + ./documents/collections/collection-2/collection.pdf + ./documents/collections/collection-2/collection.doc + ./documents/collections/collection-2/collection.rxl + SG1-0002 + + 2020 + + + Zzz Zzz Zzz + ZZZ + + + + + diff --git a/spec/relaton/cli/xml_convertor_spec.rb b/spec/relaton/cli/xml_convertor_spec.rb index 2555149..ffe794d 100644 --- a/spec/relaton/cli/xml_convertor_spec.rb +++ b/spec/relaton/cli/xml_convertor_spec.rb @@ -64,7 +64,7 @@ Relaton::Cli::XMLConvertor.to_html(file) expect(buffer).to include '1149' expect(buffer).to include 'Relaton XML' - expect(buffer).to include 'draft-camelot-holy-grenade-01' + expect(buffer).to include 'draft-camelot-holy-grenade-01' expect(buffer).to include 'Relaton XML' end end diff --git a/spec/relaton/cli/xml_to_html_renderer_spec.rb b/spec/relaton/cli/xml_to_html_renderer_spec.rb index 42438cf..500a6d4 100644 --- a/spec/relaton/cli/xml_to_html_renderer_spec.rb +++ b/spec/relaton/cli/xml_to_html_renderer_spec.rb @@ -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("[^{]+Date and time -- Timezone -- Timezone Manageme[^}]+[^{]+Date and time -- Calendars -- Gregorian calendar[^}]+[\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("[^{]+Date and time -- Timezone -- Timezone Manageme[^}]+[^{]+Date and time -- Calendars -- Gregorian calendar[^}]+[\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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index db22666..c3daff2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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 diff --git a/templates/_document.liquid b/templates/_document.liquid index fd1f160..138c376 100644 --- a/templates/_document.liquid +++ b/templates/_document.liquid @@ -4,13 +4,25 @@
{%- 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 -%} +
- {% if document.html == "" %} - {{ document.docid.id }} + {% if default_link %} + {{ document.docid.id }} {% else %} - {{ document.docid.id }} + {{ document.docid.id }} {% endif %}
@@ -25,19 +37,20 @@
Edition: {{ document.edition.content }}
- {% endif %} + {% endif %}
- {% if document.html == blank or document.html == nil %} - {{ document.title }} + {% if default_link %} + {{ document.title }} {% else %} - {{ document.title }} + {{ document.title }} {% endif %}
+ {% if document.docstatus %}
{{ document.docstatus.stage.abbreviation }} @@ -57,6 +70,7 @@
+ {% endif %}