Skip to content
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

Participants table: https://github.com/metanorma/mn-samples-jis/issue… #198

Merged
merged 5 commits into from
Jul 29, 2024
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.devel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gem "isodoc", git: "https://github.com/metanorma/isodoc", branch: "fix/publisher-multilingual"
3 changes: 3 additions & 0 deletions lib/isodoc/jis/i18n-en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ commentary_page: Comm.
JIS: 日本工業規格
permission_footer: Duplication, reprinting, etc. without permission is prohibited by copyright law.
chairperson: chairperson
membership_table: Membership Table
full_name: Full Name
affiliation: Affiliation
doctype_dict:
international-standard: International standard
japanese-industrial-standard: International standard
Expand Down
3 changes: 3 additions & 0 deletions lib/isodoc/jis/i18n-ja.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ JIS: 日本工業規格
draft_label: 案
white-paper: 白紙
chairperson: 委員会長
membership_table: 構成表
full_name: 氏名
affiliation: 所属
doctype_dict:
international-standard: 日本産業規格
japanese-industrial-standard: 日本産業規格
Expand Down
17 changes: 10 additions & 7 deletions lib/isodoc/jis/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,23 @@ def agency(xml)
investigative_committee(xml)
end

def extract_role(role, desc)
<<~XPATH
//bibdata/contributor[xmlns:role/@type = '#{role}'][xmlns:role/description = '#{desc}' or xmlns:role/description = '#{desc.downcase}']
XPATH
end

def investigative_organisation(xml)
xpath = "//bibdata/contributor" \
"[xmlns:role/@type = 'authorizer'][xmlns:role/description = " \
"'investigative organization']/organization/name"
org = xml.at(ns(xpath))
p = extract_role("authorizer", "Investigative organization")
org = xml.at(ns("#{p}/organization/name[@language = '#{@lang}']"))
org ||= xml.at(ns("#{p}/organization/name"))
if org then set_encoded(:"investigative-organization", org)
else set(:"investigative-organization", get[:publisher])
end
end

def investigative_committee(xml)
xpath = "//bibdata/contributor" \
"[xmlns:role/@type = 'authorizer'][xmlns:role/description = " \
"'investigative committee']"
xpath = extract_role("authorizer", "Investigative committee")
if o = xml.at(ns("#{xpath}/organization/name"))
set_encoded(:"investigative-committee", o)
elsif p = xml.at(ns("#{xpath}/person"))
Expand Down
50 changes: 47 additions & 3 deletions lib/isodoc/jis/presentation_section.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,22 @@ def commentary_title_hdr(elem)
elem.previous = ret
end

def toc_title_insert_pt(docxml)
ins = docxml.at(ns("//preface")) ||
def make_preface(docxml)
docxml.at(ns("//preface")) ||
docxml.at(ns("//sections | //annex | //bibliography"))
&.before("<preface> </preface>")
&.previous_element or return nil
&.previous_element
end

def toc_title_insert_pt(docxml)
ins = make_preface(docxml) or return nil
ins.children.last.after(" ").next
end

def preface_rearrange(doc)
move_introduction(doc)
super
move_participants(doc)
end

def move_introduction(doc)
Expand All @@ -63,6 +68,45 @@ def move_introduction(doc)
dest.children.first.next = source
end

def move_participants(doc)
p = doc.at(ns("//clause[@type = 'participants']")) or return
t = participant_table(p) or return
p.remove
ins = make_preface(doc) or return nil
ins.children.first.previous = t
end

def participant_table(clause)
s = clause.at(ns("./sourcecode")) or return nil
y = YAML.safe_load(s.children.to_xml(encoding: "UTF-8")) or return nil
y.is_a?(Array) or return nil
out1 = <<~OUTPUT
<clause id='_#{UUIDTools::UUID.random_create}'><title>#{@meta.get[:"investigative-committee"]} #{@i18n.membership_table}</title>
<table unnumbered='true'>
<thead>
<tr><th/><th>#{@i18n.full_name}</th><th>#{@i18n.affiliation}</th></tr>
</thead>
<tbody>
OUTPUT
out2 = <<~OUTPUT
</tbody></table></clause>
OUTPUT
"#{out1}#{participant_rows(y)}#{out2}"
end

def participant_rows(yaml)
yaml.map do |y|
r = y["role"] ? @i18n.l10n("(#{y['role']})") : ""
n = y["name"]
if n.is_a?(Hash)
n =
if @lang == "ja" then "#{n['surname']} #{n['givenname']}"
else "#{n['givenname']} #{n['surname']}" end
end
"<tr><td>#{r}</rd><td>#{n}</td><td>#{y['affiliation']}</td></tr>"
end.join("\n")
end

def middle_title(docxml)
s = docxml.at(ns("//sections")) or return
elem = s.children.first
Expand Down
6 changes: 3 additions & 3 deletions lib/metanorma/jis/front.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ def extract_org_attrs_address(node, opts, suffix)

def multiling_noko_value(value, tag, xml)
if value.is_a?(Hash)
xml.send tag do |t|
value.each do |k, v|
t.variant v, language: k
value.each do |k, v|
xml.send tag, language: k do |x|
x << v
end
end
elsif value.is_a?(Array)
Expand Down
12 changes: 5 additions & 7 deletions spec/isodoc/metadata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,13 @@
<description>Investigative organization</description>
</role>
<organization>
<name>
<variant language="ja">日本産業標準調査会</variant>
<variant language="en">Japanese Industrial Standards Committee</variant>
</name>
<name language="ja">日本産業標準調査会</name>
<name language="en">Japanese Industrial Standards Committee</name>
</organization>
</contributor>
<contributor>
<role type="authorizer">
<description>investigative committee</description>
<description>Investigative committee</description>
</role>
<person>
<name>
Expand All @@ -62,7 +60,7 @@
</contributor>
<contributor>
<role type="authorizer">
<description>investigative committee</description>
<description>Investigative committee</description>
</role>
<person>
<name>
Expand Down Expand Up @@ -155,7 +153,7 @@
:"investigative-committee"=>"Committee 123",
:"investigative-committee-representative-name"=>"KUROSAWA Akira",
:"investigative-committee-representative-role"=>"chairperson",
:"investigative-organization"=>"Japanese Industrial Standards",
:"investigative-organization"=>"Japanese Industrial Standards Committee",
:lang=>"en",
:publisher=>"Japanese Industrial Standards",
:revdate=>"2000-01-01",
Expand Down
Loading
Loading