Skip to content

Commit

Permalink
Boilerplate: #15
Browse files Browse the repository at this point in the history
  • Loading branch information
opoudjis committed Dec 17, 2023
1 parent 26f7d2b commit 1fc9b3c
Show file tree
Hide file tree
Showing 15 changed files with 485 additions and 77 deletions.
2 changes: 2 additions & 0 deletions Gemfile.devel
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
gem "metanorma-standoc", git: "https://github.com/metanorma/metanorma-standoc", branch: "main"
gem "isodoc", git: "https://github.com/metanorma/isodoc", branch: "main"
2 changes: 2 additions & 0 deletions lib/isodoc/jis/i18n-en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ commentary: Commentary
commentary_page: Comm.
JIS: 日本工業規格
permission_footer: Duplication, reprinting, etc. without permission is prohibited by copyright law.
chairperson: chairperson
doctype_dict:
international-standard: International standard
japanese-industrial-standard: International standard
technical-specification: Technical specification
technical-report: Technical report
publicly-available-specification: Publicly Available Specification
Expand Down
5 changes: 3 additions & 2 deletions lib/isodoc/jis/i18n-ja.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ cancelled_and_replaced: キャンセルされ、%に置き換えられました
norm_with_refs_pref_all_dated: 次に掲げる引用規格は,この規格に引用されることによって,その一部又は全部がこの規格の要 求事項を構成している。これらの引用規格は,記載の年の版を適用し,その後の改正版(追補を含む。) は適用しない。
norm_with_refs_pref_none_dated: 次に掲げる引用規格は,この規格に引用されることによって,その一部又は全部がこの規格の要求事項 を構成している。これらの引用規格は,その最新版(追補を含む。)を適用する。
permission_footer: 著作権法により無断での複製,転載等は禁止されております。
admitted: "代替用語"
admitted: 代替用語
table_footnote:
commentary: 解説
commentary_page:
JIS: 日本工業規格
draft_label:
white-paper: 白紙
chairperson: 委員会長
doctype_dict:
international-standard: 日本産業規格
japaanese-industrial-standard: 日本産業規格
japanese-industrial-standard: 日本産業規格
technical-specification: 標準仕様書
technical-report: 標準報告書
publicly-available-specification: Publicly Available Specification
Expand Down
25 changes: 25 additions & 0 deletions lib/isodoc/jis/i18n.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
require "japanese_calendar"
require "twitter_cldr"

module IsoDoc
module JIS
class I18n < IsoDoc::Iso::I18n
Expand All @@ -10,6 +13,28 @@ def load_yaml1(lang, script)
y = load_file("i18n-#{yaml_lang(lang, script)}.yaml")
y.empty? ? load_file("i18n-en.yaml").merge(super) : super.deep_merge(y)
end

# use Japanese ordinals for era years
def japanese_date(date)
date.nil? and return date
d = date.split(/-/).map(&:to_i)
time = Date.new(*d)
yr = japanese_year(time)
case d.size
when 1 then yr
when 2 then yr + time.strftime("%-m月")
when 3 then yr + time.strftime("%-m月%-d日")
else date
end
end

def japanese_year(time)
era_yr = time.era_year.to_i.localize(:ja)
.to_rbnf_s("SpelloutRules", "spellout-numbering-year")
"#{time.strftime('%JN')}#{era_yr}年"
rescue
time.year.to_s
end
end
end
end
94 changes: 71 additions & 23 deletions lib/isodoc/jis/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,42 @@ module IsoDoc
module JIS
class Metadata < IsoDoc::Iso::Metadata
def title(isoxml, _out)
lang = case @lang
when "ja", "en" then @lang
else "ja"
end
# intro, main, part, amd = title_parts(isoxml, lang)
lang = @lang
%w(en ja).include?(lang) or lang = "ja"
tp = title_parts(isoxml, lang)
tn = title_nums(isoxml)

set(:doctitlemain,
@c.encode(tp[:main] ? tp[:main].text : "", :hexadecimal))
set_encoded(:doctitlemain, tp[:main])
main = compose_title(tp, tn, lang)
set(:doctitle, main)
tp[:intro] and
set(:doctitleintro,
@c.encode(tp[:intro] ? tp[:intro].text : "", :hexadecimal))
set_encoded(:doctitleintro, tp[:intro])
set(:doctitlepartlabel, part_prefix(tn, lang))
set(:doctitlepart, @c.encode(tp[:part].text, :hexadecimal)) if tp[:part]
set_encoded(:doctitlepart, tp[:part])
set(:doctitleamdlabel, amd_prefix(tn, lang)) if tn[:amd]
set(:doctitleamd, @c.encode(tp[:amd].text, :hexadecimal)) if tp[:amd]
set_encoded(:doctitleamd, tp[:amd])
set(:doctitlecorrlabel, corr_prefix(tn, lang)) if tn[:corr]
end

