-
Notifications
You must be signed in to change notification settings - Fork 4
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
Fix/table capitalisation #498
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
require_relative "init" | ||
require "roman-numerals" | ||
require "isodoc" | ||
require_relative "../../relaton/render/general" | ||
require_relative "presentation_bibdata" | ||
require_relative "presentation_preface" | ||
|
||
module IsoDoc | ||
module ITU | ||
class PresentationXMLConvert < IsoDoc::PresentationXMLConvert | ||
def bibrenderer | ||
::Relaton::Render::ITU::General.new(language: @lang) | ||
end | ||
|
||
def bibrender_formattedref(formattedref, _xml) | ||
formattedref << "." unless /\.$/.match?(formattedref.text) | ||
id = reference_format_start(formattedref.parent) and | ||
formattedref.children.first.previous = id | ||
end | ||
|
||
def bibrender_relaton(xml, renderings) | ||
f = renderings[xml["id"]][:formattedref] | ||
ids = reference_format_start(xml) | ||
f &&= "<formattedref>#{ids}#{f}</formattedref>" | ||
# retain date in order to generate reference tag | ||
keep = "./docidentifier | ./uri | ./note | ./date | ./biblio-tag" | ||
xml.children = "#{f}#{xml.xpath(ns(keep)).to_xml}" | ||
end | ||
|
||
def multi_bibitem_ref_code(bib) | ||
skip = IsoDoc::Function::References::SKIP_DOCID | ||
skip1 = "@type = 'metanorma' or @type = 'metanorma-ordinal'" | ||
prim = "[@primary = 'true']" | ||
id = bib.xpath(ns("./docidentifier#{prim}[not(#{skip} or #{skip1})]")) | ||
id.empty? and id = bib.xpath(ns("./docidentifier#{prim}[not(#{skip1})]")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [81/80] |
||
id.empty? and id = bib.xpath(ns("./docidentifier[not(#{skip} or #{skip1})]")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [85/80] |
||
id.empty? and id = bib.xpath(ns("./docidentifier[not(#{skip1})]")) | ||
id.empty? and return id | ||
id.sort_by { |i| i["type"] == "ITU" ? 0 : 1 } | ||
end | ||
|
||
def render_multi_identifiers(ids) | ||
ids.map do |id| | ||
if id["type"] == "ITU" then doctype_title(id) | ||
else | ||
docid_prefix(id["type"], id.text.sub(/^\[/, "").sub(/\]$/, "")) | ||
end | ||
end.join(" | ") | ||
end | ||
|
||
def reference_format_start(bib) | ||
id = multi_bibitem_ref_code(bib) | ||
id1 = render_multi_identifiers(id) | ||
out = id1 | ||
date = bib.at(ns("./date[@type = 'published']/on | " \ | ||
"./date[@type = 'published']/from")) and | ||
out << " (#{date.text.sub(/-.*$/, '')})" | ||
out += ", " if date || !id1.empty? | ||
out | ||
end | ||
|
||
def bibliography_bibitem_number1(bib, idx) | ||
mn = bib.at(ns(".//docidentifier[@type = 'metanorma']")) and | ||
/^\[?\d+\]?$/.match?(mn.text) and | ||
mn["type"] = "metanorma-ordinal" | ||
if (mn = bib.at(ns(".//docidentifier[@type = 'metanorma-ordinal']"))) && | ||
!bibliography_bibitem_number_skip(bib) | ||
idx += 1 | ||
mn.children = "[#{idx}]" | ||
end | ||
idx | ||
end | ||
|
||
def bibliography_bibitem_number_skip(bibitem) | ||
@xrefs.klass.implicit_reference(bibitem) || | ||
bibitem["hidden"] == "true" || bibitem.parent["hidden"] == "true" | ||
end | ||
|
||
def norm_ref_entry_code(_ordinal, idents, _ids, _standard, datefn, _bib) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid parameter lists longer than 5 parameters. [6/5] |
||
ret = (idents[:metanorma] || idents[:ordinal] || idents[:sdo]).to_s | ||
/^\[.+\]$/.match?(ret) or ret = "[#{ret}]" | ||
ret += datefn | ||
ret.empty? and return ret | ||
ret.gsub("-", "‑").gsub(/ /, " ") | ||
end | ||
|
||
def biblio_ref_entry_code(_ordinal, idents, _id, _standard, datefn, _bib) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid parameter lists longer than 5 parameters. [6/5] |
||
ret = (idents[:metanorma] || idents[:ordinal] || idents[:sdo]).to_s | ||
/^\[.+\]$/.match?(ret) or ret = "[#{ret}]" | ||
ret += datefn | ||
ret.empty? and return ret | ||
ret.gsub("-", "‑").gsub(/ /, " ") | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,18 @@ | |
require_relative "../../relaton/render/general" | ||
require_relative "presentation_bibdata" | ||
require_relative "presentation_preface" | ||
require_relative "presentation_ref" | ||
|
||
module Nokogiri | ||
module XML | ||
class Node | ||
def traverse_topdown(&block) | ||
yield(self) | ||
children.each { |j| j.traverse_topdown(&block) } | ||
end | ||
end | ||
end | ||
end | ||
|
||
module IsoDoc | ||
module ITU | ||
|
@@ -39,6 +51,25 @@ def note1(elem) | |
super | ||
end | ||
|
||
def table1(elem) | ||
elem.xpath(ns("./name | ./thead/tr/th")).each do |n| | ||
capitalise_unless_text_transform(n) | ||
end | ||
super | ||
end | ||
|
||
def capitalise_unless_text_transform(elem) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cyclomatic complexity for capitalise_unless_text_transform is too high. [7/6] |
||
css = nil | ||
elem.traverse_topdown do |n| | ||
n.name == "span" && /text-transform:/.match?(n["style"]) and | ||
css = n | ||
n.text? && /\S/.match?(n.text) or next | ||
css && n.ancestors.include?(css) or | ||
n.replace(::Metanorma::Utils.strict_capitalize_first(n.text)) | ||
break | ||
end | ||
end | ||
|
||
def get_eref_linkend(node) | ||
non_locality_elems(node).select do |c| | ||
!c.text? || /\S/.match(c) | ||
|
@@ -52,57 +83,6 @@ def get_eref_linkend(node) | |
node.add_child(link) | ||
end | ||
|
||
def bibrenderer | ||
::Relaton::Render::ITU::General.new(language: @lang) | ||
end | ||
|
||
def bibrender_formattedref(formattedref, _xml) | ||
formattedref << "." unless /\.$/.match?(formattedref.text) | ||
id = reference_format_start(formattedref.parent) and | ||
formattedref.children.first.previous = id | ||
end | ||
|
||
def bibrender_relaton(xml, renderings) | ||
f = renderings[xml["id"]][:formattedref] | ||
ids = reference_format_start(xml) | ||
f &&= "<formattedref>#{ids}#{f}</formattedref>" | ||
# retain date in order to generate reference tag | ||
keep = "./docidentifier | ./uri | ./note | ./date | ./biblio-tag" | ||
xml.children = "#{f}#{xml.xpath(ns(keep)).to_xml}" | ||
end | ||
|
||
def multi_bibitem_ref_code(bib) | ||
skip = IsoDoc::Function::References::SKIP_DOCID | ||
skip1 = "@type = 'metanorma' or @type = 'metanorma-ordinal'" | ||
prim = "[@primary = 'true']" | ||
id = bib.xpath(ns("./docidentifier#{prim}[not(#{skip} or #{skip1})]")) | ||
id.empty? and id = bib.xpath(ns("./docidentifier#{prim}[not(#{skip1})]")) | ||
id.empty? and id = bib.xpath(ns("./docidentifier[not(#{skip} or #{skip1})]")) | ||
id.empty? and id = bib.xpath(ns("./docidentifier[not(#{skip1})]")) | ||
id.empty? and return id | ||
id.sort_by { |i| i["type"] == "ITU" ? 0 : 1 } | ||
end | ||
|
||
def render_multi_identifiers(ids) | ||
ids.map do |id| | ||
if id["type"] == "ITU" then doctype_title(id) | ||
else | ||
docid_prefix(id["type"], id.text.sub(/^\[/, "").sub(/\]$/, "")) | ||
end | ||
end.join(" | ") | ||
end | ||
|
||
def reference_format_start(bib) | ||
id = multi_bibitem_ref_code(bib) | ||
id1 = render_multi_identifiers(id) | ||
out = id1 | ||
date = bib.at(ns("./date[@type = 'published']/on | " \ | ||
"./date[@type = 'published']/from")) and | ||
out << " (#{date.text.sub(/-.*$/, '')})" | ||
out += ", " if date || !id1.empty? | ||
out | ||
end | ||
|
||
def titlecase(str) | ||
str.gsub(/ |_|-/, " ").split(/ /).map(&:capitalize).join(" ") | ||
end | ||
|
@@ -165,39 +145,6 @@ def info(isoxml, out) | |
super | ||
end | ||
|
||
def bibliography_bibitem_number1(bib, idx) | ||
mn = bib.at(ns(".//docidentifier[@type = 'metanorma']")) and | ||
/^\[?\d+\]?$/.match?(mn.text) and | ||
mn["type"] = "metanorma-ordinal" | ||
if (mn = bib.at(ns(".//docidentifier[@type = 'metanorma-ordinal']"))) && | ||
!bibliography_bibitem_number_skip(bib) | ||
idx += 1 | ||
mn.children = "[#{idx}]" | ||
end | ||
idx | ||
end | ||
|
||
def bibliography_bibitem_number_skip(bibitem) | ||
@xrefs.klass.implicit_reference(bibitem) || | ||
bibitem["hidden"] == "true" || bibitem.parent["hidden"] == "true" | ||
end | ||
|
||
def norm_ref_entry_code(_ordinal, idents, _ids, _standard, datefn, _bib) | ||
ret = (idents[:metanorma] || idents[:ordinal] || idents[:sdo]).to_s | ||
/^\[.+\]$/.match?(ret) or ret = "[#{ret}]" | ||
ret += datefn | ||
ret.empty? and return ret | ||
ret.gsub("-", "‑").gsub(/ /, " ") | ||
end | ||
|
||
def biblio_ref_entry_code(_ordinal, idents, _id, _standard, datefn, _bib) | ||
ret = (idents[:metanorma] || idents[:ordinal] || idents[:sdo]).to_s | ||
/^\[.+\]$/.match?(ret) or ret = "[#{ret}]" | ||
ret += datefn | ||
ret.empty? and return ret | ||
ret.gsub("-", "‑").gsub(/ /, " ") | ||
end | ||
|
||
def toc_title(docxml) | ||
@doctype == "resolution" and return | ||
super | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assignment Branch Condition size for multi_bibitem_ref_code is too high. [<8, 14, 7> 17.58/15]
Cyclomatic complexity for multi_bibitem_ref_code is too high. [7/6]