Class: IsoDoc::Jis::PresentationXMLConvert
- Inherits:
-
Iso::PresentationXMLConvert
- Object
- Iso::PresentationXMLConvert
- IsoDoc::Jis::PresentationXMLConvert
show all
- Includes:
- Init
- Defined in:
- lib/isodoc/jis/presentation_list.rb,
lib/isodoc/jis/presentation_table.rb,
lib/isodoc/jis/presentation_section.rb,
lib/isodoc/jis/presentation_xml_convert.rb
Constant Summary
collapse
- JPAN =
"\\p{Hiragana}\\p{Katakana}\\p{Han}".freeze
- JPAN_BOLD =
"<span style='font-family:\"MS Gothic\"'>".freeze
Instance Method Summary
collapse
-
#admits(elem) ⇒ Object
-
#anchor_linkend(node, linkend) ⇒ Object
if termsource xref has no SDO identifier, cite instead by full reference.
-
#annex(docxml) ⇒ Object
-
#annex1(elem) ⇒ Object
-
#annex_delim(_elem) ⇒ Object
-
#bibdata_i18n(bibdata) ⇒ Object
-
#biblio_ref_entry_code(ordinal, ids, _standard, datefn, bib) ⇒ Object
-
#bracketed_refs_processing(docxml) ⇒ Object
-
#commentary(elem) ⇒ Object
-
#commentary_title_hdr(elem) ⇒ Object
-
#contains_para?(text) ⇒ Boolean
-
#convert1(xml, filename, dir) ⇒ Object
-
#date_translate(bibdata) ⇒ Object
-
#date_translate1(date) ⇒ Object
-
#dl(docxml) ⇒ Object
TODO: move the table/figure key processing to Word, not Presentation XML.
-
#dl_id_insert(node, ret) ⇒ Object
-
#dl_to_para(node) ⇒ Object
-
#dl_to_para_name(node) ⇒ Object
-
#dl_to_para_terms(node) ⇒ Object
-
#dt_dd?(node) ⇒ Boolean
-
#edition_integer?(bibdata) ⇒ Boolean
-
#edition_translate_iso(bibdata) ⇒ Object
-
#figure_fn(elem) ⇒ Object
-
#final_tfoot_cell(node) ⇒ Object
-
#fmt_origin_cite_full?(elem) ⇒ Boolean
-
#fn_body_label(fnote) ⇒ Object
-
#fn_ref_label(fnote) ⇒ Object
-
#full_row(cols, elem, border: false) ⇒ Object
-
#initial_tfoot_cell(node) ⇒ Object
if there is already a full-row cell at the start of tfoot, use that to move content into else create a full-row cell at the start of tfoot.
-
#inline(docxml) ⇒ Object
-
#localized_strings(docxml) ⇒ Object
-
#make_preface(docxml) ⇒ Object
-
#middle_subtitle_main(out, style) ⇒ Object
-
#middle_title(docxml) ⇒ Object
-
#middle_title_hdr(out) ⇒ Object
-
#middle_title_main(out, style) ⇒ Object
-
#middle_title_para(style, intro, main, part) ⇒ Object
-
#move_commentaries_to_end(docxml) ⇒ Object
-
#move_introduction(doc) ⇒ Object
-
#move_participants(doc) ⇒ Object
-
#norm_ref_entry_code(_ordinal, ids, _standard, datefn, bib) ⇒ Object
-
#ol_depth(node) ⇒ Object
-
#omit_docid_prefix(prefix) ⇒ Object
-
#participant_rows(yaml) ⇒ Object
-
#participant_table(clause) ⇒ Object
-
#participant_table_prep(clause) ⇒ Object
-
#preface_rearrange(doc) ⇒ Object
-
#short_style_origin(docxml) ⇒ Object
-
#source1_label(elem, sources, ancestor) ⇒ Object
-
#source_join_delim(_elem) ⇒ Object
-
#strip_para(node) ⇒ Object
-
#strong(docxml) ⇒ Object
-
#strong1(text) ⇒ Object
-
#table1(node) ⇒ Object
-
#table_col_count(table) ⇒ Object
how many columns in the table?.
-
#table_cols_count(node) ⇒ Object
-
#table_content_to_tfoot(node) ⇒ Object
-
#table_dl_to_tfoot(node) ⇒ Object
-
#table_fn(elem) ⇒ Object
-
#table_footnotes(docxml) ⇒ Object
-
#table_thead_pt(node, name) ⇒ Object
-
#table_unit_notes(node, thead, cols) ⇒ Object
-
#termsource_join_delim(_elem) ⇒ Object
-
#termsource_label(elem, sources) ⇒ Object
-
#termsource_mod_text_delim(_elem) ⇒ Object
-
#termsource_modification(elem) ⇒ Object
-
#toc_title_insert_pt(docxml) ⇒ Object
-
#ul_label_list(_elem) ⇒ Object
-
#ul_label_value(elem) ⇒ Object
-
#url_note_process(_data) ⇒ Object
Methods included from Init
#bibrenderer, #convert_i18n_init1, #i18n_init, #metadata_init, #std_docid_semantic, #xref_init
Instance Method Details
#admits(elem) ⇒ Object
40
41
42
43
44
|
# File 'lib/isodoc/jis/presentation_xml_convert.rb', line 40
def admits(elem)
elem.xpath(ns(".//semx[@element = 'admitted']")).each do |t|
t.previous = @i18n.l10n("#{@i18n.admitted}: ")
end
end
|
#anchor_linkend(node, linkend) ⇒ Object
if termsource xref has no SDO identifier, cite instead by full reference
161
162
163
164
165
|
# File 'lib/isodoc/jis/presentation_xml_convert.rb', line 161
def anchor_linkend(node, linkend)
node.name == "fmt-origin" && fmt_origin_cite_full?(node) and
node["style"] ||= "short"
super
end
|
#annex(docxml) ⇒ Object
16
17
18
19
|
# File 'lib/isodoc/jis/presentation_section.rb', line 16
def annex(docxml)
super
(docxml)
end
|
#annex1(elem) ⇒ Object
7
8
9
10
|
# File 'lib/isodoc/jis/presentation_section.rb', line 7
def annex1(elem)
elem["commentary"] == "true" and return (elem)
super
end
|
#annex_delim(_elem) ⇒ Object
12
13
14
|
# File 'lib/isodoc/jis/presentation_section.rb', line 12
def annex_delim(_elem)
"<br/>"
end
|
#bibdata_i18n(bibdata) ⇒ Object
64
65
66
67
|
# File 'lib/isodoc/jis/presentation_xml_convert.rb', line 64
def bibdata_i18n(bibdata)
super
date_translate(bibdata)
end
|
#biblio_ref_entry_code(ordinal, ids, _standard, datefn, bib) ⇒ Object
227
228
229
230
231
232
233
234
235
236
237
|
# File 'lib/isodoc/jis/presentation_xml_convert.rb', line 227
def biblio_ref_entry_code(ordinal, ids, _standard, datefn, bib)
delim = bib.at(ns("./language"))&.text == "ja" ? " " : "<esc>,</esc> "
ret = esc(ids[:ordinal]) || esc(ids[:content]) || esc(ids[:metanorma]) || "[#{esc ordinal.to_s}]"
if ids[:sdo] && !ids[:sdo].empty?
ret = prefix_bracketed_ref(ret)
ret += "#{esc ids[:sdo]}#{datefn}#{delim}"
else
ret = prefix_bracketed_ref("#{ret}#{datefn}")
end
ret
end
|
#bracketed_refs_processing(docxml) ⇒ Object
208
|
# File 'lib/isodoc/jis/presentation_xml_convert.rb', line 208
def bracketed_refs_processing(docxml); end
|
30
31
32
33
34
35
|
# File 'lib/isodoc/jis/presentation_section.rb', line 30
def (elem)
t = elem.elements.first
(t)
middle_title_main(t, "CommentaryStandardName")
prefix_name(elem, {}, nil, "title")
end
|
37
38
39
40
41
42
43
44
|
# File 'lib/isodoc/jis/presentation_section.rb', line 37
def (elem)
ret = <<~COMMENTARY
<p class="CommentaryStandardNumber">JIS #{@meta.get[:docnumber_undated]}
COMMENTARY
yr = @meta.get[:docyear] and
ret += ": <span class='CommentaryEffectiveYear'>#{yr}</span>"
elem.previous = ret
end
|
#contains_para?(text) ⇒ Boolean
50
51
52
|
# File 'lib/isodoc/jis/presentation_xml_convert.rb', line 50
def contains_para?(text)
/\([^()]+\)|([^()].+)/.match?(text)
end
|
#convert1(xml, filename, dir) ⇒ Object
96
97
98
99
100
101
102
103
|
# File 'lib/isodoc/jis/presentation_xml_convert.rb', line 96
def convert1(xml, filename, dir)
j = xml.at(ns("//metanorma-extension/presentation-metadata/" \
"autonumbering-style"))&.text
j ||= "arabic"
@autonumbering_style = j.to_sym
@xrefs.autonumbering_style = j.to_sym
super
end
|
#date_translate(bibdata) ⇒ Object
69
70
71
72
73
74
|
# File 'lib/isodoc/jis/presentation_xml_convert.rb', line 69
def date_translate(bibdata)
@lang == "ja" or return
bibdata.xpath(ns("./date")).each do |d|
d.children = date_translate1(d.text)
end
end
|
#date_translate1(date) ⇒ Object
76
77
78
79
80
81
82
83
|
# File 'lib/isodoc/jis/presentation_xml_convert.rb', line 76
def date_translate1(date)
j = @i18n.japanese_date(date.strip)
@autonumbering_style == :japanese and
j.gsub!(/(\d+)/) do
$1.to_i.localize(:ja).spellout
end
j
end
|
#dl(docxml) ⇒ Object
TODO: move the table/figure key processing to Word, not Presentation XML
20
21
22
23
24
25
26
|
# File 'lib/isodoc/jis/presentation_list.rb', line 20
def dl(docxml)
super
docxml.xpath(ns("//table//dl | //figure//dl")).each do |l|
l.at(ns("./dl")) || l.at("./ancestor::xmlns:dl") and next
dl_to_para(l)
end
end
|
#dl_id_insert(node, ret) ⇒ Object
42
43
44
45
46
47
|
# File 'lib/isodoc/jis/presentation_list.rb', line 42
def dl_id_insert(node, ret)
a = node.replace(ret)
p = a.at("./descendant-or-self::xmlns:p")
node["id"] and p << "<bookmark id='#{node['id']}'/>"
a.xpath("./descendant-or-self::*[@id = '']").each { |x| x.delete("id") }
end
|
#dl_to_para(node) ⇒ Object
32
33
34
35
36
37
38
39
40
|
# File 'lib/isodoc/jis/presentation_list.rb', line 32
def dl_to_para(node)
ret = dl_to_para_name(node)
ret += dl_to_para_terms(node)
node.elements.reject { |n| %w(dt dd name fmt-name).include?(n.name) }
.each do |x|
ret += x.to_xml
end
dl_id_insert(node, ret)
end
|
#dl_to_para_name(node) ⇒ Object
49
50
51
52
53
54
55
56
|
# File 'lib/isodoc/jis/presentation_list.rb', line 49
def dl_to_para_name(node)
e = node.at(ns("./fmt-name")) or return ""
if node.parent.parent.parent.parent.parent["type"] == "participants"
""
else
"<p class='ListTitle'>#{e.children.to_xml}</p>"
end
end
|
#dl_to_para_terms(node) ⇒ Object
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/isodoc/jis/presentation_list.rb', line 58
def dl_to_para_terms(node)
ret = ""
node.elements.select { |n| dt_dd?(n) }.each_slice(2) do |dt, dd|
term = strip_para(dt)
defn = strip_para(dd)
bkmk = dd["id"] ? "<bookmark id='#{dd['id']}'/>" : ""
ret += "<p class='dl' id='#{dt['id']}'>#{term}: #{bkmk}#{defn}</p>"
end
ret
end
|
#dt_dd?(node) ⇒ Boolean
28
29
30
|
# File 'lib/isodoc/jis/presentation_list.rb', line 28
def dt_dd?(node)
%w{dt dd}.include? node.name
end
|
#edition_integer?(bibdata) ⇒ Boolean
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/isodoc/jis/presentation_xml_convert.rb', line 85
def edition_integer?(bibdata)
x = bibdata.at(ns("./edition[not(@language) or @language = '']"))
x or return
/^\d+$/.match?(x.text) or return
num = x.text.to_i
@autonumbering_style == :japanese and num = num.localize(:ja).spellout
x.next =
%(<edition language="#{@lang}" numberonly="true">#{num}</edition>)
num
end
|
#edition_translate_iso(bibdata) ⇒ Object
243
|
# File 'lib/isodoc/jis/presentation_xml_convert.rb', line 243
def edition_translate_iso(bibdata); end
|
115
116
117
118
119
120
|
# File 'lib/isodoc/jis/presentation_xml_convert.rb', line 115
def figure_fn(elem)
fnotes = elem.xpath(ns(".//fn")) - elem.xpath(ns("./name//fn")) -
elem.xpath(ns("./fmt-name//fn"))
ret = (fnotes)
f = (fnotes, ret) and elem << f
end
|
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/isodoc/jis/presentation_table.rb', line 59
def (node)
colspan = table_col_count(node)
empty_row = full_row(colspan, " ", border: true)
node.at(ns("./tfoot/tr[last()]/td")) or
node.at(ns("./tbody")).after("<tfoot>#{empty_row}</tfoot>").first
= node.at(ns("./tfoot/tr[last()]/td"))
["colspan"] != colspan.to_s and
.parent.next = empty_row
node.at(ns("./tfoot/tr[last()]/td"))
end
|
#fmt_origin_cite_full?(elem) ⇒ Boolean
167
168
169
170
171
172
173
174
|
# File 'lib/isodoc/jis/presentation_xml_convert.rb', line 167
def fmt_origin_cite_full?(elem)
sem_xml_descendant?(elem) and return
id = elem["bibitemid"] or return
b = @bibitem_lookup[id] or return
!b.at(ns(<<~XPATH))
./docidentifier[not(#{SERIAL_NUM_DOCID} or @scope = 'biblio-tag' or @type = 'metanorma' or @type = 'metanorma-ordinal' or @type='title')]
XPATH
end
|
#fn_body_label(fnote) ⇒ Object
144
145
146
147
148
149
150
151
152
153
154
|
# File 'lib/isodoc/jis/presentation_xml_convert.rb', line 144
def fn_body_label(fnote)
if fnote.ancestors("table, figure").empty? ||
!fnote.ancestors("figure").empty? &&
!fnote.ancestors("name, fmt-name").empty?
"<sup>#{fn_label(fnote)}</sup>"
else
spc = %w(zh ja ko).include?(@lang) ? "" : " "
"#{@i18n.}#{spc}<sup>#{fn_label(fnote)}" \
"<span class='fmt-label-delim'>)</span></sup>"
end
end
|
#fn_ref_label(fnote) ⇒ Object
133
134
135
136
137
138
139
140
141
142
|
# File 'lib/isodoc/jis/presentation_xml_convert.rb', line 133
def fn_ref_label(fnote)
if fnote.ancestors("table, figure").empty? ||
!fnote.ancestors("figure").empty? &&
!fnote.ancestors("name, fmt-name").empty?
"<sup>#{fn_label(fnote)}</sup>"
else
"<sup>#{fn_label(fnote)}" \
"<span class='fmt-label-delim'>)</span></sup>"
end
end
|
#full_row(cols, elem, border: false) ⇒ Object
90
91
92
93
94
95
|
# File 'lib/isodoc/jis/presentation_table.rb', line 90
def full_row(cols, elem, border: false)
b = border ? "" : " border='0'"
<<~XML
<tr #{add_id_text}><td #{add_id_text}#{b} colspan='#{cols}'>#{elem}</td></tr>
XML
end
|
if there is already a full-row cell at the start of tfoot, use that to move content into else create a full-row cell at the start of tfoot
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/isodoc/jis/presentation_table.rb', line 48
def (node)
colspan = table_col_count(node)
empty_row = full_row(colspan, " ", border: true)
node.at(ns("./tfoot/tr/td")) or
node.at(ns("./tbody")).after("<tfoot>#{empty_row}</tfoot>").first
= node.at(ns("./tfoot/tr/td"))
["colspan"] != colspan.to_s and
.parent.previous = empty_row
node.at(ns("./tfoot/tr/td"))
end
|
#inline(docxml) ⇒ Object
11
12
13
14
|
# File 'lib/isodoc/jis/presentation_xml_convert.rb', line 11
def inline(docxml)
super
strong(docxml)
end
|
#localized_strings(docxml) ⇒ Object
105
106
107
108
109
110
111
112
113
|
# File 'lib/isodoc/jis/presentation_xml_convert.rb', line 105
def localized_strings(docxml)
super
a = docxml.at(ns("//localized-strings")) or return
ret = (0..1000).map do |i|
n = i.localize(:ja).spellout
"<localized-string key='#{i}' language='ja'>#{n}</localized-string>"
end.join("\n")
a << ret
end
|
#make_preface(docxml) ⇒ Object
46
47
48
49
50
51
|
# File 'lib/isodoc/jis/presentation_section.rb', line 46
def make_preface(docxml)
docxml.at(ns("//preface")) ||
docxml.at(ns("//sections | //annex | //bibliography"))
&.before("<preface> </preface>")
&.previous_element
end
|
#middle_subtitle_main(out, style) ⇒ Object
158
159
160
161
162
163
164
165
166
167
168
169
|
# File 'lib/isodoc/jis/presentation_section.rb', line 158
def middle_subtitle_main(out, style)
t = @meta.get[:docsubtitlemain]
(t && !t.empty?) or return
ret = middle_title_para(style, :docsubtitleintro, :docsubtitlemain,
:docsubtitlepart)
if a = @meta.get[:docsubtitlepart]
ret += "<p class='zzSTDTitle2'>"
b = @meta.get[:docsubtitlepartlabel] and ret += "#{b}: "
ret += "<br/><strong>#{a}</strong></p>"
end
out.previous = ret
end
|
#middle_title(docxml) ⇒ Object
123
124
125
126
127
128
129
130
|
# File 'lib/isodoc/jis/presentation_section.rb', line 123
def middle_title(docxml)
s = docxml.at(ns("//sections")) or return
elem = s.children.first
middle_title_hdr(elem)
middle_title_main(elem, "zzSTDTitle1")
middle_subtitle_main(elem, "zzSTDTitle2")
end
|
#middle_title_hdr(out) ⇒ Object
132
133
134
135
136
137
138
139
140
141
142
143
|
# File 'lib/isodoc/jis/presentation_section.rb', line 132
def middle_title_hdr(out)
ret = "<p class='JapaneseIndustrialStandard'>#{@i18n.jis}"
@meta.get[:unpublished] and ret += @i18n.l10n("(#{@i18n.draft_label})")
ret += ("<tab/>" * 7)
ret += "<span class='JIS'>JIS</span></p>"
ret += "<p class='StandardNumber'><tab/>#{@meta.get[:docnumber_undated]}"
if yr = @meta.get[:docyear]
ret += ": <span class='EffectiveYear'>#{yr}</span>"
end
ret += "</p><p class='IDT'/>"
out.previous = ret
end
|
#middle_title_main(out, style) ⇒ Object
145
146
147
148
149
150
151
152
153
154
155
156
|
# File 'lib/isodoc/jis/presentation_section.rb', line 145
def middle_title_main(out, style)
t = @meta.get[:doctitlemain]
(t && !t.empty?) or return
ret =
middle_title_para(style, :doctitleintro, :doctitlemain, :doctitlepart)
if a = @meta.get[:doctitlepart]
ret += "<p class='zzSTDTitle1'>"
b = @meta.get[:doctitlepartlabel] and ret += "#{b}: "
ret += "<br/><strong>#{a}</strong></p>"
end
out.previous = ret
end
|
#middle_title_para(style, intro, main, part) ⇒ Object
171
172
173
174
175
176
177
178
|
# File 'lib/isodoc/jis/presentation_section.rb', line 171
def middle_title_para(style, intro, main, part)
ret = "<p class='#{style}'>#{@meta.get[intro]}"
ret += " — " if @meta.get[intro] && @meta.get[main]
ret += @meta.get[main]
ret += " — " if @meta.get[main] && @meta.get[part]
ret += "</p>"
ret
end
|
21
22
23
24
25
26
27
28
|
# File 'lib/isodoc/jis/presentation_section.rb', line 21
def (docxml)
docxml.at(ns("//annex[@commentary = 'true']")) or return
b = docxml.at(ns("//bibliography")) ||
docxml.at(ns("//annex[last()]")).after(" ").next
docxml.xpath(ns("//annex[@commentary = 'true']")).reverse_each do |x|
b.next = x.remove
end
end
|
#move_introduction(doc) ⇒ Object
64
65
66
67
68
69
70
|
# File 'lib/isodoc/jis/presentation_section.rb', line 64
def move_introduction(doc)
source = doc.at(ns("//preface/introduction")) or return
dest = doc.at(ns("//sections")) ||
doc.at(ns("//preface")).after("<sections> </sections>").next_element
dest.children.empty? and dest.children = " "
dest.add_first_child source
end
|
#move_participants(doc) ⇒ Object
72
73
74
75
76
77
78
79
|
# File 'lib/isodoc/jis/presentation_section.rb', line 72
def move_participants(doc)
doc.xpath(ns("//clause[@type = 'participants']")).reverse_each do |p|
t = participant_table(p) or next
p.remove
ins = make_preface(doc) or next
ins.add_first_child t
end
end
|
#norm_ref_entry_code(_ordinal, ids, _standard, datefn, bib) ⇒ Object
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
# File 'lib/isodoc/jis/presentation_xml_convert.rb', line 212
def norm_ref_entry_code(_ordinal, ids, _standard, datefn, bib)
delim = bib.at(ns("./language"))&.text == "ja" ? " " : "<esc>,</esc> "
ret = (ids[:ordinal] || ids[:content] || ids[:metanorma] || ids[:sdo]).to_s
ret = esc(ret)
(ids[:ordinal] || ids[:content] || ids[:metanorma]) && ids[:sdo] and
ret += "#{delim}<strong>#{esc ids[:sdo]}</strong>"
!ids[:ordinal] && !ids[:content] && !ids[:metanorma] && ids[:sdo] and
ret = "<strong>#{ret}</ret>"
ret += datefn
ret.empty? and return ret
ids[:sdo] and ret += delim
ret.sub(delim, "").strip.empty? and return ""
ret
end
|
#ol_depth(node) ⇒ Object
4
5
6
7
|
# File 'lib/isodoc/jis/presentation_list.rb', line 4
def ol_depth(node)
depth = node.ancestors("ol").size + 1
@counter.ol_type(node, depth) end
|
#omit_docid_prefix(prefix) ⇒ Object
128
129
130
131
|
# File 'lib/isodoc/jis/presentation_xml_convert.rb', line 128
def omit_docid_prefix(prefix)
prefix.nil? || prefix.empty? and return true
super || %w(JIS).include?(prefix)
end
|
#participant_rows(yaml) ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/isodoc/jis/presentation_section.rb', line 108
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
<<~XML
<tr #{add_id_text}><td #{add_id_text}>#{r}</td><td #{add_id_text}>#{n}</td><td #{add_id_text}>#{y['affiliation']}</td></tr>
XML
end.join("\n")
end
|
#participant_table(clause) ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/isodoc/jis/presentation_section.rb', line 81
def participant_table(clause)
s, t, y, d = participant_table_prep(clause)
s or return nil
out1 = <<~OUTPUT
<clause #{add_id_text} type="participants"><title>#{t}</title>
<table #{add_id_text} unnumbered='true'>
<thead>
<tr #{add_id_text}><th #{add_id_text}/><th #{add_id_text}>#{@i18n.full_name}</th><th #{add_id_text}>#{@i18n.affiliation}</th></tr>
</thead>
<tbody>
OUTPUT
out2 = <<~OUTPUT
</tbody>#{d&.to_xml}</table></clause>
OUTPUT
"#{out1}#{participant_rows(y)}#{out2}"
end
|
#participant_table_prep(clause) ⇒ Object
98
99
100
101
102
103
104
105
106
|
# File 'lib/isodoc/jis/presentation_section.rb', line 98
def participant_table_prep(clause)
s = clause.at(ns("./sourcecode/body"))
t = clause.at(ns("./title"))&.children&.to_xml ||
%(#{@meta.get[:"investigative-committee"]} #{@i18n.membership_table})
y = YAML.safe_load(s.children.to_xml(encoding: "UTF-8"))
d = clause.at(ns("./key")) || clause.at(ns("./dl"))
(s && y.is_a?(Array)) or return [nil, nil, nil, nil]
[s, t, y, d]
end
|
#preface_rearrange(doc) ⇒ Object
58
59
60
61
62
|
# File 'lib/isodoc/jis/presentation_section.rb', line 58
def preface_rearrange(doc)
move_introduction(doc)
super
move_participants(doc)
end
|
#short_style_origin(docxml) ⇒ Object
210
|
# File 'lib/isodoc/jis/presentation_xml_convert.rb', line 210
def short_style_origin(docxml); end
|
#source1_label(elem, sources, ancestor) ⇒ Object
54
55
56
57
58
59
60
61
62
|
# File 'lib/isodoc/jis/presentation_xml_convert.rb', line 54
def source1_label(elem, sources, ancestor)
elem.children = if ancestor == :table
l10n("#{@i18n.source}: #{esc sources}")
elsif contains_para?(sources)
l10n("[#{@i18n.source}: #{esc sources}]")
else
l10n("(#{@i18n.source}: #{esc sources})")
end
end
|
#source_join_delim(_elem) ⇒ Object
180
181
182
|
# File 'lib/isodoc/jis/presentation_xml_convert.rb', line 180
def source_join_delim(_elem)
@lang == "ja" ? "、" : "; "
end
|
#strip_para(node) ⇒ Object
46
47
48
|
# File 'lib/isodoc/jis/presentation_xml_convert.rb', line 46
def strip_para(node)
node.children.to_xml.gsub(%r{</?p( [^>]*)?>}, "")
end
|
#strong(docxml) ⇒ Object
19
20
21
22
23
24
|
# File 'lib/isodoc/jis/presentation_xml_convert.rb', line 19
def strong(docxml)
docxml.xpath(ns("//strong")).each do |x|
(x.children.size == 1 && x.children.first.text?) or next x.replace(strong1(x.text))
end
end
|
#strong1(text) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/isodoc/jis/presentation_xml_convert.rb', line 26
def strong1(text)
jpan = /^[#{JPAN}]/o.match?(text[0])
ret = jpan ? JPAN_BOLD : "<strong>"
text.chars.each do |n|
new = /^[#{JPAN}]/o.match?(n)
jpan && !new and ret += "</span><strong>"
!jpan && new and ret += "</strong>#{JPAN_BOLD}"
ret += n
jpan = new
end
ret += /[#{JPAN}]/o.match?(text[-1]) ? "</span>" : "</strong>"
ret
end
|
#table1(node) ⇒ Object
4
5
6
7
8
9
10
11
12
13
|
# File 'lib/isodoc/jis/presentation_table.rb', line 4
def table1(node)
super
cols = table_cols_count(node)
ins = node.at(ns("./fmt-xref-label")) ||
node.at(ns("./fmt-name"))
thead = table_thead_pt(node, ins)
table_unit_notes(node, thead, cols)
(node)
(node)
end
|
#table_col_count(table) ⇒ Object
how many columns in the table?
37
38
39
40
41
42
43
|
# File 'lib/isodoc/jis/presentation_table.rb', line 37
def table_col_count(table)
cols = 0
table&.at(ns(".//tr"))&.xpath(ns("./td | ./th"))&.each do |td|
cols += (td["colspan"] ? td["colspan"].to_i : 1)
end
cols
end
|
#table_cols_count(node) ⇒ Object
76
77
78
79
80
81
82
|
# File 'lib/isodoc/jis/presentation_table.rb', line 76
def table_cols_count(node)
cols = 0
node.at(ns(".//tr")).xpath(ns("./td | ./th")).each do |x|
cols += x["colspan"]&.to_i || 1
end
cols
end
|
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/isodoc/jis/presentation_table.rb', line 24
def (node)
node.at(ns("./note | ./fmt-source | ./example | " \
"./fmt-footnote-container")) or return
tf = (node)
%w(example note fmt-footnote-container
fmt-source).each do |n|
node.xpath(ns("./#{n}")).each do |x|
tf.children.last.next = x.remove
end
end
end
|
15
16
17
18
19
20
21
22
|
# File 'lib/isodoc/jis/presentation_table.rb', line 15
def (node)
dl = node.xpath(ns("./key")) || node.xpath(ns("./dl")) or return
dl.text.strip.empty? and return
tf = (node)
dl.reverse_each do |x|
tf.children.first.previous = x.remove
end
end
|
#table_fn(elem) ⇒ Object
122
123
124
125
126
|
# File 'lib/isodoc/jis/presentation_xml_convert.rb', line 122
def table_fn(elem)
fnotes = elem.xpath(ns(".//fn"))
ret = (fnotes)
f = (fnotes, ret) and elem << f
end
|
156
157
158
|
# File 'lib/isodoc/jis/presentation_xml_convert.rb', line 156
def (docxml)
docxml.xpath(ns("//table//fn"))
end
|
#table_thead_pt(node, name) ⇒ Object
70
71
72
73
74
|
# File 'lib/isodoc/jis/presentation_table.rb', line 70
def table_thead_pt(node, name)
node.at(ns("./thead")) ||
name&.after("<thead> </thead>")&.next ||
node.elements.first.before("<thead> </thead>").previous
end
|
#table_unit_notes(node, thead, cols) ⇒ Object
84
85
86
87
88
|
# File 'lib/isodoc/jis/presentation_table.rb', line 84
def table_unit_notes(node, thead, cols)
unit_notes = node.xpath(ns(".//note[@type = 'units']"))
unit_notes.empty? and return
thead.children.first.previous = full_row(cols, unit_notes.remove.to_xml)
end
|
#termsource_join_delim(_elem) ⇒ Object
176
177
178
|
# File 'lib/isodoc/jis/presentation_xml_convert.rb', line 176
def termsource_join_delim(_elem)
@lang == "ja" ? "、" : "; "
end
|
#termsource_label(elem, sources) ⇒ Object
200
201
202
203
204
205
206
|
# File 'lib/isodoc/jis/presentation_xml_convert.rb', line 200
def termsource_label(elem, sources)
if contains_para?(sources)
elem.replace(l10n("[#{@i18n.source}: #{esc sources}]"))
else
elem.replace(l10n("(#{@i18n.source}: #{esc sources})"))
end
end
|
#termsource_mod_text_delim(_elem) ⇒ Object
184
185
186
|
# File 'lib/isodoc/jis/presentation_xml_convert.rb', line 184
def termsource_mod_text_delim(_elem)
@lang == "ja" ? "," : ", "
end
|
#termsource_modification(elem) ⇒ Object
188
189
190
191
192
193
194
195
196
197
198
|
# File 'lib/isodoc/jis/presentation_xml_convert.rb', line 188
def termsource_modification(elem)
elem.xpath(".//text()[normalize-space() = '']").each(&:remove)
origin = elem.at(ns("./origin"))
mod = elem.at(ns("./modification"))
s = termsource_status(elem["status"])
mod && elem["status"] == "modified" and s = @i18n.modified_detail
s and origin.next = l10n(", #{s}", @lang, @script,
{ prev: origin.text })
mod or return
termsource_add_modification_text(mod)
end
|
#toc_title_insert_pt(docxml) ⇒ Object
53
54
55
56
|
# File 'lib/isodoc/jis/presentation_section.rb', line 53
def toc_title_insert_pt(docxml)
ins = make_preface(docxml) or return nil
ins.children.last.after(" ").next
end
|
#ul_label_list(_elem) ⇒ Object
9
10
11
|
# File 'lib/isodoc/jis/presentation_list.rb', line 9
def ul_label_list(_elem)
%w(- ・)
end
|
#ul_label_value(elem) ⇒ Object
13
14
15
16
17
|
# File 'lib/isodoc/jis/presentation_list.rb', line 13
def ul_label_value(elem)
depth = elem.ancestors("ul").size
val = ul_label_list(elem)
val[(depth - 1) % val.size]
end
|
#url_note_process(_data) ⇒ Object
239
240
241
|
# File 'lib/isodoc/jis/presentation_xml_convert.rb', line 239
def url_note_process(_data)
""
end
|