Class: IsoDoc::PresentationXMLConvert
- Inherits:
-
Convert
show all
- Defined in:
- lib/isodoc/presentation_xml_convert.rb,
lib/isodoc/presentation_function/math.rb,
lib/isodoc/presentation_function/refs.rb,
lib/isodoc/presentation_function/block.rb,
lib/isodoc/presentation_function/image.rb,
lib/isodoc/presentation_function/terms.rb,
lib/isodoc/presentation_function/xrefs.rb,
lib/isodoc/presentation_function/inline.rb,
lib/isodoc/presentation_function/bibdata.rb,
lib/isodoc/presentation_function/section.rb
Constant Summary
collapse
- MATHML =
{ "m" => "http://www.w3.org/1998/Math/MathML" }.freeze
- REQS =
%w(requirement recommendation permission).freeze
- SVG =
{ "m" => "http://www.w3.org/2000/svg" }.freeze
Function::Utils::CLAUSE_ANCESTOR, Function::Utils::DOCTYPE_HDR, 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, #meta, #options, #reqt_models, #requirements_processor, #xrefs
Instance Method Summary
collapse
-
#address_precompose(bib) ⇒ Object
-
#address_precompose1(addr) ⇒ Object
-
#admonition(docxml) ⇒ Object
-
#admonition1(elem) ⇒ Object
-
#amend(docxml) ⇒ Object
we use this to eliminate the semantic amend blocks from rendering.
-
#amend1(elem) ⇒ Object
-
#anchor_linkend(node, linkend) ⇒ Object
-
#anchor_linkend1(node) ⇒ Object
-
#anchor_value(id) ⇒ Object
-
#anchor_xref(node, target) ⇒ Object
-
#annex(docxml) ⇒ Object
-
#annex1(elem) ⇒ Object
-
#asciimath_dup(node) ⇒ Object
-
#bibdata(docxml) ⇒ Object
-
#bibdata_current(docxml) ⇒ Object
-
#bibdata_i18n(bib) ⇒ Object
-
#bibitem(xml, renderings) ⇒ Object
-
#bibliography_bibitem_number(docxml) ⇒ Object
-
#bibliography_bibitem_number1(bibitem, idx) ⇒ Object
-
#bibliography_bibitem_number_insert_pt(bibitem) ⇒ Object
-
#bibliography_bibitem_number_skip(bibitem) ⇒ Object
-
#bibrender(xml, renderings) ⇒ Object
-
#bibrender_formattedref(formattedref, xml) ⇒ Object
-
#bibrender_relaton(xml, renderings) ⇒ Object
-
#bibrenderer ⇒ Object
-
#blank?(elem) ⇒ Boolean
-
#block(docxml) ⇒ Object
-
#block_delim ⇒ Object
-
#cache_dataimage(uri) ⇒ Object
-
#can_conflate_eref_rendering?(refs) ⇒ Boolean
-
#can_conflate_xref_rendering?(locs) ⇒ Boolean
-
#capitalise_xref(node, linkend, label) ⇒ Object
-
#capitalise_xref1(node, linkend) ⇒ Object
-
#citestyle ⇒ Object
-
#clause(docxml) ⇒ Object
-
#clause1(elem) ⇒ Object
-
#clausetitle(docxml) ⇒ Object
-
#combine_conflated_xref_locations(locs) ⇒ Object
-
#combine_conn(list) ⇒ Object
-
#combine_xref_locations(node) ⇒ Object
-
#concept(docxml) ⇒ Object
-
#concept1(node) ⇒ Object
-
#concept1_linkmention(ref, renderterm, opts) ⇒ Object
-
#concept1_nonital(node, opts) ⇒ Object
-
#concept1_ref(_node, ref, opts) ⇒ Object
-
#concept1_ref_content(ref) ⇒ Object
-
#concept_render(node, defaults) ⇒ Object
-
#concept_render_init(node, defaults) ⇒ Object
-
#conversions(docxml) ⇒ Object
-
#convert1(docxml, _filename, _dir) ⇒ Object
-
#decorate_fraction_part(fract, locale) ⇒ Object
-
#designation(docxml) ⇒ Object
-
#designation1(desgn) ⇒ Object
-
#designation_annotate(desgn, name) ⇒ Object
-
#designation_boldface(desgn) ⇒ Object
-
#designation_field(desgn, name) ⇒ Object
-
#designation_grammar(grammar) ⇒ Object
-
#designation_localization(desgn, name) ⇒ Object
-
#designation_pronunciation(desgn, name) ⇒ Object
-
#display_order(docxml) ⇒ Object
-
#display_order_at(docxml, xpath, idx) ⇒ Object
-
#display_order_xpath(docxml, xpath, idx) ⇒ Object
-
#docid_prefixes(docxml) ⇒ Object
-
#edition_translate(bibdata) ⇒ Object
does not allow %Spellout and %Ordinal in the ordinal expression to be mixed.
-
#edition_translate1(num) ⇒ Object
-
#emf_encode(img) ⇒ Object
-
#emf_to_svg(img) ⇒ Object
-
#eps2svg(img) ⇒ Object
-
#eps_to_svg(node) ⇒ Object
-
#eps_to_svg_uri(node) ⇒ Object
-
#eps_to_svg_uri_convert(node) ⇒ Object
-
#eref(docxml) ⇒ Object
-
#eref_localities(refs, target, node) ⇒ Object
-
#eref_localities0(ref, _idx, target, node) ⇒ Object
-
#eref_localities1(target, type, from, upto, node, lang = "en") ⇒ Object
TODO: move to localization file.
-
#eref_localities1_zh(_target, type, from, upto, node) ⇒ Object
TODO: move to localization file.
-
#eref_localities_conflated(refs, target, node) ⇒ Object
-
#eref_locality_delimiter(ref) ⇒ Object
-
#eref_locality_populate(type, node) ⇒ Object
-
#eref_locality_stack(ref, idx, target, node) ⇒ Object
-
#eref_locality_stacks(refs, target, node) ⇒ Object
-
#example(docxml) ⇒ Object
-
#example1(elem) ⇒ Object
-
#expand_citeas(text) ⇒ Object
so not <origin bibitemid=“ISO7301” citeas=“ISO 7301”> <locality type=“section”><reference>3.1</reference></locality></origin>.
-
#figure(docxml) ⇒ Object
-
#figure1(elem) ⇒ Object
-
#figure_label(elem) ⇒ Object
-
#floattitle(docxml) ⇒ Object
-
#floattitle1(elem) ⇒ Object
-
#fonts_metadata(xmldoc) ⇒ Object
-
#formula(docxml) ⇒ Object
-
#formula1(elem) ⇒ Object
-
#gather_xref_locations(node) ⇒ Object
-
#get_linkend(node) ⇒ Object
-
#hash_translate(bibdata, hash, xpath, lang = @lang) ⇒ Object
-
#i18n_chain_boolean(value, entry) ⇒ Object
-
#i18n_safe(key) ⇒ Object
-
#i18n_tag(key, value) ⇒ Object
-
#i8n_name(hash, pref) ⇒ Object
-
#i8n_name1(hash, pref) ⇒ Object
-
#identifier(docxml) ⇒ Object
-
#imageconvert(docxml) ⇒ Object
-
#imgfile_suffix(uri, suffix) ⇒ Object
-
#index(docxml) ⇒ Object
-
#initialize(options) ⇒ PresentationXMLConvert
constructor
A new instance of PresentationXMLConvert.
-
#inkscape_convert(uri, file, option) ⇒ Object
-
#inkscape_installed? ⇒ Boolean
-
#inline(docxml) ⇒ Object
-
#locality_delimiter(_loc) ⇒ Object
-
#localize_maths(node, locale) ⇒ Object
symbols is merged into TwitterCldr::DataReaders::NumberDataReader.new(locale).symbols.
-
#localized_number(num, locale, precision) ⇒ Object
By itself twitter-cldr does not support fraction part digits grouping and custom delimeter, will decorate fraction part manually.
-
#localized_number1(num, locale, precision) ⇒ Object
-
#lower2cap(text) ⇒ Object
-
#mathml(docxml) ⇒ Object
-
#mathml1(node, locale) ⇒ Object
-
#merge_preferred_eligible?(first, second) ⇒ Boolean
-
#merge_second_preferred(term) ⇒ Object
-
#merge_second_preferred1(pref, second) ⇒ Object
-
#multidef(elem) ⇒ Object
-
#non_locality_elems(node) ⇒ Object
-
#note(docxml) ⇒ Object
-
#note1(elem) ⇒ Object
-
#ol(docxml) ⇒ Object
-
#ol1(elem) ⇒ Object
-
#ol_depth(node) ⇒ Object
We don’t really want users to specify type of ordered list; we will use by default a fixed hierarchy as practiced by ISO (though not fully spelled out): a) 1) i) A) I).
-
#origin(docxml) ⇒ Object
-
#parse_localize_number ⇒ Object
-
#permission(docxml) ⇒ Object
-
#postprocess(result, filename, _dir) ⇒ Object
-
#prefix_container(container, linkend, node, _target) ⇒ Object
-
#prefix_container?(container, node) ⇒ Boolean
-
#prefix_name(node, delim, number, elem) ⇒ Object
-
#prep_for_rendering(bib) ⇒ Object
-
#presmeta(name, value) ⇒ Object
-
#quotesource(docxml) ⇒ Object
-
#recommendation(docxml) ⇒ Object
-
#recommendation1(elem, type) ⇒ Object
-
#references(docxml) ⇒ Object
-
#references_render(docxml) ⇒ Object
-
#related(docxml) ⇒ Object
-
#related1(node) ⇒ Object
-
#requirement(docxml) ⇒ Object
-
#requirement_render(docxml) ⇒ Object
-
#requirement_render1(node) ⇒ Object
-
#requirement_render_preprocessing(docxml) ⇒ Object
-
#resolve_comma_connectives(locs) ⇒ Object
-
#resolve_eref_connectives(locs) ⇒ Object
-
#resolve_to_connectives(locs) ⇒ Object
-
#section(docxml) ⇒ Object
parse annex after term, references, to deal with single-term and single-ref annexes.
-
#single_term_clause(elem) ⇒ Object
-
#sourcecode(docxml) ⇒ Object
-
#sourcecode1(elem) ⇒ Object
-
#svg_emf_double(img) ⇒ Object
-
#svg_extract(elem) ⇒ Object
-
#svg_prep(img) ⇒ Object
-
#svg_to_emf(node) ⇒ Object
-
#svg_to_emf_uri(node) ⇒ Object
-
#svg_to_emf_uri_convert(node) ⇒ Object
-
#svg_wrap(elem) ⇒ Object
-
#svgmap_extract(elem) ⇒ Object
-
#table(docxml) ⇒ Object
-
#table1(elem) ⇒ Object
-
#tag_translate(tag, lang, value) ⇒ Object
-
#term(docxml) ⇒ Object
-
#term1(elem) ⇒ Object
-
#termdefinition(docxml) ⇒ Object
-
#termdefinition1(elem) ⇒ Object
-
#termexample(docxml) ⇒ Object
-
#termnote(docxml) ⇒ Object
-
#termnote1(elem) ⇒ Object
-
#terms(docxml) ⇒ Object
-
#termsource(docxml) ⇒ Object
-
#termsource1(elem) ⇒ Object
-
#termsource_modification(mod) ⇒ Object
-
#to_xml(result, filename) ⇒ Object
-
#toc(docxml) ⇒ Object
-
#toc_metadata(docxml) ⇒ Object
-
#trim_hash(hash) ⇒ Object
-
#trim_hash1(hash) ⇒ Object
-
#twitter_cldr_localiser ⇒ Object
-
#twitter_cldr_localiser_symbols ⇒ Object
-
#twitter_cldr_reader(locale) ⇒ Object
-
#unwrap_definition(elem) ⇒ Object
-
#variant(docxml) ⇒ Object
-
#variant1(node) ⇒ Object
-
#xref(docxml) ⇒ Object
-
#xref1(node) ⇒ Object
Methods inherited from Convert
#bibitem_lookup, #convert, #convert_i18n_init, #convert_init, #convert_scss, #default_file_locations, #default_fonts, #fonts_options, #generate_css, #html_doc_path, #i18n_init, #init_covers, #init_fonts, #init_i18n, #init_locations, #init_processing, #init_rendering, #init_stylesheets, #init_toc, #l10n, #localpath, #metadata_init, #middle_clause, #options_preprocess, #populate_css, #precompiled_style_or_original, #scss_fontheader, #target_pdf, #tmpfilesdir_suffix, #tmpimagedir_suffix, #xref_init
Methods included from ClassUtils
#case_strict, #case_strict1, #case_with_markup, #date_range, #liquid, #nearest_block_parent, #ns, #start_of_sentence
#attr_code, #cleanup_entities, #date_range, #emf?, #empty2nil, #eps?, #external_path, #extract_delims, #from_xhtml, #get_clause_id, #get_note_container_id, #header_strip, #header_strip_elem?, #image_localfile, #insert_tab, #labelled_ancestor, #liquid, #noko, #ns, #numeric_escapes, #populate_template, #save_dataimage, #save_svg, #sentence_join, #start_of_sentence, #to_xhtml, #to_xhtml_fragment, #to_xhtml_prep
#body_attr, #boilerplate, #define_head, #in_sourcecode, #info, #init_dir, #init_file, #make_body, #make_body1, #make_body2, #make_body3, #middle, #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
#colgroup, #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_subtitle, #clause_parse_title, #clause_parse_title1, #clause_title_depth, #clausedelim, #clausedelimspace, #copyright_parse, #feedback_parse, #foreword, #inline_header_title, #introduction, #is_clause?, #legal_parse, #license_parse, #preceding_floating_titles, #preface, #preface_block, #scope, #single_term_clause?, #symbols_abbrevs, #symbols_parse, #terms_defs, #terms_parse, #variant_title
#bibitem_ref_code, #biblio_list, #bibliography, #bibliography_parse, #bibliography_xpath, #bracket_if_num, #date_note_process, #docid_l10n, #docid_prefix, #implicit_reference, #iso_bibitem_entry_attrs, #nonstd_bibitem, #norm_ref, #norm_ref_xpath, #omit_docid_prefix, #pref_ref_code, #prefix_bracketed_ref, #ref_entry_code, #reference_format, #render_identifier, #standard?, #std_bibitem_entry, #unbracket, #unbracket1
#dl_attrs, #dl_parse, #dl_parse1, #dt_dd?, #dt_parse, #li_parse, #list_title_parse, #ol_attrs, #ol_parse, #ol_style, #ul_attrs, #ul_parse
#add_parse, #asciimath_parse, #bookmark_parse, #br_parse, #callout_parse, #del_parse, #em_parse, #eref_parse, #eref_target, #eref_url, #error_parse, #hr_parse, #image_parse, #image_title_parse, #index_parse, #index_xref_parse, #keyword_parse, #latexmath_parse, #link_parse, #location_parse, #mathml_parse, #no_locality_parse, #origin_parse, #page_break, #pagebreak_parse, #section_break, #smallcap_parse, #span_parse, #stem_parse, #strike_parse, #strong_parse, #sub_parse, #suffix_url, #sup_parse, #termrefelem_parse, #text_parse, #tt_parse, #underline_parse, #xref_parse
#form_parse, #input_parse, #label_parse, #option_parse, #select_parse, #text_input, #textarea_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_cleanup_propagate, #table_footnote_reference_format, #table_get_or_make_tfoot, #table_long_strings_cleanup, #table_note_cleanup, #textcleanup
#admonition_attrs, #admonition_class, #admonition_name, #admonition_name_parse, #admonition_parse, #annotation_parse, #div_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, #figure_parse1, #formula_attrs, #formula_parse, #formula_parse1, #formula_where, #keep_style, #middle_admonitions, #middle_title, #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_name, #recommendation_parse, #recommendation_parse1, #reqt_attrs, #requirement_parse, #sourcecode_attrs, #sourcecode_name_parse, #sourcecode_parse, #svg_parse, #toc_parse
Constructor Details
Returns a new instance of PresentationXMLConvert.
10
11
12
13
14
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 10
def initialize(options)
@format = :presentation
@suffix = "presentation.xml"
super
end
|
Instance Method Details
#address_precompose(bib) ⇒ Object
31
32
33
34
35
36
37
38
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 31
def address_precompose(bib)
bib.xpath(ns("//bibdata//address")).each do |b|
next if b.at(ns("./formattedAddress"))
x = address_precompose1(b)
b.children = "<formattedAddress>#{x}</formattedAddress>"
end
end
|
#address_precompose1(addr) ⇒ Object
57
58
59
60
61
62
63
64
65
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 57
def address_precompose1(addr)
ret = []
addr.xpath(ns("./street")).each { |s| ret << s.children.to_xml }
a = addr.at(ns("./city")) and ret << a.children.to_xml
addr.xpath(ns("./state")).each { |s| ret << s.children.to_xml }
a = addr.at(ns("./country")) and ret << a.children.to_xml
a = addr.at(ns("./postcode")) and ret[-1] += " #{a.children.to_xml}"
ret.join("<br/>")
end
|
#admonition(docxml) ⇒ Object
87
88
89
90
91
|
# File 'lib/isodoc/presentation_function/block.rb', line 87
def admonition(docxml)
docxml.xpath(ns("//admonition")).each do |f|
admonition1(f)
end
end
|
#admonition1(elem) ⇒ Object
93
94
95
96
97
|
# File 'lib/isodoc/presentation_function/block.rb', line 93
def admonition1(elem)
return if elem.at(ns("./name")) || elem["notag"] == "true"
prefix_name(elem, "", @i18n.admonition[elem["type"]]&.upcase, "name")
end
|
#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(elem) ⇒ Object
145
146
147
148
149
150
|
# File 'lib/isodoc/presentation_function/block.rb', line 145
def amend1(elem)
elem.xpath(ns("./autonumber")).each(&:remove)
elem.xpath(ns("./newcontent")).each { |a| a.name = "quote" }
elem.xpath(ns("./description")).each { |a| a.replace(a.children) }
elem.replace(elem.children)
end
|
#anchor_linkend(node, linkend) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 13
def anchor_linkend(node, linkend)
if node["citeas"].nil? && node["bibitemid"]
return @xrefs.anchor(node["bibitemid"], :xref) || "???"
elsif node.at(ns("./location"))
linkend = combine_xref_locations(node)
elsif node["target"] && node["droploc"]
return anchor_value(node["target"]) || "???"
elsif node["target"] && !/.#./.match(node["target"])
linkend = anchor_linkend1(node)
end
linkend || "???"
end
|
#anchor_linkend1(node) ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 27
def anchor_linkend1(node)
linkend = anchor_xref(node, node["target"])
container = @xrefs.anchor(node["target"], :container, false)
prefix_container?(container, node) and
linkend = prefix_container(container, linkend, node, node["target"])
capitalise_xref(node, linkend, anchor_value(node["target"]))
end
|
#anchor_value(id) ⇒ Object
8
9
10
11
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 8
def anchor_value(id)
@xrefs.anchor(id, :value) || @xrefs.anchor(id, :label) ||
@xrefs.anchor(id, :xref)
end
|
#anchor_xref(node, target) ⇒ Object
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 35
def anchor_xref(node, target)
x = @xrefs.anchor(target, :xref)
t = @xrefs.anchor(target, :title)
if node["style"] == "basic" && t then t
elsif node["style"] == "full" && t
l10n("#{x}, #{t}")
else
x
end
end
|
#annex(docxml) ⇒ Object
43
44
45
46
47
48
|
# File 'lib/isodoc/presentation_function/section.rb', line 43
def annex(docxml)
docxml.xpath(ns("//annex")).each do |f|
annex1(f)
@xrefs.klass.single_term_clause?(f) and single_term_clause(f)
end
end
|
#annex1(elem) ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/isodoc/presentation_function/section.rb', line 50
def annex1(elem)
lbl = @xrefs.anchor(elem["id"], :label)
if t = elem.at(ns("./title"))
t.children = "<strong>#{t.children.to_xml}</strong>"
end
prefix_name(elem, "<br/><br/>", lbl, "title")
end
|
#asciimath_dup(node) ⇒ Object
92
93
94
95
96
97
|
# File 'lib/isodoc/presentation_function/math.rb', line 92
def asciimath_dup(node)
return if @suppressasciimathdup
a = MathML2AsciiMath.m2a(node.to_xml)
node.next = "<!-- #{a} -->"
end
|
#bibdata(docxml) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 5
def bibdata(docxml)
toc_metadata(docxml)
fonts_metadata(docxml)
docid_prefixes(docxml)
a = bibdata_current(docxml) or return
address_precompose(a)
bibdata_i18n(a)
a.next =
"<localized-strings>#{i8n_name(trim_hash(@i18n.get), '').join}"\
"</localized-strings>"
end
|
#bibdata_current(docxml) ⇒ Object
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 67
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(bib) ⇒ Object
78
79
80
81
82
83
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 78
def bibdata_i18n(bib)
hash_translate(bib, @i18n.get["doctype_dict"], "./ext/doctype")
hash_translate(bib, @i18n.get["stage_dict"], "./status/stage")
hash_translate(bib, @i18n.get["substage_dict"], "./status/substage")
edition_translate(bib)
end
|
#bibitem(xml, renderings) ⇒ Object
35
36
37
38
|
# File 'lib/isodoc/presentation_function/refs.rb', line 35
def bibitem(xml, renderings)
@xrefs.klass.implicit_reference(xml) and xml["hidden"] = "true"
bibrender(xml, renderings)
end
|
#bibliography_bibitem_number(docxml) ⇒ Object
75
76
77
78
79
80
81
|
# File 'lib/isodoc/presentation_function/refs.rb', line 75
def bibliography_bibitem_number(docxml)
i = 0
docxml.xpath(ns("//references[@normative = 'false']/bibitem")).each do |b|
i = bibliography_bibitem_number1(b, i)
end
@xrefs.references docxml
end
|
#bibliography_bibitem_number1(bibitem, idx) ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/isodoc/presentation_function/refs.rb', line 83
def bibliography_bibitem_number1(bibitem, idx)
ins = bibliography_bibitem_number_insert_pt(bibitem)
mn = bibitem.at(ns(".//docidentifier[@type = 'metanorma']")) and
/^\[?\d+\]?$/.match?(mn.text) and
mn.remove unless bibliography_bibitem_number_skip(bibitem)
idx += 1
ins.next =
"<docidentifier type='metanorma-ordinal'>[#{idx}]</docidentifier>"
end
idx
end
|
#bibliography_bibitem_number_insert_pt(bibitem) ⇒ Object
96
97
98
99
100
101
102
|
# File 'lib/isodoc/presentation_function/refs.rb', line 96
def bibliography_bibitem_number_insert_pt(bibitem)
unless ins = bibitem.at(ns(".//docidentifier")).previous_element
bibitem.at(ns(".//docidentifier")).previous = " "
ins = bibitem.at(ns(".//docidentifier")).previous
end
ins
end
|
#bibliography_bibitem_number_skip(bibitem) ⇒ Object
68
69
70
71
72
73
|
# File 'lib/isodoc/presentation_function/refs.rb', line 68
def bibliography_bibitem_number_skip(bibitem)
@xrefs.klass.implicit_reference(bibitem) ||
bibitem.at(ns(".//docidentifier[@type = 'metanorma']")) ||
bibitem.at(ns(".//docidentifier[@type = 'metanorma-ordinal']")) ||
bibitem["hidden"] == "true" || bibitem.parent["hidden"] == "true"
end
|
#bibrender(xml, renderings) ⇒ Object
40
41
42
43
44
45
|
# File 'lib/isodoc/presentation_function/refs.rb', line 40
def bibrender(xml, renderings)
if f = xml.at(ns("./formattedref"))
bibrender_formattedref(f, xml)
else bibrender_relaton(xml, renderings)
end
end
|
47
48
49
50
51
|
# File 'lib/isodoc/presentation_function/refs.rb', line 47
def bibrender_formattedref(formattedref, xml)
code = render_identifier(bibitem_ref_code(xml))
(code[:sdo] && xml["suppress_identifier"] != "true") and
formattedref << " [#{code[:sdo]}] "
end
|
#bibrender_relaton(xml, renderings) ⇒ Object
53
54
55
56
57
58
|
# File 'lib/isodoc/presentation_function/refs.rb', line 53
def bibrender_relaton(xml, renderings)
f = renderings[xml["id"]][:formattedref]
f &&= "<formattedref>#{f}</formattedref>"
xml.children =
"#{f}#{xml.xpath(ns('./docidentifier | ./uri | ./note')).to_xml}"
end
|
#bibrenderer ⇒ Object
60
61
62
|
# File 'lib/isodoc/presentation_function/refs.rb', line 60
def bibrenderer
::Relaton::Render::IsoDoc::General.new(language: @lang)
end
|
#blank?(elem) ⇒ Boolean
156
157
158
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 156
def blank?(elem)
elem.nil? || (elem.respond_to?(:empty?) && elem.empty?)
end
|
#block(docxml) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 49
def block(docxml)
amend docxml
table docxml
figure docxml
sourcecode docxml
formula docxml
example docxml
note docxml
admonition docxml
ol docxml
permission docxml
requirement docxml
recommendation docxml
requirement_render docxml
end
|
#block_delim ⇒ Object
11
12
13
|
# File 'lib/isodoc/presentation_function/block.rb', line 11
def block_delim
" — "
end
|
#cache_dataimage(uri) ⇒ Object
142
143
144
145
146
147
148
|
# File 'lib/isodoc/presentation_function/image.rb', line 142
def cache_dataimage(uri)
if %r{^data:}.match?(uri)
uri = save_dataimage(uri)
@tempfile_cache << uri
end
uri
end
|
#can_conflate_eref_rendering?(refs) ⇒ Boolean
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/isodoc/presentation_function/inline.rb', line 51
def can_conflate_eref_rendering?(refs)
(refs.size > 1 &&
refs.all? { |r| r.name == "localityStack" } &&
refs.all? { |r| r.xpath(ns("./locality")).size == 1 }) or return false
first = refs.first.at(ns("./locality/@type")).text
refs.all? do |r|
r.at(ns("./locality/@type")).text == first
end
end
|
#can_conflate_xref_rendering?(locs) ⇒ Boolean
104
105
106
107
108
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 104
def can_conflate_xref_rendering?(locs)
(locs.all? { |l| l[:container].nil? } ||
locs.all? { |l| l[:container] == locs.first[:container] }) &&
locs.all? { |l| l[:type] == locs[0][:type] }
end
|
#capitalise_xref(node, linkend, label) ⇒ Object
110
111
112
113
114
115
116
117
118
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 110
def capitalise_xref(node, linkend, label)
linktext = linkend.gsub(/<[^>]+>/, "")
(label && !label.empty? && /^#{Regexp.escape(label)}/.match?(linktext)) ||
linktext[0, 1].match?(/\p{Upper}/) and return linkend
node["case"] and
return Common::case_with_markup(linkend, node["case"], @script)
capitalise_xref1(node, linkend)
end
|
#capitalise_xref1(node, linkend) ⇒ Object
120
121
122
123
124
125
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 120
def capitalise_xref1(node, linkend)
if start_of_sentence(node)
Common::case_with_markup(linkend, "capital", @script)
else linkend
end
end
|
#citestyle ⇒ Object
64
65
66
|
# File 'lib/isodoc/presentation_function/refs.rb', line 64
def citestyle
nil
end
|
#clause(docxml) ⇒ Object
5
6
7
8
9
10
11
|
# File 'lib/isodoc/presentation_function/section.rb', line 5
def clause(docxml)
docxml.xpath(ns("//clause | "\
"//terms | //definitions | //references"))
.each do |f|
clause1(f)
end
end
|
#clause1(elem) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/isodoc/presentation_function/section.rb', line 13
def clause1(elem)
level = @xrefs.anchor(elem["id"], :level, false) ||
(elem.ancestors("clause, annex").size + 1)
t = elem.at(ns("./title")) and t["depth"] = level
return if !elem.ancestors("boilerplate").empty? ||
@suppressheadingnumbers || elem["unnumbered"]
lbl = @xrefs.anchor(elem["id"], :label,
elem.parent.name != "sections") or return
prefix_name(elem, "<tab/>", "#{lbl}#{clausedelim}", "title")
end
|
#clausetitle(docxml) ⇒ Object
113
|
# File 'lib/isodoc/presentation_function/section.rb', line 113
def clausetitle(docxml); end
|
#combine_conflated_xref_locations(locs) ⇒ Object
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 64
def combine_conflated_xref_locations(locs)
out = locs.each { |l| l[:target] = anchor_value(l[:target]) }
ret = l10n("#{locs.first[:elem]} #{combine_conn(out)}")
container = @xrefs.anchor(locs.first[:node]["target"], :container,
false)
prefix_container?(container, locs.first[:node]) and
ret = prefix_container(container, ret, locs.first[:node],
locs.first[:node]["target"])
ret
end
|
#combine_conn(list) ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 85
def combine_conn(list)
return list.first[:target] if list.size == 1
if list[1..-1].all? { |l| l[:conn] == "and" }
@i18n.boolean_conj(list.map { |l| l[:target] }, "and")
elsif list[1..-1].all? { |l| l[:conn] == "or" }
@i18n.boolean_conj(list.map { |l| l[:target] }, "or")
else
ret = list[0][:target]
list[1..-1].each { |l| ret = i18n_chain_boolean(ret, l) }
ret
end
end
|
#combine_xref_locations(node) ⇒ Object
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 53
def combine_xref_locations(node)
locs = gather_xref_locations(node)
linkend = if can_conflate_xref_rendering?(locs)
combine_conflated_xref_locations(locs)
else
out = locs.each { |l| l[:target] = anchor_linkend1(l[:node]) }
l10n(combine_conn(out))
end
capitalise_xref(node, linkend, anchor_value(node["target"]))
end
|
#concept(docxml) ⇒ Object
3
4
5
|
# File 'lib/isodoc/presentation_function/terms.rb', line 3
def concept(docxml)
docxml.xpath(ns("//concept")).each { |f| concept1(f) }
end
|
#concept1(node) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/isodoc/presentation_function/terms.rb', line 7
def concept1(node)
xref = node&.at(ns("./xref/@target"))&.text or
return concept_render(node, ital: "true", ref: "true",
linkref: "true", linkmention: "false")
if node.at(ns("//definitions//dt[@id = '#{xref}']"))
concept_render(node, ital: "false", ref: "false",
linkref: "true", linkmention: "false")
else concept_render(node, ital: "true", ref: "true",
linkref: "true", linkmention: "false")
end
end
|
#concept1_linkmention(ref, renderterm, opts) ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/isodoc/presentation_function/terms.rb', line 44
def concept1_linkmention(ref, renderterm, opts)
return unless opts[:linkmention] == "true" && !renderterm.nil? && !ref.nil?
ref2 = ref.clone
r2 = renderterm.clone
renderterm.replace(ref2).children = r2
end
|
#concept1_nonital(node, opts) ⇒ Object
30
31
32
33
34
|
# File 'lib/isodoc/presentation_function/terms.rb', line 30
def concept1_nonital(node, opts)
opts[:ital] == "false" or return
r = node.at(ns(".//renderterm"))
r&.replace(r&.children)
end
|
#concept1_ref(_node, ref, opts) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/isodoc/presentation_function/terms.rb', line 52
def concept1_ref(_node, ref, opts)
ref.nil? and return
return ref.remove if opts[:ref] == "false"
r = concept1_ref_content(ref)
ref = r.at("./descendant-or-self::xmlns:xref | "\
"./descendant-or-self::xmlns:eref | "\
"./descendant-or-self::xmlns:termref")
%w(xref eref).include? ref&.name and get_linkend(ref)
if opts[:linkref] == "false" && %w(xref eref).include?(ref&.name)
ref.replace(ref.children)
end
end
|
#concept1_ref_content(ref) ⇒ Object
66
67
68
69
70
71
72
73
74
|
# File 'lib/isodoc/presentation_function/terms.rb', line 66
def concept1_ref_content(ref)
if non_locality_elems(ref).select do |c|
!c.text? || /\S/.match(c)
end.empty?
ref.replace(@i18n.term_defined_in.sub(/%/,
ref.to_xml))
else ref.replace("[#{ref.to_xml}]")
end
end
|
#concept_render(node, defaults) ⇒ Object
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/isodoc/presentation_function/terms.rb', line 19
def concept_render(node, defaults)
opts, render, ref = concept_render_init(node, defaults)
node&.at(ns("./refterm"))&.remove
ref && opts[:ref] != "false" and render&.next = " "
opts[:ital] == "true" and render&.name = "em"
concept1_linkmention(ref, render, opts)
concept1_ref(node, ref, opts)
concept1_nonital(node, opts)
node.replace(node.children)
end
|
#concept_render_init(node, defaults) ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/isodoc/presentation_function/terms.rb', line 36
def concept_render_init(node, defaults)
opts = %i(ital ref linkref linkmention).each_with_object({}) do |x, m|
m[x] = node[x.to_s] || defaults[x]
end
[opts, node.at(ns("./renderterm")),
node.at(ns("./xref | ./eref | ./termref"))]
end
|
#conversions(docxml) ⇒ Object
24
25
26
27
28
29
30
31
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 24
def conversions(docxml)
bibdata docxml
@xrefs.parse docxml
section docxml
block docxml
terms docxml
inline docxml
end
|
#convert1(docxml, _filename, _dir) ⇒ Object
16
17
18
19
20
21
22
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 16
def convert1(docxml, _filename, _dir)
@xrefs.parse docxml
info docxml, nil
conversions(docxml)
docxml.root["type"] = "presentation"
docxml.to_xml.gsub(/</, "<").gsub(/>/, ">")
end
|
#decorate_fraction_part(fract, locale) ⇒ Object
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/isodoc/presentation_function/math.rb', line 49
def decorate_fraction_part(fract, locale)
result = []
= (locale)
fract = fract.slice(0..([:precision] || -1))
fr_group_digits = [:fraction_group_digits] || 1
until fract.empty?
result.push(fract.slice!(0, fr_group_digits))
end
result.join([:fraction_group].to_s)
end
|
#designation(docxml) ⇒ Object
93
94
95
96
97
98
|
# File 'lib/isodoc/presentation_function/terms.rb', line 93
def designation(docxml)
docxml.xpath(ns("//term")).each { |t| merge_second_preferred(t) }
docxml.xpath(ns("//preferred | //admitted | //deprecates")).each do |p|
designation1(p)
end
end
|
#designation1(desgn) ⇒ Object
126
127
128
129
130
131
132
133
|
# File 'lib/isodoc/presentation_function/terms.rb', line 126
def designation1(desgn)
s = desgn.at(ns("./termsource"))
name = desgn.at(ns("./expression/name | ./letter-symbol/name | "\
"./graphical-symbol")) or return
designation_annotate(desgn, name)
s and desgn.next = s
end
|
#designation_annotate(desgn, name) ⇒ Object
135
136
137
138
139
140
141
142
143
|
# File 'lib/isodoc/presentation_function/terms.rb', line 135
def designation_annotate(desgn, name)
designation_boldface(desgn)
designation_field(desgn, name)
g = desgn.at(ns("./expression/grammar")) and
name << ", #{designation_grammar(g).join(', ')}"
designation_localization(desgn, name)
designation_pronunciation(desgn, name)
desgn.children = name.children
end
|
#designation_boldface(desgn) ⇒ Object
145
146
147
148
149
|
# File 'lib/isodoc/presentation_function/terms.rb', line 145
def designation_boldface(desgn)
desgn.name == "preferred" or return
name = desgn.at(ns("./expression/name | ./letter-symbol/name")) or return
name.children = "<strong>#{name.children}</strong>"
end
|
#designation_field(desgn, name) ⇒ Object
151
152
153
154
155
156
157
|
# File 'lib/isodoc/presentation_function/terms.rb', line 151
def designation_field(desgn, name)
f = desgn.xpath(ns("./field-of-application | ./usage-info"))
&.map { |u| u.children.to_xml }&.join(", ")
return nil if f&.empty?
name << ", <#{f}>"
end
|
#designation_grammar(grammar) ⇒ Object
159
160
161
162
163
164
165
166
167
168
169
170
|
# File 'lib/isodoc/presentation_function/terms.rb', line 159
def designation_grammar(grammar)
ret = []
grammar.xpath(ns("./gender | ./number")).each do |x|
ret << @i18n.grammar_abbrevs[x.text]
end
%w(isPreposition isParticiple isAdjective isVerb isAdverb isNoun)
.each do |x|
grammar.at(ns("./#{x}[text() = 'true']")) and
ret << @i18n.grammar_abbrevs[x]
end
ret
end
|
#designation_localization(desgn, name) ⇒ Object
172
173
174
175
176
177
178
179
|
# File 'lib/isodoc/presentation_function/terms.rb', line 172
def designation_localization(desgn, name)
loc = [desgn&.at(ns("./expression/@language"))&.text,
desgn&.at(ns("./expression/@script"))&.text,
desgn&.at(ns("./@geographic-area"))&.text].compact
return if loc.empty?
name << ", #{loc.join(' ')}"
end
|
#designation_pronunciation(desgn, name) ⇒ Object
181
182
183
184
185
|
# File 'lib/isodoc/presentation_function/terms.rb', line 181
def designation_pronunciation(desgn, name)
f = desgn.at(ns("./expression/pronunciation")) or return
name << ", /#{f.children.to_xml}/"
end
|
#display_order(docxml) ⇒ Object
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/isodoc/presentation_function/section.rb', line 99
def display_order(docxml)
i = 0
i = display_order_xpath(docxml, "//preface/*", i)
i = display_order_at(docxml, "//clause[@type = 'scope']", i)
i = display_order_at(docxml, @xrefs.klass.norm_ref_xpath, i)
i = display_order_at(docxml, "//sections/terms | "\
"//sections/clause[descendant::terms]", i)
i = display_order_at(docxml, "//sections/definitions", i)
i = display_order_xpath(docxml, @xrefs.klass.middle_clause(docxml), i)
i = display_order_xpath(docxml, "//annex", i)
i = display_order_xpath(docxml, @xrefs.klass.bibliography_xpath, i)
display_order_xpath(docxml, "//indexsect", i)
end
|
#display_order_at(docxml, xpath, idx) ⇒ Object
83
84
85
86
87
88
89
|
# File 'lib/isodoc/presentation_function/section.rb', line 83
def display_order_at(docxml, xpath, idx)
return idx unless c = docxml.at(ns(xpath))
idx += 1
c["displayorder"] = idx
idx
end
|
#display_order_xpath(docxml, xpath, idx) ⇒ Object
91
92
93
94
95
96
97
|
# File 'lib/isodoc/presentation_function/section.rb', line 91
def display_order_xpath(docxml, xpath, idx)
docxml.xpath(ns(xpath)).each do |c|
idx += 1
c["displayorder"] = idx
end
idx
end
|
#docid_prefixes(docxml) ⇒ Object
104
105
106
107
108
|
# File 'lib/isodoc/presentation_function/refs.rb', line 104
def docid_prefixes(docxml)
docxml.xpath(ns("//references/bibitem/docidentifier")).each do |i|
i.children = @xrefs.klass.docid_prefix(i["type"], i.text)
end
end
|
#edition_translate(bibdata) ⇒ Object
does not allow %Spellout and %Ordinal in the ordinal expression to be mixed
93
94
95
96
97
98
99
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 93
def edition_translate(bibdata)
x = bibdata.at(ns("./edition")) or return
/^\d+$/.match?(x.text) or return
tag_translate(x, @lang,
@i18n.edition_ordinal.sub(/%(Spellout|Ordinal)?/,
edition_translate1(x.text.to_i)))
end
|
#edition_translate1(num) ⇒ Object
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 101
def edition_translate1(num)
ruleset = case @i18n.edition_ordinal
when /%Spellout/ then "SpelloutRules"
when /%Ordinal/ then "OrdinalRules"
else "Digit"
end
ruleset == "Digit" and return num.to_s
ed = @c.decode(@i18n.edition)
@i18n.inflect_ordinal(num, @i18n.inflection&.dig(ed) || {},
ruleset)
end
|
#emf_encode(img) ⇒ Object
84
85
86
87
88
89
|
# File 'lib/isodoc/presentation_function/image.rb', line 84
def emf_encode(img)
svg_prep(img)
img.children = "<emf src='#{img['src']}'/>"
img["src"] = ""
img
end
|
#emf_to_svg(img) ⇒ Object
97
98
99
100
|
# File 'lib/isodoc/presentation_function/image.rb', line 97
def emf_to_svg(img)
emf = Metanorma::Utils::save_dataimage(img.at(ns("./emf/@src")).text)
Emf2svg.from_file(emf).sub(/<\?[^>]+>/, "")
end
|
#eps2svg(img) ⇒ Object
65
66
67
68
69
70
71
72
73
|
# File 'lib/isodoc/presentation_function/image.rb', line 65
def eps2svg(img)
return unless eps?(img["mimetype"])
img["mimetype"] = "image/svg+xml"
if src = eps_to_svg(img)
img["src"] = src
img.children = ""
end
end
|
#eps_to_svg(node) ⇒ Object
102
103
104
105
106
107
|
# File 'lib/isodoc/presentation_function/image.rb', line 102
def eps_to_svg(node)
uri = eps_to_svg_uri(node)
ret = imgfile_suffix(uri, "svg")
File.exist?(ret) and return ret
inkscape_convert(uri, ret, "--export-plain-svg")
end
|
#eps_to_svg_uri(node) ⇒ Object
137
138
139
140
|
# File 'lib/isodoc/presentation_function/image.rb', line 137
def eps_to_svg_uri(node)
uri = eps_to_svg_uri_convert(node)
cache_dataimage(uri)
end
|
#eps_to_svg_uri_convert(node) ⇒ Object
158
159
160
161
162
163
164
165
|
# File 'lib/isodoc/presentation_function/image.rb', line 158
def eps_to_svg_uri_convert(node)
if node.text.strip.empty?
node["src"]
else
a = Base64.strict_encode64(node.children.to_xml)
"data:application/postscript;base64,#{a}"
end
end
|
#eref(docxml) ⇒ Object
187
188
189
|
# File 'lib/isodoc/presentation_function/inline.rb', line 187
def eref(docxml)
docxml.xpath(ns("//eref")).each { |f| xref1(f) }
end
|
#eref_localities(refs, target, node) ⇒ Object
31
32
33
34
35
36
37
38
|
# File 'lib/isodoc/presentation_function/inline.rb', line 31
def eref_localities(refs, target, node)
if can_conflate_eref_rendering?(refs)
l10n(", #{eref_localities_conflated(refs, target, node)}")
else
ret = resolve_eref_connectives(eref_locality_stacks(refs, target, node))
l10n(ret.join)
end
end
|
#eref_localities0(ref, _idx, target, node) ⇒ Object
141
142
143
144
145
146
147
148
|
# File 'lib/isodoc/presentation_function/inline.rb', line 141
def eref_localities0(ref, _idx, target, node)
if ref["type"] == "whole" then @i18n.wholeoftext
else
eref_localities1(target, ref["type"],
ref&.at(ns("./referenceFrom"))&.text,
ref&.at(ns("./referenceTo"))&.text, node, @lang)
end
end
|
#eref_localities1(target, type, from, upto, node, lang = "en") ⇒ Object
TODO: move to localization file
160
161
162
163
164
165
166
167
168
169
|
# File 'lib/isodoc/presentation_function/inline.rb', line 160
def eref_localities1(target, type, from, upto, node, lang = "en")
return nil if type == "anchor"
lang == "zh" and
return l10n(eref_localities1_zh(target, type, from, upto, node))
ret = eref_locality_populate(type, node)
ret += " #{from}" if from
ret += "–#{upto}" if upto
l10n(ret)
end
|
#eref_localities1_zh(_target, type, from, upto, node) ⇒ Object
TODO: move to localization file
151
152
153
154
155
156
157
|
# File 'lib/isodoc/presentation_function/inline.rb', line 151
def eref_localities1_zh(_target, type, from, upto, node)
ret = "第#{from}" if from
ret += "–#{upto}" if upto
loc = eref_locality_populate(type, node)
ret += " #{loc}" unless node["droploc"] == "true"
ret
end
|
#eref_localities_conflated(refs, target, node) ⇒ Object
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/isodoc/presentation_function/inline.rb', line 40
def eref_localities_conflated(refs, target, node)
droploc = node["droploc"]
node["droploc"] = true
ret = resolve_eref_connectives(eref_locality_stacks(refs, target,
node))
node.delete("droploc") unless droploc
eref_localities1(target,
refs.first.at(ns("./locality/@type")).text,
l10n(ret[1..-1].join), nil, node, @lang)
end
|
#eref_locality_delimiter(ref) ⇒ Object
114
115
116
117
118
119
|
# File 'lib/isodoc/presentation_function/inline.rb', line 114
def eref_locality_delimiter(ref)
if ref&.next_element&.name == "localityStack"
ref.next_element["connective"]
else locality_delimiter(ref)
end
end
|
#eref_locality_populate(type, node) ⇒ Object
171
172
173
174
175
176
177
178
179
180
181
|
# File 'lib/isodoc/presentation_function/inline.rb', line 171
def eref_locality_populate(type, node)
return "" if node["droploc"] == "true"
loc = type.sub(/^locality:/, "")
ret = @i18n.locality[loc] || loc
ret = case node["case"]
when "lowercase" then loc.downcase
else Metanorma::Utils.strict_capitalize_first(ret)
end
" #{ret}"
end
|
#eref_locality_stack(ref, idx, target, node) ⇒ Object
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
# File 'lib/isodoc/presentation_function/inline.rb', line 121
def eref_locality_stack(ref, idx, target, node)
ret = []
if ref.name == "localityStack"
ref.elements.each_with_index do |rr, j|
l = eref_localities0(rr, j, target, node) or next
ret << l
ret << locality_delimiter(rr) unless j == ref.elements.size - 1
end
else
l = eref_localities0(ref, idx, target, node) and ret << l
end
ret[-1] == ", " and ret.pop
ret
end
|
#eref_locality_stacks(refs, target, node) ⇒ Object
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/isodoc/presentation_function/inline.rb', line 102
def eref_locality_stacks(refs, target, node)
ret = refs.each_with_index.with_object([]) do |(r, i), m|
added = eref_locality_stack(r, i, target, node)
added.empty? and next
added.each { |a| m << a }
next if i == refs.size - 1
m << eref_locality_delimiter(r)
end
ret.empty? ? ret : [", "] + ret
end
|
#example(docxml) ⇒ Object
53
54
55
56
57
|
# File 'lib/isodoc/presentation_function/block.rb', line 53
def example(docxml)
docxml.xpath(ns("//example")).each do |f|
example1(f)
end
end
|
#example1(elem) ⇒ Object
59
60
61
62
63
64
65
66
67
|
# File 'lib/isodoc/presentation_function/block.rb', line 59
def example1(elem)
n = @xrefs.get[elem["id"]]
lbl = if n.nil? || n[:label].nil? || n[:label].empty?
@i18n.example
else
l10n("#{@i18n.example} #{n[:label]}")
end
prefix_name(elem, block_delim, lbl, "name")
end
|
#expand_citeas(text) ⇒ Object
so not <origin bibitemid=“ISO7301” citeas=“ISO 7301”> <locality type=“section”><reference>3.1</reference></locality></origin>
26
27
28
29
|
# File 'lib/isodoc/presentation_function/inline.rb', line 26
def expand_citeas(text)
text.nil? and return text
HTMLEntities.new.decode(text.gsub(/&#x/, "&#"))
end
|
8
9
10
11
12
13
14
|
# File 'lib/isodoc/presentation_function/image.rb', line 8
def figure(docxml)
docxml.xpath("//m:svg", SVG).each { |f| svg_wrap(f) }
docxml.xpath(ns("//image")).each { |f| (f) }
docxml.xpath(ns("//figure")).each { |f| figure1(f) }
docxml.xpath(ns("//svgmap")).each { |s| (s) }
imageconvert(docxml)
end
|
49
50
51
52
53
54
55
56
57
|
# File 'lib/isodoc/presentation_function/image.rb', line 49
def figure1(elem)
return sourcecode1(elem) if elem["class"] == "pseudocode" ||
elem["type"] == "pseudocode"
return if elem.at(ns("./figure")) && !elem.at(ns("./name"))
lbl = @xrefs.anchor(elem["id"], :label, false) or return
prefix_name(elem, block_delim,
l10n("#{figure_label(elem)} #{lbl}"), "name")
end
|
59
60
61
62
63
|
# File 'lib/isodoc/presentation_function/image.rb', line 59
def figure_label(elem)
klass = elem["class"] || "figure"
klasslbl = @i18n.get[klass] || klass
lower2cap klasslbl
end
|
#floattitle(docxml) ⇒ Object
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/isodoc/presentation_function/section.rb', line 25
def floattitle(docxml)
docxml.xpath(ns("//clause | //annex | //appendix | //introduction | "\
"//foreword | //preface/abstract | //acknowledgements | "\
"//terms | //definitions | //references"))
.each do |f|
floattitle1(f)
end
docxml.xpath(ns("//sections | //preface")).each { |f| floattitle1(f) }
end
|
#floattitle1(elem) ⇒ Object
36
37
38
39
40
41
|
# File 'lib/isodoc/presentation_function/section.rb', line 36
def floattitle1(elem)
elem.xpath(ns(".//floating-title")).each do |p|
p.name = "p"
p["type"] = "floating-title"
end
end
|
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 40
def fonts_metadata(xmldoc)
return unless @fontist_fonts
ins = xmldoc.at(ns("//presentation-metadata")) ||
xmldoc.at(ns("//misc-container")) || xmldoc.at(ns("//bibdata"))
CSV.parse_line(@fontist_fonts, col_sep: ";").map(&:strip).each do |f|
ins.next = presmeta("fonts", f)
end
@fontlicenseagreement and
ins.next = presmeta("font-license-agreement", @fontlicenseagreement)
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
|
48
49
50
51
|
# File 'lib/isodoc/presentation_function/block.rb', line 48
def formula1(elem)
lbl = @xrefs.anchor(elem["id"], :label, false)
prefix_name(elem, "", lbl, "name")
end
|
#gather_xref_locations(node) ⇒ Object
75
76
77
78
79
80
81
82
83
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 75
def gather_xref_locations(node)
node.xpath(ns("./location")).each_with_object([]) do |l, m|
type = @xrefs.anchor(l["target"], :type)
m << { conn: l["connective"], target: l["target"],
type: type, node: l, elem: @xrefs.anchor(l["target"], :elem),
container: @xrefs.anchor(node["target"], :container, false) ||
%w(termnote).include?(type) }
end
end
|
#get_linkend(node) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/isodoc/presentation_function/inline.rb', line 12
def get_linkend(node)
c1 = non_locality_elems(node).select { |c| !c.text? || /\S/.match(c) }
return unless c1.empty?
link = anchor_linkend(node, docid_l10n(node["target"] ||
expand_citeas(node["citeas"])))
link += eref_localities(node.xpath(ns("./locality | ./localityStack")),
link, node)
non_locality_elems(node).each(&:remove)
node.add_child(cleanup_entities(link))
end
|
#hash_translate(bibdata, hash, xpath, lang = @lang) ⇒ Object
85
86
87
88
89
90
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 85
def hash_translate(bibdata, hash, xpath, lang = @lang)
x = bibdata.at(ns(xpath)) or return
hash.is_a? Hash or return
hash[x.text] or return
tag_translate(x, lang, hash[x.text])
end
|
#i18n_chain_boolean(value, entry) ⇒ Object
99
100
101
102
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 99
def i18n_chain_boolean(value, entry)
@i18n.send("chain_#{entry[:conn]}").sub(/%1/, value)
.sub(/%2/, entry[:target])
end
|
#i18n_safe(key) ⇒ Object
125
126
127
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 125
def i18n_safe(key)
key.to_s.gsub(/\s|\./, "_")
end
|
#i18n_tag(key, value) ⇒ Object
120
121
122
123
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 120
def i18n_tag(key, value)
"<localized-string key='#{key}' language='#{@lang}'>#{value}"\
"</localized-string>"
end
|
#i8n_name(hash, pref) ⇒ Object
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 129
def i8n_name(hash, pref)
case hash
when Hash then i8n_name1(hash, pref)
when Array
hash.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, hash)]
end
end
|
#i8n_name1(hash, pref) ⇒ Object
141
142
143
144
145
146
147
148
149
150
151
152
153
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 141
def i8n_name1(hash, pref)
hash.reject { |_k, v| blank?(v) }.each_with_object([]) do |(k, v), g|
case v
when Hash then i8n_name(v, i18n_safe(k)).each { |x| g << x }
when 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
|
#identifier(docxml) ⇒ Object
222
223
224
225
226
|
# File 'lib/isodoc/presentation_function/inline.rb', line 222
def identifier(docxml)
docxml.xpath(ns("//identifier")).each do |n|
n.name = "tt"
end
end
|
#imageconvert(docxml) ⇒ Object
29
30
31
32
33
34
|
# File 'lib/isodoc/presentation_function/image.rb', line 29
def imageconvert(docxml)
docxml.xpath(ns("//image")).each do |f|
eps2svg(f)
svg_emf_double(f)
end
end
|
#imgfile_suffix(uri, suffix) ⇒ Object
167
168
169
|
# File 'lib/isodoc/presentation_function/image.rb', line 167
def imgfile_suffix(uri, suffix)
"#{File.join(File.dirname(uri), File.basename(uri, '.*'))}.#{suffix}"
end
|
#index(docxml) ⇒ Object
79
80
81
|
# File 'lib/isodoc/presentation_function/section.rb', line 79
def index(docxml)
docxml.xpath(ns("//index | //index-xref | //indexsect")).each(&:remove)
end
|
#inkscape_convert(uri, file, option) ⇒ Object
121
122
123
124
125
126
127
128
129
130
|
# File 'lib/isodoc/presentation_function/image.rb', line 121
def inkscape_convert(uri, file, option)
exe = inkscape_installed? or raise "Inkscape missing in PATH, unable" \
"to convert image #{uri}. Aborting."
uri = Metanorma::Utils::external_path uri
exe = Metanorma::Utils::external_path exe
system(%(#{exe} #{option} #{uri})) and
return Metanorma::Utils::datauri(file)
raise %(Fail on #{exe} #{option} #{uri})
end
|
#inkscape_installed? ⇒ Boolean
171
172
173
174
175
176
177
178
179
180
181
|
# File 'lib/isodoc/presentation_function/image.rb', line 171
def inkscape_installed?
cmd = "inkscape"
exts = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""]
ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
exts.each do |ext|
exe = File.join(path, "#{cmd}#{ext}")
return exe if File.executable?(exe) && !File.directory?(exe)
end
end
nil
end
|
#inline(docxml) ⇒ Object
65
66
67
68
69
70
71
72
73
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 65
def inline(docxml)
xref docxml
eref docxml
origin docxml
quotesource docxml
mathml docxml
variant docxml
identifier docxml
end
|
#locality_delimiter(_loc) ⇒ Object
137
138
139
|
# File 'lib/isodoc/presentation_function/inline.rb', line 137
def locality_delimiter(_loc)
", "
end
|
#localize_maths(node, locale) ⇒ Object
symbols is merged into TwitterCldr::DataReaders::NumberDataReader.new(locale).symbols
18
19
20
21
22
23
24
25
|
# File 'lib/isodoc/presentation_function/math.rb', line 18
def localize_maths(node, locale)
node.xpath(".//m:mn", MATHML).each do |x|
num = BigDecimal(x.text)
precision = /\./.match?(x.text) ? x.text.sub(/^.*\./, "").size : 0
x.children = localized_number(num, locale, precision)
rescue ArgumentError => e
end
end
|
#localized_number(num, locale, precision) ⇒ Object
By itself twitter-cldr does not support fraction part digits grouping and custom delimeter, will decorate fraction part manually
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/isodoc/presentation_function/math.rb', line 29
def localized_number(num, locale, precision)
localized = localized_number1(num, locale, precision)
= (locale)
return localized unless [:decimal]
integer, fraction = localized.split([:decimal])
return localized if fraction.nil? || fraction.length.zero?
[integer, decorate_fraction_part(fraction, locale)]
.join([:decimal])
end
|
#localized_number1(num, locale, precision) ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/isodoc/presentation_function/math.rb', line 41
def localized_number1(num, locale, precision)
if precision.zero?
num.localize(locale).to_s
else
num.localize(locale).to_decimal.to_s(precision: precision)
end
end
|
#lower2cap(text) ⇒ Object
5
6
7
8
9
|
# File 'lib/isodoc/presentation_function/block.rb', line 5
def lower2cap(text)
return text if /^[[:upper:]][[:upper:]]/.match?(text)
text.capitalize
end
|
#mathml(docxml) ⇒ Object
9
10
11
12
13
14
|
# File 'lib/isodoc/presentation_function/math.rb', line 9
def mathml(docxml)
locale =
docxml.xpath("//m:math", MATHML).each do |f|
mathml1(f, locale)
end
end
|
#mathml1(node, locale) ⇒ Object
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/isodoc/presentation_function/math.rb', line 99
def mathml1(node, locale)
asciimath_dup(node)
localize_maths(node, locale)
return unless node.elements.size == 1 && node.elements.first.name == "mn"
if node.parent.name == "stem"
node.parent.replace(node.at("./m:mn", MATHML).children)
else
node.replace(node.at("./m:mn", MATHML).children)
end
end
|
#merge_preferred_eligible?(first, second) ⇒ Boolean
117
118
119
120
121
122
123
124
|
# File 'lib/isodoc/presentation_function/terms.rb', line 117
def merge_preferred_eligible?(first, second)
firstex = first.at(ns("./expression")) || {}
secondex = second.at(ns("./expression")) || {}
first["geographic-area"] == second["geographic-area"] &&
firstex["language"] == secondex["language"] &&
!first.at(ns("./pronunciation | ./grammar")) &&
!second.at(ns("./pronunciation | ./grammar"))
end
|
#merge_second_preferred(term) ⇒ Object
100
101
102
103
104
105
106
107
|
# File 'lib/isodoc/presentation_function/terms.rb', line 100
def merge_second_preferred(term)
pref = nil
term.xpath(ns("./preferred[expression/name]")).each_with_index do |p, i|
if i.zero? then pref = p
else merge_second_preferred1(pref, p)
end
end
end
|
#merge_second_preferred1(pref, second) ⇒ Object
109
110
111
112
113
114
115
|
# File 'lib/isodoc/presentation_function/terms.rb', line 109
def merge_second_preferred1(pref, second)
if merge_preferred_eligible?(pref, second)
n1 = pref.at(ns("./expression/name"))
n2 = second.remove.at(ns("./expression/name"))
n1.children = l10n("#{n1.children.to_xml}; #{n2.children.to_xml}")
end
end
|
#multidef(elem) ⇒ Object
215
216
217
218
219
220
221
222
223
|
# File 'lib/isodoc/presentation_function/terms.rb', line 215
def multidef(elem)
d = elem.at(ns("./definition"))
d = d.replace("<ol><li>#{d.children.to_xml}</li></ol>").first
elem.xpath(ns("./definition")).each do |f|
f = f.replace("<li>#{f.children.to_xml}</li>").first
d << f
end
d.wrap("<definition></definition>")
end
|
#non_locality_elems(node) ⇒ Object
6
7
8
9
10
|
# File 'lib/isodoc/presentation_function/inline.rb', line 6
def non_locality_elems(node)
node.children.reject do |c|
%w{locality localityStack location}.include? c.name
end
end
|
#note(docxml) ⇒ Object
69
70
71
72
73
|
# File 'lib/isodoc/presentation_function/block.rb', line 69
def note(docxml)
docxml.xpath(ns("//note")).each do |f|
note1(f)
end
end
|
#note1(elem) ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/isodoc/presentation_function/block.rb', line 75
def note1(elem)
return if elem.parent.name == "bibitem" || elem["notag"] == "true"
n = @xrefs.get[elem["id"]]
lbl = if n.nil? || n[:label].nil? || n[:label].empty?
@i18n.note
else
l10n("#{@i18n.note} #{n[:label]}")
end
prefix_name(elem, "", lbl, "name")
end
|
#ol(docxml) ⇒ Object
152
153
154
155
156
157
|
# File 'lib/isodoc/presentation_function/block.rb', line 152
def ol(docxml)
docxml.xpath(ns("//ol")).each do |f|
ol1(f)
end
@xrefs.list_anchor_names(docxml.xpath(ns(@xrefs.sections_xpath)))
end
|
#ol1(elem) ⇒ Object
172
173
174
|
# File 'lib/isodoc/presentation_function/block.rb', line 172
def ol1(elem)
elem["type"] ||= ol_depth(elem).to_s
end
|
#ol_depth(node) ⇒ Object
We don’t really want users to specify type of ordered list; we will use by default a fixed hierarchy as practiced by ISO (though not fully spelled out): a) 1) i) A) I)
162
163
164
165
166
167
168
169
170
|
# File 'lib/isodoc/presentation_function/block.rb', line 162
def ol_depth(node)
depth = node.ancestors("ul, ol").size + 1
type = :alphabet
type = :arabic if [2, 7].include? depth
type = :roman if [3, 8].include? depth
type = :alphabet_upper if [4, 9].include? depth
type = :roman_upper if [5, 10].include? depth
type
end
|
#origin(docxml) ⇒ Object
191
192
193
|
# File 'lib/isodoc/presentation_function/inline.rb', line 191
def origin(docxml)
docxml.xpath(ns("//origin[not(termref)]")).each { |f| xref1(f) }
end
|
#parse_localize_number ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/isodoc/presentation_function/math.rb', line 79
def parse_localize_number
return {} unless @localizenumber
m = %r{(?<group>[^#])?(?<groupdigits>#+0)(?<decimal>.)(?<fractdigits>#+)(?<fractgroup>[^#])?}
.match(@localizenumber) or return {}
ret = { decimal: m[:decimal], group_digits: m[:groupdigits].size,
fraction_group_digits: m[:fractdigits].size,
group: m[:group] || "",
fraction_group: m[:fractgroup] || "" }.compact
%i(group fraction_group).each { |x| ret[x] == " " and ret[x] = "\u00A0" }
ret
end
|
#permission(docxml) ⇒ Object
111
112
113
114
115
|
# File 'lib/isodoc/presentation_function/block.rb', line 111
def permission(docxml)
docxml.xpath(ns("//permission")).each do |f|
recommendation1(f, lower2cap(@i18n.permission))
end
end
|
#postprocess(result, filename, _dir) ⇒ Object
85
86
87
88
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 85
def postprocess(result, filename, _dir)
to_xml(result, filename)
@files_to_delete.each { |f| FileUtils.rm_rf f }
end
|
#prefix_container(container, linkend, node, _target) ⇒ Object
3
4
5
6
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 3
def prefix_container(container, linkend, node, _target)
l10n("#{anchor_xref(node, container)}, #{linkend}")
end
|
#prefix_container?(container, node) ⇒ Boolean
46
47
48
49
50
51
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 46
def prefix_container?(container, node)
type = @xrefs.anchor(node["target"], :type)
container &&
get_note_container_id(node, type) != container &&
@xrefs.get[node["target"]]
end
|
#prefix_name(node, delim, number, elem) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/isodoc/presentation_function/block.rb', line 15
def prefix_name(node, delim, number, elem)
return if number.nil? || number.empty?
unless name = node.at(ns("./#{elem}"))
(node.children.empty? and node.add_child("<#{elem}></#{elem}>")) or
node.children.first.previous = "<#{elem}></#{elem}>"
name = node.children.first
end
if name.children.empty? then name.add_child(cleanup_entities(number.strip))
else (name.children.first.previous = "#{number.strip}#{delim}")
end
end
|
#prep_for_rendering(bib) ⇒ Object
29
30
31
32
33
|
# File 'lib/isodoc/presentation_function/refs.rb', line 29
def prep_for_rendering(bib)
bib["suppress_identifier"] == true and
bib.xpath(ns("./docidentifier")).each(&:remove)
bib["type"] ||= "standard"
end
|
52
53
54
55
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 52
def presmeta(name, value)
"<presentation-metadata><name>#{name}</name><value>#{value}</value>"\
"</presentation-metadata>"
end
|
#quotesource(docxml) ⇒ Object
195
196
197
|
# File 'lib/isodoc/presentation_function/inline.rb', line 195
def quotesource(docxml)
docxml.xpath(ns("//quote/source")).each { |f| xref1(f) }
end
|
#recommendation(docxml) ⇒ Object
99
100
101
102
103
|
# File 'lib/isodoc/presentation_function/block.rb', line 99
def recommendation(docxml)
docxml.xpath(ns("//recommendation")).each do |f|
recommendation1(f, lower2cap(@i18n.recommendation))
end
end
|
#recommendation1(elem, type) ⇒ Object
117
118
119
120
121
|
# File 'lib/isodoc/presentation_function/block.rb', line 117
def recommendation1(elem, type)
lbl = @reqt_models.model(elem["model"])
.recommendation_label(elem, type, xrefs)
prefix_name(elem, "", l10n(lbl), "name")
end
|
#references(docxml) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/isodoc/presentation_function/refs.rb', line 5
def references(docxml)
bibliography_bibitem_number(docxml)
renderings = references_render(docxml)
docxml.xpath(ns("//references/bibitem")).each do |x|
bibitem(x, renderings)
end
docxml.xpath(ns("//references[bibitem/@hidden = 'true']")).each do |x|
x.at(ns("./bibitem[not(@hidden = 'true')]")) and next
x["hidden"] = "true"
end
@xrefs.parse_inclusions(refs: true).parse(docxml)
end
|
#references_render(docxml) ⇒ Object
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/isodoc/presentation_function/refs.rb', line 18
def references_render(docxml)
d = docxml.clone
d.remove_namespaces!
refs = d.xpath("//references/bibitem").each_with_object([]) do |b, m|
prep_for_rendering(b)
m << b.to_xml
end.join
bibrenderer.render_all("<references>#{refs}</references>",
type: citestyle)
end
|
76
77
78
|
# File 'lib/isodoc/presentation_function/terms.rb', line 76
def related(docxml)
docxml.xpath(ns("//related")).each { |f| related1(f) }
end
|
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/isodoc/presentation_function/terms.rb', line 80
def related1(node)
p = node.at(ns("./preferred"))
ref = node.at(ns("./xref | ./eref | ./termref"))
label = @i18n.relatedterms[node["type"]].upcase
if p && ref
node.replace(l10n("<p><strong>#{label}:</strong> "\
"<em>#{p.to_xml}</em> (#{ref.to_xml})</p>"))
else
node.replace(l10n("<p><strong>#{label}:</strong> "\
"<strong>**RELATED TERM NOT FOUND**</strong></p>"))
end
end
|
#requirement(docxml) ⇒ Object
105
106
107
108
109
|
# File 'lib/isodoc/presentation_function/block.rb', line 105
def requirement(docxml)
docxml.xpath(ns("//requirement")).each do |f|
recommendation1(f, lower2cap(@i18n.requirement))
end
end
|
#requirement_render(docxml) ⇒ Object
180
181
182
183
184
185
186
187
188
189
|
# File 'lib/isodoc/presentation_function/block.rb', line 180
def requirement_render(docxml)
requirement_render_preprocessing(docxml)
REQS.each do |x|
REQS.each do |y|
docxml.xpath(ns("//#{x}//#{y}")).each { |r| requirement_render1(r) }
end
end
docxml.xpath(ns("//requirement | //recommendation | //permission"))
.each { |r| requirement_render1(r) }
end
|
#requirement_render1(node) ⇒ Object
191
192
193
194
|
# File 'lib/isodoc/presentation_function/block.rb', line 191
def requirement_render1(node)
node.replace(@reqt_models.model(node["model"])
.requirement_render1(node))
end
|
#requirement_render_preprocessing(docxml) ⇒ Object
176
|
# File 'lib/isodoc/presentation_function/block.rb', line 176
def requirement_render_preprocessing(docxml); end
|
#resolve_comma_connectives(locs) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/isodoc/presentation_function/inline.rb', line 73
def resolve_comma_connectives(locs)
locs1 = []
add = ""
until locs.empty?
if [", ", " "].include?(locs[1])
add += locs[0..2].join
locs.shift(3)
else
locs1 << add unless add.empty?
add = ""
locs1 << locs.shift
end
end
locs1 << add unless add.empty?
locs1
end
|
#resolve_eref_connectives(locs) ⇒ Object
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/isodoc/presentation_function/inline.rb', line 62
def resolve_eref_connectives(locs)
locs = resolve_comma_connectives(locs)
locs = resolve_to_connectives(locs)
return locs if locs.size < 3
locs = locs.each_slice(2).with_object([]) do |a, m|
m << { conn: a[0], target: a[1] }
end
[", ", combine_conn(locs)]
end
|
#resolve_to_connectives(locs) ⇒ Object
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/isodoc/presentation_function/inline.rb', line 90
def resolve_to_connectives(locs)
locs1 = []
until locs.empty?
if locs[1] == "to"
locs1 << @i18n.chain_to.sub(/%1/, locs[0]).sub(/%2/, locs[2])
locs.shift(3)
else locs1 << locs.shift
end
end
locs1
end
|
#section(docxml) ⇒ Object
parse annex after term, references, to deal with single-term and single-ref annexes
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 35
def section(docxml)
references docxml
clause docxml
term docxml
annex docxml
index docxml
clausetitle docxml
floattitle docxml
toc docxml
display_order docxml
end
|
#single_term_clause(elem) ⇒ Object
58
59
60
61
62
63
64
65
66
|
# File 'lib/isodoc/presentation_function/section.rb', line 58
def single_term_clause(elem)
t = elem.at(ns("./terms | ./definitions | ./references"))
t.at(ns("./title"))&.remove
t.xpath(ns(".//clause | .//terms | .//definitions | .//references"))
.each do |c|
tit = c.at(ns("./title")) or return
tit["depth"] = tit["depth"].to_i - 1 unless tit["depth"] == "1"
end
end
|
#sourcecode(docxml) ⇒ Object
28
29
30
31
32
|
# File 'lib/isodoc/presentation_function/block.rb', line 28
def sourcecode(docxml)
docxml.xpath(ns("//sourcecode")).each do |f|
sourcecode1(f)
end
end
|
#sourcecode1(elem) ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/isodoc/presentation_function/block.rb', line 34
def sourcecode1(elem)
return if labelled_ancestor(elem)
lbl = @xrefs.anchor(elem["id"], :label, false) or return
prefix_name(elem, block_delim,
l10n("#{lower2cap @i18n.figure} #{lbl}"), "name")
end
|
#svg_emf_double(img) ⇒ Object
75
76
77
78
79
80
81
82
|
# File 'lib/isodoc/presentation_function/image.rb', line 75
def svg_emf_double(img)
if emf?(img["mimetype"])
img = emf_encode(img)
img.children.first.previous = emf_to_svg(img)
elsif img["mimetype"] == "image/svg+xml"
src = svg_to_emf(img) and img << "<emf src='#{src}'/>"
end
end
|
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/isodoc/presentation_function/image.rb', line 36
def (elem)
return unless %r{^data:image/svg\+xml;}.match?(elem["src"])
return if elem.at("./m:svg", SVG)
svg = Base64.strict_decode64(elem["src"]
.sub(%r{^data:image/svg\+xml;(charset=[^;]+;)?base64,}, ""))
x = Nokogiri::XML.fragment(svg.sub(/<\?xml[^>]*>/, "")) do |config|
config.huge
end
elem["src"] = ""
elem.children = x
end
|
#svg_prep(img) ⇒ Object
91
92
93
94
95
|
# File 'lib/isodoc/presentation_function/image.rb', line 91
def svg_prep(img)
img["mimetype"] = "image/svg+xml"
%r{^data:image}.match?(img["src"]) or
img["src"] = Metanorma::Utils::datauri(img["src"])
end
|
#svg_to_emf(node) ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/isodoc/presentation_function/image.rb', line 109
def svg_to_emf(node)
uri = svg_to_emf_uri(node)
if node.elements&.first&.name == "svg" &&
(!node["height"] || node["height"] == "auto")
node["height"] = node.elements.first["height"]
node["width"] = node.elements.first["width"]
end
ret = imgfile_suffix(uri, "emf")
File.exist?(ret) and return ret
inkscape_convert(uri, ret, '--export-type="emf"')
end
|
#svg_to_emf_uri(node) ⇒ Object
132
133
134
135
|
# File 'lib/isodoc/presentation_function/image.rb', line 132
def svg_to_emf_uri(node)
uri = svg_to_emf_uri_convert(node)
cache_dataimage(uri)
end
|
#svg_to_emf_uri_convert(node) ⇒ Object
150
151
152
153
154
155
156
|
# File 'lib/isodoc/presentation_function/image.rb', line 150
def svg_to_emf_uri_convert(node)
if node.elements&.first&.name == "svg"
a = Base64.strict_encode64(node.children.to_xml)
"data:image/svg+xml;base64,#{a}"
else node["src"]
end
end
|
#svg_wrap(elem) ⇒ Object
16
17
18
19
20
21
|
# File 'lib/isodoc/presentation_function/image.rb', line 16
def svg_wrap(elem)
return if elem.parent.name == "image"
elem.replace("<image src='' mimetype='image/svg+xml' height='auto' "\
"width='auto'>#{elem.to_xml}</image>")
end
|
23
24
25
26
27
|
# File 'lib/isodoc/presentation_function/image.rb', line 23
def (elem)
if f = elem.at(ns("./figure")) then elem.replace(f)
else elem.remove
end
end
|
#table(docxml) ⇒ Object
123
124
125
126
127
|
# File 'lib/isodoc/presentation_function/block.rb', line 123
def table(docxml)
docxml.xpath(ns("//table")).each do |f|
table1(f)
end
end
|
#table1(elem) ⇒ Object
129
130
131
132
133
134
135
136
|
# File 'lib/isodoc/presentation_function/block.rb', line 129
def table1(elem)
return if labelled_ancestor(elem)
return if elem["unnumbered"] && !elem.at(ns("./name"))
n = @xrefs.anchor(elem["id"], :label, false)
prefix_name(elem, block_delim, l10n("#{lower2cap @i18n.table} #{n}"),
"name")
end
|
#tag_translate(tag, lang, value) ⇒ Object
113
114
115
116
117
118
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 113
def tag_translate(tag, lang, value)
tag["language"] = ""
tag.next = tag.dup
tag.next["language"] = lang
tag.next.children = value
end
|
#term(docxml) ⇒ Object
68
69
70
71
72
|
# File 'lib/isodoc/presentation_function/section.rb', line 68
def term(docxml)
docxml.xpath(ns("//term")).each do |f|
term1(f)
end
end
|
#term1(elem) ⇒ Object
74
75
76
77
|
# File 'lib/isodoc/presentation_function/section.rb', line 74
def term1(elem)
lbl = @xrefs.get[elem["id"]][:label] or return
prefix_name(elem, "", "#{lbl}#{clausedelim}", "name")
end
|
#termdefinition(docxml) ⇒ Object
204
205
206
207
208
|
# File 'lib/isodoc/presentation_function/terms.rb', line 204
def termdefinition(docxml)
docxml.xpath(ns("//term[definition]")).each do |f|
termdefinition1(f)
end
end
|
#termdefinition1(elem) ⇒ Object
210
211
212
213
|
# File 'lib/isodoc/presentation_function/terms.rb', line 210
def termdefinition1(elem)
unwrap_definition(elem)
multidef(elem) if elem.xpath(ns("./definition")).size > 1
end
|
#termexample(docxml) ⇒ Object
187
188
189
190
191
|
# File 'lib/isodoc/presentation_function/terms.rb', line 187
def termexample(docxml)
docxml.xpath(ns("//termexample")).each do |f|
example1(f)
end
end
|
#termnote(docxml) ⇒ Object
193
194
195
196
197
|
# File 'lib/isodoc/presentation_function/terms.rb', line 193
def termnote(docxml)
docxml.xpath(ns("//termnote")).each do |f|
termnote1(f)
end
end
|
#termnote1(elem) ⇒ Object
199
200
201
202
|
# File 'lib/isodoc/presentation_function/terms.rb', line 199
def termnote1(elem)
lbl = l10n(@xrefs.anchor(elem["id"], :label) || "???")
prefix_name(elem, "", lower2cap(lbl), "name")
end
|
#terms(docxml) ⇒ Object
75
76
77
78
79
80
81
82
83
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 75
def terms(docxml)
termexample docxml
termnote docxml
termdefinition docxml
designation docxml
termsource docxml
concept docxml
related docxml
end
|
#termsource(docxml) ⇒ Object
234
235
236
237
238
239
240
241
|
# File 'lib/isodoc/presentation_function/terms.rb', line 234
def termsource(docxml)
docxml.xpath(ns("//termsource/modification")).each do |f|
termsource_modification(f)
end
docxml.xpath(ns("//termsource")).each do |f|
termsource1(f)
end
end
|
#termsource1(elem) ⇒ Object
243
244
245
246
247
248
|
# File 'lib/isodoc/presentation_function/terms.rb', line 243
def termsource1(elem)
while elem&.next_element&.name == "termsource"
elem << "; #{elem.next_element.remove.children.to_xml}"
end
elem.children = l10n("[#{@i18n.source}: #{elem.children.to_xml.strip}]")
end
|
#termsource_modification(mod) ⇒ Object
250
251
252
253
254
255
256
|
# File 'lib/isodoc/presentation_function/terms.rb', line 250
def termsource_modification(mod)
mod.previous_element.next = l10n(", #{@i18n.modified}")
mod.text.strip.empty? or mod.previous = " – "
mod.elements.size == 1 and
mod.elements[0].replace(mod.elements[0].children)
mod.replace(mod.children)
end
|
#to_xml(result, filename) ⇒ Object
90
91
92
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 90
def to_xml(result, filename)
File.open(filename, "w:UTF-8") { |f| f.write(result) }
end
|
#toc(docxml) ⇒ Object
115
116
117
118
119
120
|
# File 'lib/isodoc/presentation_function/section.rb', line 115
def toc(docxml)
docxml.xpath(ns("//toc//xref[text()]")).each do |x|
lbl = @xrefs.anchor(x["target"], :label) or next
x.children.first.previous = "#{lbl}<tab/>"
end
end
|
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 17
def toc_metadata(docxml)
return unless @tocfigures || @toctables || @tocrecommendations
ins = docxml.at(ns("//misc-container")) ||
docxml.at(ns("//bibdata")).after("<misc-container/>").next_element
@tocfigures and
ins << "<toc type='figure'><title>#{@i18n.toc_figures}</title></toc>"
@toctables and
ins << "<toc type='table'><title>#{@i18n.toc_tables}</title></toc>"
@tocfigures and
ins << "<toc type='recommendation'><title>#{@i18n.toc_recommendations}"\
"</title></toc>"
end
|
#trim_hash(hash) ⇒ Object
160
161
162
163
164
165
166
167
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 160
def trim_hash(hash)
loop do
h_new = trim_hash1(hash)
break hash if hash == h_new
hash = h_new
end
end
|
#trim_hash1(hash) ⇒ Object
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 169
def trim_hash1(hash)
return hash unless hash.is_a? Hash
hash.each_with_object({}) do |(k, v), g|
next if blank?(v)
g[k] = case v
when Hash then trim_hash1(hash[k])
when Array
hash[k].map { |a| trim_hash1(a) }.reject { |a| blank?(a) }
else v
end
end
end
|
73
74
75
76
77
|
# File 'lib/isodoc/presentation_function/math.rb', line 73
def
locale = TwitterCldr.supported_locale?(@lang.to_sym) ? @lang.to_sym : :en
(locale)
locale
end
|
60
61
62
|
# File 'lib/isodoc/presentation_function/math.rb', line 60
def
{}
end
|
64
65
66
67
68
69
70
71
|
# File 'lib/isodoc/presentation_function/math.rb', line 64
def (locale)
return @twitter_cldr_reader if @twitter_cldr_reader
num = TwitterCldr::DataReaders::NumberDataReader.new(locale)
@twitter_cldr_reader = num.symbols.merge!()
.merge!(parse_localize_number)
@twitter_cldr_reader
end
|
#unwrap_definition(elem) ⇒ Object
225
226
227
228
229
230
231
232
|
# File 'lib/isodoc/presentation_function/terms.rb', line 225
def unwrap_definition(elem)
elem.xpath(ns("./definition")).each do |d|
%w(verbal-definition non-verbal-representation).each do |e|
v = d&.at(ns("./#{e}"))
v&.replace(v.children)
end
end
end
|
#variant(docxml) ⇒ Object
203
204
205
206
207
208
209
210
211
212
|
# File 'lib/isodoc/presentation_function/inline.rb', line 203
def variant(docxml)
docxml.xpath(ns("//variant")).each { |f| variant1(f) }
docxml.xpath(ns("//variant[@remove = 'true']")).each(&:remove)
docxml.xpath(ns("//variant")).each do |v|
next unless v&.next&.name == "variant"
v.next = "/"
end
docxml.xpath(ns("//variant")).each { |f| f.replace(f.children) }
end
|
#variant1(node) ⇒ Object
214
215
216
217
218
219
220
|
# File 'lib/isodoc/presentation_function/inline.rb', line 214
def variant1(node)
if !((!node["lang"] || node["lang"] == @lang) &&
(!node["script"] || node["script"] == @script)) &&
found_matching_variant_sibling(node)
node["remove"] = "true"
end
end
|
#xref(docxml) ⇒ Object
183
184
185
|
# File 'lib/isodoc/presentation_function/inline.rb', line 183
def xref(docxml)
docxml.xpath(ns("//xref")).each { |f| xref1(f) }
end
|
#xref1(node) ⇒ Object
199
200
201
|
# File 'lib/isodoc/presentation_function/inline.rb', line 199
def xref1(node)
get_linkend(node)
end
|