Skip to content

Commit

Permalink
automatically set document-scheme based on copyright-year: #1148
Browse files Browse the repository at this point in the history
  • Loading branch information
opoudjis committed Apr 1, 2024
1 parent d824d45 commit 6aae21b
Show file tree
Hide file tree
Showing 11 changed files with 1,206 additions and 1,265 deletions.
3 changes: 2 additions & 1 deletion Gemfile.devel
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
gem "isodoc", git: "https://github.com/metanorma/isodoc", branch: "main"
gem "isodoc", git: "https://github.com/metanorma/isodoc", branch: "fix/refactor-toWord"
gem "metanorma-standoc", git: "https://github.com/metanorma/metanorma-standoc", branch: "main"
10 changes: 4 additions & 6 deletions lib/isodoc/iso/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ def index_entries(words, index, primary)
ret = index_entries_head(words[primary],
index.dig(words[primary], nil, nil),
index_entries_opt)
words2 = index[words[primary]]&.keys&.reject do |k|
k.nil?
end&.each_with_object({}) { |w, v| v[w.downcase] = w }
words2 = index[words[primary]]&.keys&.compact
&.each_with_object({}) { |w, v| v[w.downcase] = w }
unless words2.empty?
ret += "<ul>"
words2.keys.localize(@lang.to_sym).sort.to_a.each do |w|
Expand All @@ -67,9 +66,8 @@ def index_entries2(words, index, secondary)
ret = index_entries_head(words[secondary],
index.dig(words[secondary], nil),
index_entries_opt)
words3 = index[words[secondary]]&.keys&.reject do |k|
k.nil?
end&.each_with_object({}) { |w, v| v[w.downcase] = w }
words3 = index[words[secondary]]&.keys&.compact
&.each_with_object({}) { |w, v| v[w.downcase] = w }
unless words3.empty?
ret += "<ul>"
words3.keys.localize(@lang.to_sym).sort.to_a.each do |w|
Expand Down
2 changes: 1 addition & 1 deletion lib/isodoc/iso/word_dis_cleanup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def word_cleanup(docxml)
end

def word_section_end_empty_para(docxml)
docxml.at("//div[@class='WordSection1']/p[last()]").remove
docxml.at("//div[@class='WordSection1']/p[last()]")&.remove
end

def word_table_cell_para(docxml)
Expand Down
2 changes: 0 additions & 2 deletions lib/isodoc/iso/word_dis_convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ def make_tr_attr(cell, row, totalrows, header, bordered)
end

