Class: IsoDoc::PresentationXMLConvert
- Inherits:
-
Convert
show all
- Defined in:
- lib/isodoc/presentation_xml_convert.rb,
lib/isodoc/presentation_function/block.rb,
lib/isodoc/presentation_function/inline.rb,
lib/isodoc/presentation_function/bibdata.rb,
lib/isodoc/presentation_function/section.rb
Constant Summary
Function::Utils::CLAUSE_ANCESTOR, Function::Utils::DOCTYPE_HDR, Function::Utils::NOKOHEAD, Function::Utils::NOTE_CONTAINER_ANCESTOR
Function::Table::SW
Function::Section::TERM_CLAUSE
Function::Lists::OL_STYLE
Function::Cleanup::FIGURE_WITH_FOOTNOTES
Function::Blocks::EXAMPLE_TBL_ATTR, Function::Blocks::EXAMPLE_TD_ATTR
Instance Attribute Summary
Attributes inherited from Convert
#i18n, #options
Instance Method Summary
collapse
-
#amend(docxml) ⇒ Object
we use this to eliminate the semantic amend blocks from rendering.
-
#amend1(f) ⇒ Object
-
#anchor_linkend(node, linkend) ⇒ Object
-
#anchor_linkend1(node) ⇒ Object
-
#annex(docxml) ⇒ Object
-
#annex1(f) ⇒ Object
-
#bibdata(docxml) ⇒ Object
-
#bibdata_current(docxml) ⇒ Object
-
#bibdata_i18n(b) ⇒ Object
-
#blank?(v) ⇒ Boolean
-
#block(docxml) ⇒ Object
-
#capitalise_xref(node, linkend) ⇒ Object
-
#clause(docxml) ⇒ Object
-
#clause1(f) ⇒ Object
-
#conversions(docxml) ⇒ Object
-
#convert1(docxml, filename, dir) ⇒ Object
-
#eref(docxml) ⇒ Object
-
#eref_localities(refs, target) ⇒ Object
so not <origin bibitemid=“ISO7301” citeas=“ISO 7301”> <locality type=“section”><reference>3.1</reference></locality></origin>.
-
#eref_localities0(r, i, target, delim) ⇒ Object
-
#eref_localities1(target, type, from, to, delim, lang = "en") ⇒ Object
TODO: move to localization file.
-
#eref_localities1_zh(target, type, from, to, delim) ⇒ Object
TODO: move to localization file.
-
#eref_locality_stack(r, i, target, delim, ret) ⇒ Object
-
#example(docxml) ⇒ Object
-
#example1(f) ⇒ Object
-
#figure(docxml) ⇒ Object
-
#figure1(f) ⇒ Object
-
#formula(docxml) ⇒ Object
-
#formula1(f) ⇒ Object
-
#get_linkend(node) ⇒ Object
-
#hash_translate(bibdata, hash, xpath) ⇒ Object
-
#i18n_safe(k) ⇒ Object
-
#i18n_tag(k, v) ⇒ Object
-
#i8n_name(h, pref) ⇒ Object
-
#i8n_name1(h, pref) ⇒ Object
-
#initialize(options) ⇒ PresentationXMLConvert
constructor
A new instance of PresentationXMLConvert.
-
#inline(docxml) ⇒ Object
-
#nearest_block_parent(node) ⇒ Object
-
#non_locality_elems(node) ⇒ Object
-
#note(docxml) ⇒ Object
-
#note1(f) ⇒ Object
-
#origin(docxml) ⇒ Object
-
#permission(docxml) ⇒ Object
-
#postprocess(result, filename, dir) ⇒ Object
-
#prefix_container(container, linkend, _target) ⇒ Object
-
#prefix_name(f, delim, number, elem) ⇒ Object
-
#quotesource(docxml) ⇒ Object
-
#recommendation(docxml) ⇒ Object
-
#recommendation1(f, type) ⇒ Object
-
#requirement(docxml) ⇒ Object
-
#section(docxml) ⇒ Object
-
#sourcecode(docxml) ⇒ Object
-
#sourcecode1(f) ⇒ Object
-
#table(docxml) ⇒ Object
-
#table1(f) ⇒ Object
-
#term(docxml) ⇒ Object
-
#term1(f) ⇒ Object
-
#termexample(docxml) ⇒ Object
-
#termnote(docxml) ⇒ Object
-
#termnote1(f) ⇒ Object
-
#toXML(result, filename) ⇒ Object
-
#trim_hash(h) ⇒ Object
-
#trim_hash1(h) ⇒ Object
-
#xref(docxml) ⇒ Object
-
#xref1(f) ⇒ Object
Methods inherited from Convert
#convert, #convert_init, #convert_scss, #default_file_locations, #default_fonts, #fonts_options, #generate_css, #html_doc_path, #i18n_init, #l10n, #metadata_init, #middle_clause, #populate_css, #precompiled_style_or_original, #scss_fontheader, #tmpimagedir_suffix, #xref_init
Methods included from ClassUtils
#date_range, #liquid, #ns
#attr_code, #date_range, #empty2nil, #extract_delims, #from_xhtml, #get_clause_id, #get_note_container_id, #header_strip, #image_localfile, #insert_tab, #labelled_ancestor, #liquid, #noko, #ns, #populate_template, #save_dataimage, #sentence_join, #to_xhtml, #to_xhtml_fragment
#body_attr, #boilerplate, #define_head, #in_sourcecode, #info, #init_file, #make_body, #make_body1, #make_body2, #make_body3, #middle, #middle_admonitions, #middle_title, #note?, #parse, #rel_tmpimagedir, #set_termdomain, #tmpimagedir
#admitted_term_parse, #definition_parse, #deprecated_term_parse, #modification_parse, #para_then_remainder, #term_parse, #termdef_parse, #termdocsource_parse, #termnote_delim, #termnote_parse, #termref_parse
#make_tr_attr, #table_attrs, #table_parse, #table_title_parse, #tbody_parse, #tcaption, #tfoot_parse, #thead_parse, #tr_parse
#abstract, #acknowledgements, #annex_attrs, #annex_name, #clause_attrs, #clause_name, #clause_parse, #clause_parse_title, #clausedelim, #clausedelimspace, #copyright_parse, #feedback_parse, #foreword, #inline_header_title, #introduction, #is_clause?, #legal_parse, #license_parse, #preface, #preface_block, #scope, #symbols_abbrevs, #symbols_parse, #terms_defs, #terms_parse
#bibitem_ref_code, #biblio_list, #bibliography, #bibliography_parse, #bibliography_xpath, #bracket_if_num, #date_note_process, #docid_l10n, #docid_prefix, #format_ref, #implicit_reference, #is_standard, #iso_bibitem_entry_attrs, #iso_title, #nonstd_bibitem, #norm_ref, #norm_ref_xpath, #omit_docid_prefix, #pref_ref_code, #prefix_bracketed_ref, #ref_entry_code, #reference_format, #render_identifier, #std_bibitem_entry
#dl_attrs, #dl_parse, #dt_dd?, #dt_parse, #li_parse, #ol_attrs, #ol_depth, #ol_parse, #ol_style, #ul_attrs, #ul_parse
#bookmark_parse, #br_parse, #callout_parse, #concept_parse, #em_parse, #eref_parse, #eref_target, #error_parse, #found_matching_variant_sibling, #hr_parse, #image_parse, #image_title_parse, #index_parse, #keyword_parse, #link_parse, #no_locality_parse, #origin_parse, #page_break, #pagebreak_parse, #section_break, #smallcap_parse, #stem_parse, #strike_parse, #strong_parse, #sub_parse, #suffix_url, #sup_parse, #termrefelem_parse, #text_parse, #tt_parse, #variant_parse, #xref_parse
#admonition_cleanup, #break_up_long_strings, #break_up_long_strings1, #cleanup, #example_cleanup, #figure_aside_process, #figure_cleanup, #figure_get_or_make_dl, #footnote_cleanup, #footnote_reference_format, #inline_header_cleanup, #merge_fnref_into_fn_text, #new_fullcolspan_row, #passthrough_cleanup, #remove_bottom_border, #symbols_cleanup, #table_cleanup, #table_footnote_cleanup, #table_footnote_reference_format, #table_get_or_make_tfoot, #table_long_strings_cleanup, #table_note_cleanup, #termref_cleanup, #textcleanup
#admonition_attrs, #admonition_class, #admonition_name, #admonition_name_parse, #admonition_parse, #annotation_parse, #example_div_attr, #example_div_parse, #example_label, #example_parse, #example_table_attr, #example_table_parse, #figure_attrs, #figure_key, #figure_name_parse, #figure_parse, #formula_attrs, #formula_parse, #formula_parse1, #formula_where, #keep_style, #note_attrs, #note_delim, #note_p_parse, #note_parse, #note_parse1, #para_attrs, #para_class, #para_parse, #passthrough_parse, #permission_parse, #pre_parse, #pseudocode_attrs, #pseudocode_parse, #quote_attribution, #quote_parse, #recommendation_attr_keyvalue, #recommendation_attr_parse, #recommendation_attributes, #recommendation_attributes1, #recommendation_labels, #recommendation_name, #recommendation_parse, #reqt_attrs, #reqt_component_attrs, #reqt_metadata_node, #requirement_component_parse, #requirement_parse, #requirement_skip_parse, #sourcecode_attrs, #sourcecode_name_parse, #sourcecode_parse
Constructor Details
Returns a new instance of PresentationXMLConvert.
8
9
10
11
12
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 8
def initialize(options)
@format = :presentation
@suffix = "presentation.xml"
super
end
|
Instance Method Details
#amend(docxml) ⇒ Object
we use this to eliminate the semantic amend blocks from rendering
139
140
141
142
143
|
# File 'lib/isodoc/presentation_function/block.rb', line 139
def amend(docxml)
docxml.xpath(ns("//amend")).each do |f|
amend1(f)
end
end
|
#amend1(f) ⇒ Object
145
146
147
148
149
150
|
# File 'lib/isodoc/presentation_function/block.rb', line 145
def amend1(f)
f.xpath(ns("./autonumber")).each { |a| a.remove }
f.xpath(ns("./newcontent")).each { |a| a.name = "quote" }
f.xpath(ns("./description")).each { |a| a.replace(a.children) }
f.replace(f.children)
end
|
#anchor_linkend(node, linkend) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/isodoc/presentation_function/inline.rb', line 7
def anchor_linkend(node, linkend)
if node["citeas"].nil? && node["bibitemid"]
return @xrefs.anchor(node["bibitemid"] ,:xref) || "???"
elsif node["target"] && node["droploc"]
return @xrefs.anchor(node["target"], :value) ||
@xrefs.anchor(node["target"], :label) ||
@xrefs.anchor(node["target"], :xref) || "???"
elsif node["target"] && !/.#./.match(node["target"])
linkend = anchor_linkend1(node)
end
linkend || "???"
end
|
#anchor_linkend1(node) ⇒ Object
20
21
22
23
24
25
26
27
|
# File 'lib/isodoc/presentation_function/inline.rb', line 20
def anchor_linkend1(node)
linkend = @xrefs.anchor(node["target"], :xref)
container = @xrefs.anchor(node["target"], :container, false)
(container && get_note_container_id(node) != container &&
@xrefs.get[node["target"]]) &&
linkend = prefix_container(container, linkend, node["target"])
capitalise_xref(node, linkend)
end
|
#annex(docxml) ⇒ Object
21
22
23
24
25
|
# File 'lib/isodoc/presentation_function/section.rb', line 21
def annex(docxml)
docxml.xpath(ns("//annex")).each do |f|
annex1(f)
end
end
|
#annex1(f) ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/isodoc/presentation_function/section.rb', line 27
def annex1(f)
lbl = @xrefs.anchor(f['id'], :label)
if t = f.at(ns("./title"))
t.children = "<strong>#{t.children.to_xml}</strong>"
end
prefix_name(f, "<br/><br/>", lbl, "title")
end
|
#bibdata(docxml) ⇒ Object
3
4
5
6
7
8
9
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 3
def bibdata(docxml)
a = bibdata_current(docxml) or return
bibdata_i18n(a)
a.next =
"<localized-strings>#{i8n_name(trim_hash(@i18n.get), "").join("")}"\
"</localized-strings>"
end
|
#bibdata_current(docxml) ⇒ Object
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 11
def bibdata_current(docxml)
a = docxml.at(ns("//bibdata")) or return
a.xpath(ns("./language")).each do |l|
l.text == @lang and l["current"] = "true"
end
a.xpath(ns("./script")).each do |l|
l.text == @script and l["current"] = "true"
end
a
end
|
#bibdata_i18n(b) ⇒ Object
22
23
24
25
26
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 22
def bibdata_i18n(b)
hash_translate(b, @i18n.get["doctype_dict"], "./ext/doctype")
hash_translate(b, @i18n.get["stage_dict"], "./status/stage")
hash_translate(b, @i18n.get["substage_dict"], "./status/substage")
end
|
#blank?(v) ⇒ Boolean
71
72
73
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 71
def blank?(v)
v.nil? || v.respond_to?(:empty?) && v.empty?
end
|
#block(docxml) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 35
def block(docxml)
amend docxml
table docxml
figure docxml
sourcecode docxml
formula docxml
example docxml
termexample docxml
note docxml
termnote docxml
permission docxml
requirement docxml
recommendation docxml
end
|
#capitalise_xref(node, linkend) ⇒ Object
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/isodoc/presentation_function/inline.rb', line 29
def capitalise_xref(node, linkend)
return linkend unless %w(Latn Cyrl Grek).include? @script
return linkend&.capitalize if node["case"] == "capital"
return linkend&.downcase if node["case"] == "lowercase"
return linkend if linkend[0,1].match(/\p{Upper}/)
prec = nearest_block_parent(node).xpath("./descendant-or-self::text()") &
node.xpath("./preceding::text()")
(prec.empty? || /(?!<[^.].)\.\s+$/.match(prec.map { |p| p.text }.join)) ?
linkend&.capitalize : linkend
end
|
#clause(docxml) ⇒ Object
3
4
5
6
7
8
9
|
# File 'lib/isodoc/presentation_function/section.rb', line 3
def clause(docxml)
docxml.xpath(ns("//clause | "\
"//terms | //definitions | //references")).
each do |f|
clause1(f)
end
end
|
#clause1(f) ⇒ Object
11
12
13
14
15
16
17
18
19
|
# File 'lib/isodoc/presentation_function/section.rb', line 11
def clause1(f)
level = @xrefs.anchor(f['id'], :level, false) || "1"
t = f.at(ns("./title")) and t["depth"] = level
return if !f.ancestors("boilerplate").empty?
return if @suppressheadingnumbers || f["unnumbered"]
lbl = @xrefs.anchor(f['id'], :label,
f.parent.name != "sections") or return
prefix_name(f, "<tab/>", "#{lbl}#{clausedelim}", "title")
end
|
#conversions(docxml) ⇒ Object
22
23
24
25
26
27
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 22
def conversions(docxml)
bibdata docxml
section docxml
block docxml
inline docxml
end
|
#convert1(docxml, filename, dir) ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 14
def convert1(docxml, filename, dir)
@xrefs.parse docxml
info docxml, nil
conversions(docxml)
docxml.root["type"] = "presentation"
docxml.to_xml
end
|
#eref(docxml) ⇒ Object
122
123
124
125
126
|
# File 'lib/isodoc/presentation_function/inline.rb', line 122
def eref(docxml)
docxml.xpath(ns("//eref")).each do |f|
xref1(f)
end
end
|
#eref_localities(refs, target) ⇒ Object
so not <origin bibitemid=“ISO7301” citeas=“ISO 7301”> <locality type=“section”><reference>3.1</reference></locality></origin>
65
66
67
68
69
70
71
72
73
|
# File 'lib/isodoc/presentation_function/inline.rb', line 65
def eref_localities(refs, target)
ret = ""
refs.each_with_index do |r, i|
delim = ","
delim = ";" if r.name == "localityStack" && i>0
ret = eref_locality_stack(r, i, target, delim, ret)
end
ret
end
|
#eref_localities0(r, i, target, delim) ⇒ Object
87
88
89
90
91
92
93
|
# File 'lib/isodoc/presentation_function/inline.rb', line 87
def eref_localities0(r, i, target, delim)
if r["type"] == "whole" then l10n("#{delim} #{@i18n.wholeoftext}")
else
eref_localities1(target, r["type"], r.at(ns("./referenceFrom")),
r.at(ns("./referenceTo")), delim, @lang)
end
end
|
#eref_localities1(target, type, from, to, delim, lang = "en") ⇒ Object
TODO: move to localization file
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/isodoc/presentation_function/inline.rb', line 105
def eref_localities1(target, type, from, to, delim, lang = "en")
return "" if type == "anchor"
return l10n(eref_localities1_zh(target, type, from, to, delim)) if lang == "zh"
ret = delim
loc = @i18n.locality[type] || type.sub(/^locality:/, "").capitalize
ret += " #{loc}"
ret += " #{from.text}" if from
ret += "–#{to.text}" if to
l10n(ret)
end
|
#eref_localities1_zh(target, type, from, to, delim) ⇒ Object
TODO: move to localization file
96
97
98
99
100
101
102
|
# File 'lib/isodoc/presentation_function/inline.rb', line 96
def eref_localities1_zh(target, type, from, to, delim)
ret = "#{delim} 第#{from.text}" if from
ret += "–#{to.text}" if to
loc = (@i18n.locality[type] || type.sub(/^locality:/, "").capitalize )
ret += " #{loc}"
ret
end
|
#eref_locality_stack(r, i, target, delim, ret) ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/isodoc/presentation_function/inline.rb', line 75
def eref_locality_stack(r, i, target, delim, ret)
if r.name == "localityStack"
r.elements.each_with_index do |rr, j|
ret += eref_localities0(rr, j, target, delim)
delim = ","
end
else
ret += eref_localities0(r, i, target, delim)
end
ret
end
|
#example(docxml) ⇒ Object
54
55
56
57
58
|
# File 'lib/isodoc/presentation_function/block.rb', line 54
def example(docxml)
docxml.xpath(ns("//example")).each do |f|
example1(f)
end
end
|
#example1(f) ⇒ Object
66
67
68
69
70
71
|
# File 'lib/isodoc/presentation_function/block.rb', line 66
def example1(f)
n = @xrefs.get[f["id"]]
lbl = (n.nil? || n[:label].nil? || n[:label].empty?) ? @i18n.example :
l10n("#{@i18n.example} #{n[:label]}")
prefix_name(f, " — ", lbl, "name")
end
|
3
4
5
6
7
|
# File 'lib/isodoc/presentation_function/block.rb', line 3
def figure(docxml)
docxml.xpath(ns("//figure")).each do |f|
figure1(f)
end
end
|
9
10
11
12
13
14
15
16
|
# File 'lib/isodoc/presentation_function/block.rb', line 9
def figure1(f)
return sourcecode1(f) if f["class"] == "pseudocode" ||
f["type"] == "pseudocode"
return if labelled_ancestor(f) && f.ancestors("figure").empty?
return if f.at(ns("./figure")) and !f.at(ns("./name"))
lbl = @xrefs.anchor(f['id'], :label, false) or return
prefix_name(f, " — ", l10n("#{@i18n.figure} #{lbl}"), "name")
end
|
42
43
44
45
46
|
# File 'lib/isodoc/presentation_function/block.rb', line 42
def formula(docxml)
docxml.xpath(ns("//formula")).each do |f|
formula1(f)
end
end
|
49
50
51
52
|
# File 'lib/isodoc/presentation_function/block.rb', line 49
def formula1(f)
lbl = @xrefs.anchor(f['id'], :label, false)
prefix_name(f, "", lbl, "name")
end
|
#get_linkend(node) ⇒ Object
54
55
56
57
58
59
60
61
|
# File 'lib/isodoc/presentation_function/inline.rb', line 54
def get_linkend(node)
contents = non_locality_elems(node).select { |c| !c.text? || /\S/.match(c) }
return unless contents.empty?
link = anchor_linkend(node, docid_l10n(node["target"] || node["citeas"]))
link += eref_localities(node.xpath(ns("./locality | ./localityStack")), link)
non_locality_elems(node).each { |n| n.remove }
node.add_child(link)
end
|
#hash_translate(bibdata, hash, xpath) ⇒ Object
28
29
30
31
32
33
34
35
36
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 28
def hash_translate(bibdata, hash, xpath)
x = bibdata.at(ns(xpath)) or return
x["language"] = ""
hash.is_a? Hash or return
hash[x.text] or return
x.next = x.dup
x.next["language"] = @lang
x.next.children = hash[x.text]
end
|
#i18n_safe(k) ⇒ Object
42
43
44
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 42
def i18n_safe(k)
k.gsub(/\s|\./, "_")
end
|
#i18n_tag(k, v) ⇒ Object
38
39
40
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 38
def i18n_tag(k, v)
"<localized-string key='#{k}' language='#{@lang}'>#{v}</localized-string>"
end
|
#i8n_name(h, pref) ⇒ Object
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 46
def i8n_name(h, pref)
if h.is_a? Hash then i8n_name1(h, pref)
elsif h.is_a? Array
h.reject { |a| blank?(a) }.each_with_object([]).
with_index do |(v1, g), i|
i8n_name(v1, "#{i18n_safe(k)}.#{i}").each { |x| g << x }
end
else [i18n_tag(pref, h)]
end
end
|
#i8n_name1(h, pref) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 57
def i8n_name1(h, pref)
h.reject { |k, v| blank?(v) }.each_with_object([]) do |(k, v), g|
if v.is_a? Hash then i8n_name(v, i18n_safe(k)).each { |x| g << x }
elsif v.is_a? Array
v.reject { |a| blank?(a) }.each_with_index do |v1, i|
i8n_name(v1, "#{i18n_safe(k)}.#{i}").each { |x| g << x }
end
else
g << i18n_tag("#{pref}#{pref.empty? ? "" : "."}#{i18n_safe(k)}", v)
end
end
end
|
#inline(docxml) ⇒ Object
50
51
52
53
54
55
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 50
def inline(docxml)
xref docxml
eref docxml
origin docxml
quotesource docxml
end
|
#nearest_block_parent(node) ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/isodoc/presentation_function/inline.rb', line 40
def nearest_block_parent(node)
until %w(p title td th name formula
li dt dd sourcecode pre).include?(node.name)
node = node.parent
end
node
end
|
#non_locality_elems(node) ⇒ Object
48
49
50
51
52
|
# File 'lib/isodoc/presentation_function/inline.rb', line 48
def non_locality_elems(node)
node.children.select do |c|
!%w{locality localityStack}.include? c.name
end
end
|
#note(docxml) ⇒ Object
73
74
75
76
77
|
# File 'lib/isodoc/presentation_function/block.rb', line 73
def note(docxml)
docxml.xpath(ns("//note")).each do |f|
note1(f)
end
end
|
#note1(f) ⇒ Object
80
81
82
83
84
85
86
|
# File 'lib/isodoc/presentation_function/block.rb', line 80
def note1(f)
return if f.parent.name == "bibitem"
n = @xrefs.get[f["id"]]
lbl = (@i18n.note if n.nil? || n[:label].nil? || n[:label].empty?) ?
@i18n.note : l10n("#{@i18n.note} #{n[:label]}")
prefix_name(f, "", lbl, "name")
end
|
#origin(docxml) ⇒ Object
128
129
130
131
132
|
# File 'lib/isodoc/presentation_function/inline.rb', line 128
def origin(docxml)
docxml.xpath(ns("//origin[not(termref)]")).each do |f|
xref1(f)
end
end
|
#permission(docxml) ⇒ Object
112
113
114
115
116
|
# File 'lib/isodoc/presentation_function/block.rb', line 112
def permission(docxml)
docxml.xpath(ns("//permission")).each do |f|
recommendation1(f, @i18n.permission)
end
end
|
#postprocess(result, filename, dir) ⇒ Object
57
58
59
60
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 57
def postprocess(result, filename, dir)
toXML(result, filename)
@files_to_delete.each { |f| FileUtils.rm_rf f }
end
|
#prefix_container(container, linkend, _target) ⇒ Object
3
4
5
|
# File 'lib/isodoc/presentation_function/inline.rb', line 3
def prefix_container(container, linkend, _target)
l10n(@xrefs.anchor(container, :xref) + ", " + linkend)
end
|
#prefix_name(f, delim, number, elem) ⇒ Object
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/isodoc/presentation_function/block.rb', line 18
def prefix_name(f, delim, number, elem)
return if number.nil? || number.empty?
unless name = f.at(ns("./#{elem}"))
f.children.empty? and f.add_child("<#{elem}></#{elem}>") or
f.children.first.previous = "<#{elem}></#{elem}>"
name = f.children.first
end
name.children.empty? ? name.add_child(number) :
( name.children.first.previous = "#{number}#{delim}" )
end
|
#quotesource(docxml) ⇒ Object
134
135
136
137
138
|
# File 'lib/isodoc/presentation_function/inline.rb', line 134
def quotesource(docxml)
docxml.xpath(ns("//quote/source")).each do |f|
xref1(f)
end
end
|
#recommendation(docxml) ⇒ Object
100
101
102
103
104
|
# File 'lib/isodoc/presentation_function/block.rb', line 100
def recommendation(docxml)
docxml.xpath(ns("//recommendation")).each do |f|
recommendation1(f, @i18n.recommendation)
end
end
|
#recommendation1(f, type) ⇒ Object
119
120
121
122
123
|
# File 'lib/isodoc/presentation_function/block.rb', line 119
def recommendation1(f, type)
n = @xrefs.anchor(f['id'], :label, false)
lbl = (n.nil? ? type : l10n("#{type} #{n}"))
prefix_name(f, "", lbl, "name")
end
|
#requirement(docxml) ⇒ Object
106
107
108
109
110
|
# File 'lib/isodoc/presentation_function/block.rb', line 106
def requirement(docxml)
docxml.xpath(ns("//requirement")).each do |f|
recommendation1(f, @i18n.requirement)
end
end
|
#section(docxml) ⇒ Object
29
30
31
32
33
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 29
def section(docxml)
clause docxml
annex docxml
term docxml
end
|
#sourcecode(docxml) ⇒ Object
29
30
31
32
33
|
# File 'lib/isodoc/presentation_function/block.rb', line 29
def sourcecode(docxml)
docxml.xpath(ns("//sourcecode")).each do |f|
sourcecode1(f)
end
end
|
#sourcecode1(f) ⇒ Object
35
36
37
38
39
40
|
# File 'lib/isodoc/presentation_function/block.rb', line 35
def sourcecode1(f)
return if labelled_ancestor(f)
return unless f.ancestors("example").empty?
lbl = @xrefs.anchor(f['id'], :label, false) or return
prefix_name(f, " — ", l10n("#{@i18n.figure} #{lbl}"), "name")
end
|
#table(docxml) ⇒ Object
125
126
127
128
129
|
# File 'lib/isodoc/presentation_function/block.rb', line 125
def table(docxml)
docxml.xpath(ns("//table")).each do |f|
table1(f)
end
end
|
#table1(f) ⇒ Object
131
132
133
134
135
136
|
# File 'lib/isodoc/presentation_function/block.rb', line 131
def table1(f)
return if labelled_ancestor(f)
return if f["unnumbered"] && !f.at(ns("./name"))
n = @xrefs.anchor(f['id'], :label, false)
prefix_name(f, " — ", l10n("#{@i18n.table} #{n}"), "name")
end
|
#term(docxml) ⇒ Object
35
36
37
38
39
|
# File 'lib/isodoc/presentation_function/section.rb', line 35
def term(docxml)
docxml.xpath(ns("//term")).each do |f|
term1(f)
end
end
|
#term1(f) ⇒ Object
41
42
43
44
|
# File 'lib/isodoc/presentation_function/section.rb', line 41
def term1(f)
lbl = @xrefs.get[f["id"]][:label] or return
prefix_name(f, "", "#{lbl}#{clausedelim}", "name")
end
|
#termexample(docxml) ⇒ Object
60
61
62
63
64
|
# File 'lib/isodoc/presentation_function/block.rb', line 60
def termexample(docxml)
docxml.xpath(ns("//termexample")).each do |f|
example1(f)
end
end
|
#termnote(docxml) ⇒ Object
88
89
90
91
92
|
# File 'lib/isodoc/presentation_function/block.rb', line 88
def termnote(docxml)
docxml.xpath(ns("//termnote")).each do |f|
termnote1(f)
end
end
|
#termnote1(f) ⇒ Object
95
96
97
98
|
# File 'lib/isodoc/presentation_function/block.rb', line 95
def termnote1(f)
lbl = l10n(@xrefs.anchor(f['id'], :label) || '???')
prefix_name(f, "", lbl, "name")
end
|
#toXML(result, filename) ⇒ Object
62
63
64
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 62
def toXML(result, filename)
File.open(filename, "w:UTF-8") { |f| f.write(result) }
end
|
#trim_hash(h) ⇒ Object
75
76
77
78
79
80
81
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 75
def trim_hash(h)
loop do
h_new = trim_hash1(h)
break h if h==h_new
h = h_new
end
end
|
#trim_hash1(h) ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 83
def trim_hash1(h)
return h unless h.is_a? Hash
h.each_with_object({}) do |(k,v), g|
next if blank?(v)
g[k] = if v.is_a? Hash then trim_hash1(h[k])
elsif v.is_a? Array
h[k].map { |a| trim_hash1(a) }.reject { |a| blank?(a) }
else
v
end
end
end
|
#xref(docxml) ⇒ Object
116
117
118
119
120
|
# File 'lib/isodoc/presentation_function/inline.rb', line 116
def xref(docxml)
docxml.xpath(ns("//xref")).each do |f|
xref1(f)
end
end
|
#xref1(f) ⇒ Object
140
141
142
|
# File 'lib/isodoc/presentation_function/inline.rb', line 140
def xref1(f)
get_linkend(f)
end
|