def subtitle(isoxml, _out)
lang = @lang == "ja" ? "en" : "ja"
tp = title_parts(isoxml, lang)
tn = title_nums(isoxml)

set(:docsubtitlemain,
@c.encode(tp[:main] ? tp[:main].text : "", :hexadecimal))
set_encoded(:docsubtitlemain, tp[:main])
main = compose_title(tp, tn, lang)
set(:docsubtitle, main)
tp[:intro] and
set(:docsubtitleintro,
@c.encode(tp[:intro] ? tp[:intro].text : "", :hexadecimal))
set_encoded(:docsubtitleintro, tp[:intro])
set(:docsubtitlepartlabel, part_prefix(tn, lang))
tp[:part] and
set(:docsubtitlepart,
@c.encode(tp[:part].text, :hexadecimal))
set_encoded(:docsubtitlepart, tp[:part])
set(:docsubtitleamdlabel, amd_prefix(tn, lang)) if tn[:amd]
set(:docsubtitleamd, @c.encode(tp[:amd].text, :hexadecimal)) if tp[:amd]
set_encoded(:docsubtitleamd, tp[:amd])
set(:docsubtitlecorrlabel, corr_prefix(tn, lang)) if tn[:corr]
end

def set_encoded(name, field)
field or return
field.respond_to?(:text) and field = field.text
set(name, @c.encode(field, :hexadecimal))
end

PART_LABEL = { en: "Part", ja: "その" }.freeze

def docid(isoxml, _out)
Expand All @@ -56,6 +49,61 @@ def docid(isoxml, _out)
set(:docnumber, id)
set(:docnumber_undated, id.sub(/:\d{4}$/, ""))
end

def bibdate(isoxml, _out)
isoxml.xpath(ns("//bibdata/date")).each do |d|
val = Common::date_range(d)
@lang == "ja" and val = @i18n.japanese_date(val)
set("#{d['type'].gsub(/-/, '_')}date".to_sym, val)
end
end

def version(isoxml, out)
super
@lang == "ja" or return
revdate = @i18n.japanese_date(isoxml
.at(ns("//bibdata/version/revision-date"))&.text)
set(:revdate, revdate)
set(:draftinfo, draftinfo(get[:draft], revdate))
end

def agency(xml)
super
investigative_organisation(xml)
investigative_committee(xml)
end

def investigative_organisation(xml)
xpath = "//bibdata/contributor" \
"[xmlns:role/@type = 'authorizer'][xmlns:role/description = " \
"'investigative organization']/organization/name"
org = xml.at(ns(xpath))
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']"
if o = xml.at(ns("#{xpath}/organization/name"))
set_encoded(:"investigative-committee", o)
elsif p = xml.at(ns("#{xpath}/person"))
investigative_committee_person(p)
end
end

def investigative_committee_person(person)
n = extract_person_names([person])
pos = person.at(ns("./affiliation/name")) || @i18n.chairperson
org = person.at(ns("./affiliation/organization/name"))
set_encoded(:"investigative-committee", org)
unless n.empty?
set_encoded(:"investigative-committee-representative-role", pos)
set(:"investigative-committee-representative-name", n.first)
end
end
end
end
end
23 changes: 1 addition & 22 deletions lib/isodoc/jis/presentation_xml_convert.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
require_relative "init"
require "isodoc"
require_relative "presentation_section"
require "japanese_calendar"
require "twitter_cldr"

module IsoDoc
module JIS
Expand Down Expand Up @@ -151,29 +149,10 @@ def bibdata_i18n(bibdata)

def date_translate(bibdata)
bibdata.xpath(ns("./date")).each do |d|
d.children = japanese_date(d.text.strip)
d.children = @i18n.japanese_date(d.text.strip)
end
end

# use Japanese ordinals for era years
def japanese_date(date)
d = date.split(/-/).map(&:to_i)
time = Date.new(*d)
yr = japanese_year(time)
case d.size
when 1 then yr
when 2 then yr + time.strftime("%-m月")
when 3 then yr + time.strftime("%-m月%-d日")
else date
end
end

def japanese_year(time)
era_yr = time.era_year.to_i.localize(:ja)
.to_rbnf_s("SpelloutRules", "spellout-numbering-year")
"#{time.strftime('%JN')}#{era_yr}年"
end

include Init
end
end
Expand Down
12 changes: 12 additions & 0 deletions lib/metanorma/jis/boilerplate-en.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
== copyright-statement

Competent Minister: Minister of Economy, Trade and Industry Established: October 31, 1951 Revised: {{ revdate }}
Date of publication in the Official Gazette: {{ announceddate }}
Draft creator: Japanese Standards Association
(Mita MT Building, 3-13-12 Mita, Minato-ku, Tokyo 108-0073 Tel: 03-4231-8530)
Investigative Working Group: {{ investigative-organization }} {{ investigative-committee }}
{% if investigative-committee-representative-name %}({{ investigative-committee-representative-role | capitalize }}: {{ investigative-committee-representative-name }}){% endif %}