def toWord(result, filename, dir, header)
result = from_xhtml(word_cleanup(to_xhtml(result)))
.gsub("-DOUBLE_HYPHEN_ESCAPE-", "--")
@wordstylesheet = wordstylesheet_update
::Html2Doc::IsoDIS.new(
filename: filename,
Expand Down
10 changes: 9 additions & 1 deletion lib/metanorma/iso/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,16 @@ def admonition_name(node)
name
end

DOCUMENT_SCHEMES = [1951, 1972, 1979, 1987, 1989, 2012, 2013, 2024].freeze

def document_scheme(node)
node.attr("document-scheme") || "2024"
r = node.attr("document-scheme") and return r
r = node.attr("copyright-year")&.to_i or return "2024"
DOCUMENT_SCHEMES.each_index do |i|
i.zero? and next
r < DOCUMENT_SCHEMES[i] and return DOCUMENT_SCHEMES[i - 1].to_s
end
"2024"
end

def outputs(node, ret)
Expand Down
310 changes: 91 additions & 219 deletions spec/isodoc/postproc_spec.rb

Large diffs are not rendered by default.

9 changes: 3 additions & 6 deletions spec/isodoc/section_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1104,9 +1104,6 @@
<p class="MsoNormal">
<br clear="all" class="section"/>
</p>
<p class="MsoNormal">
<br clear="all" class="section"/>
</p>
<br clear="all" style="page-break-before:always;mso-break-type:section-break"/>
<div class="WordSection3">
<h1>Index</h1>
Expand Down Expand Up @@ -1167,9 +1164,9 @@
word = File.read("test.doc", encoding: "UTF-8")
.sub(/^.*<body /m, "<body ").sub(%r{</body>.*$}m, "</body>")
wordxml = Nokogiri::XML(word)
wordxml.at("//div[@class = 'WordSection1']").remove
wordxml.at("//div[@class = 'WordSection2']").remove
wordxml.at("//div[@class = 'WordSection3']").remove
wordxml.xpath("//div[@class = 'WordSection1' or @class = 'WordSection2']")
.each(&:remove)
wordxml.at("//div[@class = 'WordSection3']")&.remove
expect(xmlpp(wordxml.to_xml))
.to be_equivalent_to xmlpp(doc)
end
Expand Down
68 changes: 66 additions & 2 deletions spec/metanorma/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1988,9 +1988,73 @@
</presentation-metadata>
</metanorma-extension>
OUTPUT
expect(xmlpp(strip_guid(Nokogiri::XML(Asciidoctor.convert(input,
*OPTIONS))
expect(xmlpp(strip_guid(Nokogiri::XML(Asciidoctor
.convert(input, *OPTIONS))
.at("//xmlns:metanorma-extension").to_xml)))
.to be_equivalent_to xmlpp(output)

input.sub!(":document-scheme: DOCUMENT-SCHEME",
":copyright-year: 1960")
output.sub!("DOCUMENT-SCHEME", "1951")
expect(xmlpp(strip_guid(Nokogiri::XML(Asciidoctor
.convert(input, *OPTIONS))
.at("//xmlns:metanorma-extension").to_xml)))
.to be_equivalent_to xmlpp(output)

input.sub!(":copyright-year: 1960", ":copyright-year: 1973")
output.sub!("<value>1951</value>", "<value>1972</value>")
expect(xmlpp(strip_guid(Nokogiri::XML(Asciidoctor
.convert(input, *OPTIONS))
.at("//xmlns:metanorma-extension").to_xml)))
.to be_equivalent_to xmlpp(output)

input.sub!(":copyright-year: 1973", ":copyright-year: 1980")
output.sub!("<value>1972</value>", "<value>1979</value>")
expect(xmlpp(strip_guid(Nokogiri::XML(Asciidoctor
.convert(input, *OPTIONS))
.at("//xmlns:metanorma-extension").to_xml)))
.to be_equivalent_to xmlpp(output)

input.sub!(":copyright-year: 1980", ":copyright-year: 1988")
output.sub!("<value>1979</value>", "<value>1987</value>")
expect(xmlpp(strip_guid(Nokogiri::XML(Asciidoctor
.convert(input, *OPTIONS))
.at("//xmlns:metanorma-extension").to_xml)))
.to be_equivalent_to xmlpp(output)

input.sub!(":copyright-year: 1988", ":copyright-year: 1990")
output.sub!("<value>1987</value>", "<value>1989</value>")
expect(xmlpp(strip_guid(Nokogiri::XML(Asciidoctor
.convert(input, *OPTIONS))
.at("//xmlns:metanorma-extension").to_xml)))
.to be_equivalent_to xmlpp(output)

input.sub!(":copyright-year: 1990", ":copyright-year: 2012")
output.sub!("<value>1989</value>", "<value>2012</value>")
expect(xmlpp(strip_guid(Nokogiri::XML(Asciidoctor
.convert(input, *OPTIONS))
.at("//xmlns:metanorma-extension").to_xml)))
.to be_equivalent_to xmlpp(output)

input.sub!(":copyright-year: 2012", ":copyright-year: 2014")
output.sub!("<value>2012</value>", "<value>2013</value>")
expect(xmlpp(strip_guid(Nokogiri::XML(Asciidoctor
.convert(input, *OPTIONS))
.at("//xmlns:metanorma-extension").to_xml)))
.to be_equivalent_to xmlpp(output)

input.sub!(":copyright-year: 2014", ":copyright-year: 2025")
output.sub!("<value>2013</value>", "<value>2024</value>")
expect(xmlpp(strip_guid(Nokogiri::XML(Asciidoctor
.convert(input, *OPTIONS))
.at("//xmlns:metanorma-extension").to_xml)))
.to be_equivalent_to xmlpp(output)

input.sub!(":copyright-year: 2014", "")
expect(xmlpp(strip_guid(Nokogiri::XML(Asciidoctor
.convert(input, *OPTIONS))
.at("//xmlns:metanorma-extension").to_xml)))
.to be_equivalent_to xmlpp(output)

end
end
3 changes: 1 addition & 2 deletions spec/metanorma/section_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require "spec_helper"

RSpec.describe Metanorma::ISO do
=begin
it "processes sections" do
input = <<~INPUT
#{ASCIIDOC_BLANK_HDR}
Expand Down Expand Up @@ -244,7 +243,7 @@
expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
.to be_equivalent_to xmlpp(output)
end
=end

it "processes terms & definitions with external source" do
input = <<~INPUT
#{ASCIIDOC_BLANK_HDR}
Expand Down
Loading

0 comments on commit 6aae21b

Please sign in to comment.