Skip to content

Commit

Permalink
Merge pull request #850 from metanorma/features/metanorma-extension-c…
Browse files Browse the repository at this point in the history
…ontributors

contributor metadata in metanorma extensions: https://github.com/meta…
  • Loading branch information
opoudjis authored Dec 28, 2023
2 parents 7eff1b6 + 5a502dc commit 1639fd7
Show file tree
Hide file tree
Showing 13 changed files with 3,008 additions and 2,576 deletions.
12 changes: 5 additions & 7 deletions lib/metanorma/standoc/base.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
require "date"
require "nokogiri"
require "htmlentities"
require "json"
require "pathname"
require "isodoc"
require "relaton"
require "fileutils"
require "metanorma-utils"
require "isodoc/xslfo_convert"
require_relative "render"
require_relative "localbib"
require "mn-requirements"
Expand Down Expand Up @@ -80,8 +78,8 @@ def init_processing(node)
end

def init_reqt(node)
@default_requirement_model = (node.attr("requirements-model") ||
default_requirement_model)
@default_requirement_model = node.attr("requirements-model") ||
default_requirement_model
@reqt_models = requirements_processor
.new({ default: @default_requirement_model })
end
Expand Down Expand Up @@ -117,9 +115,9 @@ def init_output(node)
end

def init_i18n(node)
@lang = (node.attr("language") || "en")
@script = (node.attr("script") ||
Metanorma::Utils.default_script(node.attr("language")))
@lang = node.attr("language") || "en"
@script = node.attr("script") ||
Metanorma::Utils.default_script(node.attr("language"))
@locale = node.attr("locale")
@isodoc = isodoc(@lang, @script, @locale, node.attr("i18nyaml"))
@i18n = @isodoc.i18n
Expand Down
1 change: 1 addition & 0 deletions lib/metanorma/standoc/cleanup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def cleanup(xmldoc)
mathml_cleanup(xmldoc)
script_cleanup(xmldoc)
docidentifier_cleanup(xmldoc) # feeds: bibdata_cleanup
ext_contributor_cleanup(xmldoc) # feeds: bibdata_cleanup
bibdata_cleanup(xmldoc)
svgmap_cleanup(xmldoc) # feeds: img_cleanup
boilerplate_cleanup(xmldoc)
Expand Down
110 changes: 110 additions & 0 deletions lib/metanorma/standoc/cleanup_bibdata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,116 @@ def bibdata_embed_id_cleanup(xmldoc)
.each { |x| x << ident.text }
end
end

def ext_contributor_cleanup(xmldoc)
t = xmldoc.xpath("//metanorma-extension/clause/title").detect do |x|
x.text.strip.casecmp("contributor metadata").zero?
end or return
a = t.at("../sourcecode") or return
ins = xmldoc.at("//bibdata/contributor[last()]")
ext_contributors_process(YAML.safe_load(a.text), ins)
end

def ext_contributors_process(yaml, ins)
yaml.is_a?(Hash) and yaml = [yaml]
yaml.reverse.each { |y| ext_contributor_process(y, ins) }
end

def ext_contributor_process(yaml, ins)
ret = ext_contributor_role(yaml)
ret += ext_contributor_name(yaml)
ret += ext_contributor_credentials(yaml)
ret += ext_contributor_affiliations(yaml)
ret += ext_contributor_contact(yaml)
ins.next = "<contributor>#{ret}</contributor>"
end

def extract(key, tag, yaml)
a = yaml[key] and return "<#{tag}>#{a}</#{tag}>"
""
end

def ext_contributor_role(yaml)
a = yaml["role"] || "author"
"<role type='#{a}'>#{yaml['description']}</role>"
end

def ext_contributor_name(yaml)
ret = extract("fullname", "completename", yaml)
if ret.empty?
ret = extract("givenname", "forename", yaml)
ret += extract("initials", "initial", yaml)
ret += extract("surname", "surname", yaml)
end
"<name>#{ret}</name>"
end

def ext_contributor_credentials(yaml)
extract("contributor-credentials", "credentials", yaml)
end

def ext_contributor_affiliations(yaml)
x = yaml["affiliations"] or return ""
x.is_a?(Hash) and x = [x]
x.map do |a|
ext_contributor_affiliation(a)
end.join("\n")
end

def ext_contributor_affiliation(yaml)
ret = extract("contributor-position", "name", yaml)
ret += ext_contributor_org(yaml)
ret.empty? and return ""
"<affiliation>#{ret}</affiliation>"
end

def ext_contributor_org(yaml)
ret = extract("affiliation", "name", yaml)
ret += extract("affiliation_abbrev", "abbreviation", yaml)
ret += extract("affiliation_subdiv", "subdivision", yaml)
ret += ext_contributor_contact(yaml)
ret += ext_contributor_logo(yaml)
ret.empty? and return ""
"<organization>#{ret}</organization>"
end

def ext_contributor_contact(yaml)
ret = ext_contributor_address(yaml)
ret += ext_contributor_phone(yaml)
ret += ext_contributor_email(yaml)
ret += ext_contributor_uri(yaml)
ret
end

def ext_contributor_address(yaml)
ret = extract("address", "formattedAddress", yaml)
if ret.empty?
%w(street city state country postcode).each do |k|
ret += extract(k, k, yaml)
end
end
ret.empty? and return ""
"<address>#{ret}</address>"
end

def ext_contributor_phone(yaml)
ret = extract("phone", "phone", yaml)
a = yaml["fax"] and ret += "<phone type='fax'>#{a}</phone>"
ret
end

def ext_contributor_email(yaml)
extract("email", "email", yaml)
end

def ext_contributor_uri(yaml)
extract("contributor-uri", "uri", yaml)
end

def ext_contributor_logo(yaml)
a = yaml["affiliation_logo"] or return ""
"<logo><image src='#{a}'/></logo>"
end
end
end
end
4 changes: 4 additions & 0 deletions lib/metanorma/standoc/front_organisation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def org_address(org, xml)
f << p.gsub(/ \+\n/, "<br/>")
end
end
org_contact(org, xml)
end

def org_contact(org, xml)
p = org[:phone] and xml.phone p
p = org[:fax] and xml.phone p, type: "fax"
p = org[:email] and xml.email p
Expand Down
Loading

0 comments on commit 1639fd7

Please sign in to comment.