== feedback-statement

Any comments or questions regarding this standard should be directed to the above drafter or the International Standardization Division, Industrial Science and Technology Policy and Environment Bureau, Ministry of Economy, Trade and Industry (Tokyo 100-8901 Tokyo, Japan). Please contact 1-3-1 Kasumigaseki, Chiyoda-ku, Tokyo. In accordance with the provisions of the Industrial Standardization Law, Japanese Industrial Standards shall be reviewed by the Japan Industrial Standards Committee by the date when at least five years have passed. It will be put up for discussion and promptly confirmed, amended or repealed.
18 changes: 18 additions & 0 deletions lib/metanorma/jis/boilerplate-ja.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
== copyright-statement

主 務 大 臣:経済産業大臣 制定:昭和 26.10.31 改正:{{ revdate }}

官 報 掲 載 日:{{ announceddate }}

原 案 作 成 者:一般財団法人日本規格協会

(〒108-0073 東京都港区三田 3-13-12 三田 MT ビル TEL 03-4231-8530)

審 議 部 会:{{ investigative-organization }}{{ investigative-committee }}{% if investigative-committee-representative-name %}({{ investigative-committee-representative-role }} {{ investigative-committee-representative-name }}){% endif %}

== feedback-statement


この規格についての意見又は質問は,上記原案作成者又は経済産業省産業技術環境局 国際標準課(〒100-8901 東京 都千代田区霞が関 1-3-1)にご連絡ください。

なお,日本産業規格は,産業標準化法の規定によって,少なくとも 5 年を経過する日までに日本産業標準調査会の審 議に付され,速やかに,確認,改正又は廃止されます。
16 changes: 16 additions & 0 deletions lib/metanorma/jis/cleanup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ def clean_example_keep_separate(xmldoc)
n.delete("keep-separate")
end
end

def bibdata_cleanup(xmldoc)
super
bibdata_supply_chairperson_role(xmldoc)
end

def bibdata_supply_chairperson_role(xmldoc)
xpath =
"//bibdata/contributor" \
"[role/@type = 'authorizer'][role/description = " \
"'investigative committee']/person/affiliation"
xmldoc.xpath(xpath).each do |a|
a.at("./name") or next
a.children.first.previous = "<name>#{@i18n.chairperson}</name>"
end
end
end
end
end
8 changes: 4 additions & 4 deletions lib/metanorma/jis/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ def doctype(node)
ret
end

def boilerplate_file(_x_orig)
File.join(@libdir, "jis_intro_jp.xml")
end

def section_attributes(node)
ret = super
if node.attr("style") == "appendix" && node.level == 1 &&
Expand All @@ -44,6 +40,10 @@ def example_attrs(node)
.merge("keep-separate": node.attr("keep-separate")))
end

def boilerplate_file(_x_orig)
File.join(@libdir, "boilerplate-#{@lang}.adoc")
end

def html_converter(node)
if node.nil?
IsoDoc::JIS::HtmlConvert.new({})
Expand Down
3 changes: 1 addition & 2 deletions lib/metanorma/jis/front.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ def metadata_author(node, xml)
org_contributor(node, xml,
{ source: ["publisher", "pub"], role: "author",
default: JIS_HASH })
node.attr("doctype") == "expert-commentary" and
personal_author(node, xml)
personal_author(node, xml)
end

def metadata_publisher(node, xml)
Expand Down
44 changes: 44 additions & 0 deletions spec/isodoc/metadata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,49 @@
<abbreviation>JIS</abbreviation>
</organization>
</contributor>
<contributor>
<role type="authorizer">
<description>Investigative organization</description>
</role>
<organization>
<name>
<variant language="ja">日本産業標準調査会</variant>
<variant language="en">Japanese Industrial Standards Committee</variant>
</name>
</organization>
</contributor>
<contributor>
<role type="authorizer">
<description>investigative committee</description>
</role>
<person>
<name>
<completename>KUROSAWA Akira</completename>
</name>
<affiliation>
<organization>
<name>Committee 123</name>
</organization>
</affiliation>
</person>
</contributor>
<contributor>
<role type="authorizer">
<description>investigative committee</description>
</role>
<person>
<name>
<completename>MIFUNE Toshiro</completename>
</name>
<affiliation>
<name>委員会長</name>
<name>lead actor</name>
<organization>
<name>Committee 123</name>
</organization>
</affiliation>
</person>
</contributor>
<edition>2</edition>
<version>
<revision-date>2000-01-01</revision-date>
Expand Down Expand Up @@ -109,6 +152,7 @@
:draftinfo=>" (draft 0.3.4, 2000-01-01)",
:edition=>"2",
:horizontal=>"true",
:investigative-organization=>"",
:lang=>"en",
:publisher=>"Japanese Industrial Standards",
:revdate=>"2000-01-01",
Expand Down
Loading

0 comments on commit 1fc9b3c

Please sign in to comment.