Class: IsoDoc::Convert
- Inherits:
-
Common
show all
- Defined in:
- lib/isodoc/css.rb,
lib/isodoc/init.rb,
lib/isodoc/convert.rb
Constant Summary
collapse
- AGENCIES =
%w(ISO IEC ITU IETF NIST OGC IEEE BIPM BSI BS JIS IANA UN W3C
IHO CSA IEV)
.freeze
Function::Utils::CLAUSE_ANCESTOR, Function::Utils::DOCTYPE_HDR, Function::Utils::HUGESTRICT, Function::Utils::LABELLED_ANCESTOR_ELEMENTS, Function::Utils::NOTE_CONTAINER_ANCESTOR
Function::ToWordHtml::TOP_ELEMENTS
Function::Table::SW
Function::Section::TERM_CLAUSE
Function::Lists::OL_STYLE
Function::Inline::MATHML, Function::Inline::SPAN_UNWRAP_CLASSES
Function::Cleanup::TABLENOTE_CSS
Function::Blocks::EXAMPLE_TBL_ATTR, Function::Blocks::EXAMPLE_TD_ATTR
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#agency?(text) ⇒ Boolean
-
#bibrenderer(options = {}) ⇒ Object
-
#compile_scss(modified_stylesheet) ⇒ Object
-
#connectives_spans(text) ⇒ Object
-
#convert(input_filename, file = nil, debug = false, output_filename = nil) ⇒ Object
-
#convert1(docxml, filename, dir) ⇒ Object
-
#convert1_namespaces(html) ⇒ Object
-
#convert_i18n_init(docxml) ⇒ Object
-
#convert_i18n_init1(docxml) ⇒ Object
-
#convert_init(file, input_filename, debug) ⇒ Object
-
#convert_scss(filename, stylesheet, stripwordcss) ⇒ Object
-
#default_file_locations(_options) ⇒ Object
none for this parent gem, but will be populated in child gems which have access to stylesheets &c.
-
#default_fonts(_options) ⇒ Object
-
#docid_l10n(text) ⇒ Object
-
#docid_prefix(prefix, docid) ⇒ Object
-
#fonts_options ⇒ Object
-
#generate_css(filename, stripwordcss) ⇒ Object
stripwordcss if HTML stylesheet, !stripwordcss if DOC stylesheet.
-
#html_doc_path(*file) ⇒ Object
-
#i18n_init(lang, script, locale, i18nyaml = nil) ⇒ Object
-
#init_arrangement(options) ⇒ Object
-
#init_covers(options) ⇒ Object
-
#init_fonts(options) ⇒ Object
-
#init_i18n(options) ⇒ Object
-
#init_locations(options) ⇒ Object
-
#init_processing ⇒ Object
-
#init_rendering(options) ⇒ Object
-
#init_stylesheets(options) ⇒ Object
-
#init_toc(options) ⇒ Object
-
#initialize(options) ⇒ Convert
constructor
htmlstylesheet: Generic stylesheet for HTML htmlstylesheet_override: Override stylesheet for HTML wordstylesheet: Generic stylesheet for Word wordstylesheet_override: Override stylesheet for Word standardsheet: Stylesheet specific to Standard header: Header file for Word htmlcoverpage: Cover page for HTML wordcoverpage: Cover page for Word htmlintropage: Introductory page for HTML wordintropage: Introductory page for Word normalfontsize: Font size for body text smallerfontsize: Font size for smaller than body text monospacefontsize: Font size for monospace font footnotefontsize: Font size for footnotes i18nyaml: YAML file for internationalisation of text ulstyle: list style in Word CSS for unordered lists olstyle: list style in Word CSS for ordered lists bodyfont: font to use for body text headerfont: font to use for header text monospace: font to use for monospace text suppressheadingnumbers: suppress heading numbers for clauses scripts: Scripts file for HTML scripts_override: Override scripts file for HTML scripts_pdf: Scripts file for PDF (not used in XSLT PDF) datauriimage: Encode images in HTML output as data URIs breakupurlsintables: whether to insert spaces in URLs in tables every 40-odd chars sectionsplit: split up HTML output on sections bare: do not insert any prefatory material (coverpage, boilerplate) tocfigures: add ToC for figures toctables: add ToC for tables tocrecommendations: add ToC for rcommendations fonts: fontist fonts to install fontlicenseagreement: fontist font license agreement modspecidentifierbase: base prefix for any Modspec identifiers sourcehighlighter: whether to apply sourcecode highlighting semantic_xml_insert: whether to insert into presentation XML a copy of semantic XML output_formats: hash of supported output formats and suffixes.
-
#l10n(expr, lang = @lang, script = @script, locale = @locale) ⇒ Object
-
#load_scss_paths(filename) ⇒ Object
-
#localpath(path) ⇒ Object
-
#metadata_init(lang, script, locale, i18n) ⇒ Object
-
#middle_clause(_docxml = nil) ⇒ Object
-
#omit_docid_prefix(prefix) ⇒ Object
-
#options_preprocess(options) ⇒ Object
-
#populate_css ⇒ Object
run this after @meta is populated.
-
#precompiled_style_or_original(stylesheet_path) ⇒ Object
Check if already compiled version(.css) exists, if not, return original scss file.
-
#preprocess_css(stylesheet, html) ⇒ Object
-
#scss_fontheader(is_html_css) ⇒ Object
-
#swap_renderer(oldklass, newklass, file, input_filename, debug) ⇒ Object
use a different class than self for rendering, as a result of document-specific criteria but pass on any singleton methods defined on top of the self instance.
-
#target_pdf(node) ⇒ Object
-
#tmpfilesdir_suffix ⇒ Object
-
#tmpimagedir_suffix ⇒ Object
-
#toc_init(docxml) ⇒ Object
-
#write_css(filename, stylesheet) ⇒ Object
-
#xref_init(lang, script, _klass, i18n, options) ⇒ Object
Methods included from ClassUtils
#case_strict, #case_strict1, #case_with_markup, #date_range, #liquid, #nearest_block_parent, #ns, #start_of_sentence, #to_xml
#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, #to_xml
#body_attr, #boilerplate, #content, #cross_align, #define_head, #info, #init_dir, #init_file, #make_body, #make_body1, #make_body2, #make_body3, #note?, #parse, #rel_tmpimagedir, #tmpimagedir, #top_element_render
#admitted_term_parse, #definition_parse, #deprecated_term_parse, #modification_parse, #semx_admitted_term_parse, #semx_deprecated_term_parse, #semx_related_parse, #semx_term_parse, #semx_termref_parse, #term_parse, #termdef_parse, #termdocsource_parse, #termdomain_parse, #termnote_p_class, #termnote_parse, #termnote_parse1, #termref_parse
#colgroup, #make_tr_attr, #make_tr_attr_style, #table_attrs, #table_parse, #table_parse_core, #table_parse_tail, #table_title_parse, #tbody_parse, #tcaption, #tfoot_parse, #thead_parse, #tr_parse
#abstract, #acknowledgements, #annex, #annex_attrs, #annex_name, #clause, #clause_attrs, #clause_name, #clause_parse, #clause_parse_subtitle, #clause_parse_title, #clause_parse_title1, #clause_title_depth, #clausedelim, #clausedelimspace, #colophon, #copyright_parse, #executivesummary, #feedback_parse, #footnotes, #foreword, #freestanding_title, #indexsect, #inline_header_title, #introduction, #is_clause?, #legal_parse, #license_parse, #preface, #preface_attrs, #preface_block, #preface_normal, #scope, #sections_names, #single_term_clause?, #symbols_abbrevs, #symbols_parse, #table_of_contents, #terms_defs, #terms_parse, #variant_title
#bibitem_entry, #biblio_list, #bibliography, #bibliography_parse, #bibliography_xpath, #iso_bibitem_entry_attrs, #norm_ref, #norm_ref_xpath, #reference_format
#dl_attrs, #dl_parse, #dl_parse1, #dl_parse_notes, #dt_dd?, #dt_parse, #li_parse, #list_title_parse, #ol_attrs, #ol_depth, #ol_parse, #ol_style, #ul_attrs, #ul_parse
#footnote_parse, #get_table_ancestor_id, #make_table_footnote_link, #table_footnote_parse, #update_table_fn_body_ref
#add_parse, #amend_parse, #asciimath_parse, #author_parse, #bookmark_parse, #br_parse, #callout_parse, #children_parse, #concept_parse, #date_parse, #del_parse, #em_parse, #eref_parse, #erefstack_parse, #error_parse, #floating_title_parse, #fmt_concept_parse, #fmt_date_parse, #fmt_fn_label_parse, #fmt_footnote_container_parse, #fmt_identifier_parse, #fmt_name_parse, #hr_parse, #identifier_parse, #image_body_parse, #image_parse, #image_title_parse, #index_parse, #index_xref_parse, #keyword_parse, #latexmath_parse, #link_parse, #location_parse, #mathml_parse, #name_parse, #no_locality_parse, #origin_parse, #page_break, #pagebreak_parse, #rb_parse, #rt_parse, #ruby_parse, #section_break, #semx_definition_parse, #semx_eref_parse, #semx_link_parse, #semx_origin_parse, #semx_parse, #semx_sourcecode_parse, #semx_stem_parse, #semx_xref_parse, #smallcap_parse, #span_parse, #stem_parse, #strike_parse, #strong_parse, #sub_parse, #suffix_url, #sup_parse, #svgmap_parse, #termrefelem_parse, #text_parse, #tt_parse, #underline_parse, #xref_label_parse, #xref_parse
#form_parse, #input_parse, #label_parse, #option_parse, #select_parse, #text_input, #textarea_parse
#admonition_cleanup, #cleanup, #example_cleanup, #figure_cleanup, #footnote_cleanup, #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_get_or_make_tfoot, #table_note_cleanup, #textcleanup
#admonition_attrs, #admonition_class, #admonition_name, #admonition_name_in_first_para, #admonition_name_para_delim, #admonition_name_parse, #admonition_p_parse, #admonition_parse, #admonition_parse1, #annotation_parse, #attribution_parse, #block_body_first_elem, #columnbreak_parse, #cross_align_parse, #div_parse, #example_div_attr, #example_div_parse, #example_label, #example_parse, #example_table_attr, #example_table_parse, #figure_attrs, #figure_name_parse, #figure_parse, #figure_parse1, #fmt_fn_body_parse, #formula_attrs, #formula_parse, #formula_parse1, #keep_style, #note_attrs, #note_p_class, #note_p_parse, #note_parse, #note_parse1, #para_attrs, #para_class, #para_parse, #passthrough_parse, #permission_parse, #pre_parse, #pseudocode_attrs, #pseudocode_parse, #quote_parse, #recommendation_name, #recommendation_parse, #recommendation_parse1, #reqt_attrs, #requirement_parse, #source_parse, #sourcecode_attrs, #sourcecode_name_parse, #sourcecode_parse, #sourcecode_parse1, #starts_with_para?, #svg_parse, #toc_parse
Constructor Details
#initialize(options) ⇒ Convert
htmlstylesheet: Generic stylesheet for HTML htmlstylesheet_override: Override stylesheet for HTML wordstylesheet: Generic stylesheet for Word wordstylesheet_override: Override stylesheet for Word standardsheet: Stylesheet specific to Standard header: Header file for Word htmlcoverpage: Cover page for HTML wordcoverpage: Cover page for Word htmlintropage: Introductory page for HTML wordintropage: Introductory page for Word normalfontsize: Font size for body text smallerfontsize: Font size for smaller than body text monospacefontsize: Font size for monospace font footnotefontsize: Font size for footnotes i18nyaml: YAML file for internationalisation of text ulstyle: list style in Word CSS for unordered lists olstyle: list style in Word CSS for ordered lists bodyfont: font to use for body text headerfont: font to use for header text monospace: font to use for monospace text suppressheadingnumbers: suppress heading numbers for clauses scripts: Scripts file for HTML scripts_override: Override scripts file for HTML scripts_pdf: Scripts file for PDF (not used in XSLT PDF) datauriimage: Encode images in HTML output as data URIs breakupurlsintables: whether to insert spaces in URLs in tables
every 40-odd chars
sectionsplit: split up HTML output on sections bare: do not insert any prefatory material (coverpage, boilerplate) tocfigures: add ToC for figures toctables: add ToC for tables tocrecommendations: add ToC for rcommendations fonts: fontist fonts to install fontlicenseagreement: fontist font license agreement modspecidentifierbase: base prefix for any Modspec identifiers sourcehighlighter: whether to apply sourcecode highlighting semantic_xml_insert: whether to insert into presentation XML
a copy of semantic XML
output_formats: hash of supported output formats and suffixes
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/isodoc/convert.rb', line 55
def initialize(options) @options = options_preprocess(options)
init_stylesheets(@options)
init_covers(@options)
init_toc(@options)
init_fonts(@options)
init_processing
init_locations(@options)
init_i18n(@options)
init_rendering(@options)
init_arrangement(@options)
end
|
Instance Attribute Details
#bibrender ⇒ Object
Returns the value of attribute bibrender.
12
13
14
|
# File 'lib/isodoc/convert.rb', line 12
def bibrender
@bibrender
end
|
Returns the value of attribute doctype.
12
13
14
|
# File 'lib/isodoc/convert.rb', line 12
def doctype
@doctype
end
|
Returns the value of attribute i18n.
12
13
14
|
# File 'lib/isodoc/convert.rb', line 12
def i18n
@i18n
end
|
Returns the value of attribute meta.
12
13
14
|
# File 'lib/isodoc/convert.rb', line 12
def meta
@meta
end
|
Returns the value of attribute options.
12
13
14
|
# File 'lib/isodoc/convert.rb', line 12
def options
@options
end
|
#reqt_models ⇒ Object
Returns the value of attribute reqt_models.
12
13
14
|
# File 'lib/isodoc/convert.rb', line 12
def reqt_models
@reqt_models
end
|
#requirements_processor ⇒ Object
Returns the value of attribute requirements_processor.
12
13
14
|
# File 'lib/isodoc/convert.rb', line 12
def requirements_processor
@requirements_processor
end
|
#tempfile_cache ⇒ Object
Returns the value of attribute tempfile_cache.
12
13
14
|
# File 'lib/isodoc/convert.rb', line 12
def tempfile_cache
@tempfile_cache
end
|
#wordcoverpage ⇒ Object
Returns the value of attribute wordcoverpage.
12
13
14
|
# File 'lib/isodoc/convert.rb', line 12
def wordcoverpage
@wordcoverpage
end
|
#wordintropage ⇒ Object
Returns the value of attribute wordintropage.
12
13
14
|
# File 'lib/isodoc/convert.rb', line 12
def wordintropage
@wordintropage
end
|
Returns the value of attribute xrefs.
12
13
14
|
# File 'lib/isodoc/convert.rb', line 12
def xrefs
@xrefs
end
|
Instance Method Details
#agency?(text) ⇒ Boolean
141
142
143
|
# File 'lib/isodoc/init.rb', line 141
def agency?(text)
self.class::AGENCIES.include?(text)
end
|
#bibrenderer(options = {}) ⇒ Object
88
89
90
91
|
# File 'lib/isodoc/convert.rb', line 88
def bibrenderer(options = {})
::Relaton::Render::IsoDoc::General.new(options.merge(language: @lang,
i18nhash: @i18n.get))
end
|
#compile_scss(modified_stylesheet) ⇒ Object
88
89
90
91
92
93
94
|
# File 'lib/isodoc/css.rb', line 88
def compile_scss(modified_stylesheet)
SassC::Engine
.new(modified_stylesheet, quiet_deps: true, syntax: :scss,
silence_deprecations: %w(mixed-decls),
importer: SasscImporter)
.render.gsub(/__WORD__/, "")
end
|
#connectives_spans(text) ⇒ Object
167
168
169
170
171
172
173
174
|
# File 'lib/isodoc/init.rb', line 167
def connectives_spans(text)
text.gsub("<conn>", "<span class='fmt-conn'>")
.gsub("</conn>", "</span>")
.gsub("<enum-comma>", "<span class='fmt-enum-comma'>")
.gsub("</enum-comma>", "</span>")
.gsub("<comma>", "<span class='fmt-comma'>")
.gsub("</comma>", "</span>")
end
|
#convert(input_filename, file = nil, debug = false, output_filename = nil) ⇒ Object
142
143
144
145
146
147
148
149
150
151
152
|
# File 'lib/isodoc/convert.rb', line 142
def convert(input_filename, file = nil, debug = false,
output_filename = nil)
file = File.read(input_filename, encoding: "utf-8") if file.nil?
@openmathdelim, @closemathdelim = (file)
docxml, filename, dir = convert_init(file, input_filename, debug)
result = convert1(docxml, filename, dir)
debug and return result
output_filename ||= "#{filename}.#{@suffix}"
postprocess(result, output_filename, dir)
FileUtils.rm_rf dir
end
|
#convert1(docxml, filename, dir) ⇒ Object
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/isodoc/convert.rb', line 97
def convert1(docxml, filename, dir)
@xrefs.parse docxml
noko do |xml|
xml.html lang: @lang.to_s do |html|
convert1_namespaces(html.parent)
info docxml, nil
populate_css
html.head { |head| define_head head, filename, dir }
make_body(html, docxml)
end
end.join("\n")
end
|
#convert1_namespaces(html) ⇒ Object
93
94
95
|
# File 'lib/isodoc/convert.rb', line 93
def convert1_namespaces(html)
html.add_namespace("epub", "http://www.idpf.org/2007/ops")
end
|
#convert_i18n_init(docxml) ⇒ Object
122
123
124
125
126
127
128
129
130
|
# File 'lib/isodoc/convert.rb', line 122
def convert_i18n_init(docxml)
convert_i18n_init1(docxml)
i18n_init(@lang, @script, @locale)
@bibrender ||= bibrenderer
@reqt_models = requirements_processor
.new({ default: "default", lang: @lang, script: @script,
locale: @locale, labels: @i18n.get,
modspecidentifierbase: @modspecidentifierbase })
end
|
#convert_i18n_init1(docxml) ⇒ Object
132
133
134
135
136
137
138
139
140
|
# File 'lib/isodoc/convert.rb', line 132
def convert_i18n_init1(docxml)
lang = docxml.at(ns("//bibdata/language")) and @lang = lang.text
if script = docxml.at(ns("//bibdata/script"))
@script = script.text
elsif lang
@script = ::Metanorma::Utils::default_script(@lang)
end
locale = docxml.at(ns("//bibdata/locale")) and @locale = locale.text
end
|
#convert_init(file, input_filename, debug) ⇒ Object
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/isodoc/convert.rb', line 110
def convert_init(file, input_filename, debug)
docxml = Nokogiri::XML(file, &:huge)
filename, dir = init_file(input_filename, debug)
docxml.root.default_namespace = ""
convert_i18n_init(docxml)
metadata_init(@lang, @script, @locale, @i18n)
xref_init(@lang, @script, self, @i18n,
{ locale: @locale, bibrender: @bibrender })
toc_init(docxml)
[docxml, filename, dir]
end
|
#convert_scss(filename, stylesheet, stripwordcss) ⇒ Object
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/isodoc/css.rb', line 77
def convert_scss(filename, stylesheet, stripwordcss)
load_scss_paths(filename)
Dir.mktmpdir do |dir|
variables_file_path = File.join(dir, "variables.scss")
File.write(variables_file_path, (stripwordcss))
SassC.load_paths << dir
modified_stylesheet = %( @use "variables" as *;\n#{stylesheet})
compile_scss(modified_stylesheet)
end
end
|
#default_file_locations(_options) ⇒ Object
none for this parent gem, but will be populated in child gems which have access to stylesheets &c
48
49
50
|
# File 'lib/isodoc/css.rb', line 48
def default_file_locations(_options)
{}
end
|
#default_fonts(_options) ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/isodoc/css.rb', line 38
def default_fonts(_options)
{
bodyfont: "Arial",
headerfont: "Arial",
monospacefont: "Courier New",
}
end
|
#docid_l10n(text) ⇒ Object
145
146
147
148
149
150
151
152
153
|
# File 'lib/isodoc/init.rb', line 145
def docid_l10n(text)
text.nil? and return text
@i18n.all_parts and text.gsub!(/All Parts/i, @i18n.all_parts.downcase)
x = Nokogiri::XML::DocumentFragment.parse(text)
(x.xpath(".//text()") - x.xpath(".//fn//text()")).each do |n|
n.replace(n.text.gsub(/ /, " "))
end
to_xml(x)
end
|
#docid_prefix(prefix, docid) ⇒ Object
155
156
157
158
159
|
# File 'lib/isodoc/init.rb', line 155
def docid_prefix(prefix, docid)
docid = "#{prefix} #{docid}" if prefix && !omit_docid_prefix(prefix) &&
!/^#{prefix}\b/.match(docid)
docid_l10n(docid)
end
|
#fonts_options ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/isodoc/css.rb', line 52
def fonts_options
{
"bodyfont" => options[:bodyfont] || "Arial",
"headerfont" => options[:headerfont] || "Arial",
"monospacefont" => options[:monospacefont] || "Courier New",
"normalfontsize" => options[:normalfontsize],
"monospacefontsize" => options[:monospacefontsize],
"smallerfontsize" => options[:smallerfontsize],
"footnotefontsize" => options[:footnotefontsize],
}
end
|
#generate_css(filename, stripwordcss) ⇒ Object
stripwordcss if HTML stylesheet, !stripwordcss if DOC stylesheet
107
108
109
110
111
112
113
114
115
|
# File 'lib/isodoc/css.rb', line 107
def generate_css(filename, stripwordcss)
filename.nil? and return nil
filename = precompiled_style_or_original(filename)
stylesheet = File.read(filename, encoding: "UTF-8")
stylesheet = preprocess_css(stylesheet, stripwordcss)
File.extname(filename) == ".scss" and
stylesheet = convert_scss(filename, stylesheet, stripwordcss)
write_css(filename, stylesheet)
end
|
#html_doc_path(*file) ⇒ Object
76
77
78
79
80
81
82
|
# File 'lib/isodoc/convert.rb', line 76
def html_doc_path(*file)
file.each do |f|
ret = File.join(@libdir, File.join("html", f))
File.exist?(ret) and return ret
end
nil
end
|
#i18n_init(lang, script, locale, i18nyaml = nil) ⇒ Object
12
13
14
15
|
# File 'lib/isodoc/init.rb', line 12
def i18n_init(lang, script, locale, i18nyaml = nil)
@i18n = I18n.new(lang, script, locale: locale,
i18nyaml: i18nyaml || @i18nyaml)
end
|
#init_arrangement(options) ⇒ Object
54
55
56
57
58
59
|
# File 'lib/isodoc/init.rb', line 54
def init_arrangement(options)
@sectionsplit = options[:sectionsplit] == "true"
@bare = options[:bare]
@semantic_xml_insert = options[:semanticxmlinsert] != "false"
@log = options[:log]
end
|
#init_covers(options) ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/isodoc/init.rb', line 109
def init_covers(options)
@header = options[:header]
@htmlcoverpage = options[:htmlcoverpage]
@wordcoverpage = options[:wordcoverpage]
@htmlintropage = options[:htmlintropage]
@wordintropage = options[:wordintropage]
@scripts = options[:scripts] ||
File.join(File.dirname(__FILE__), "base_style", "scripts.html")
@scripts_pdf = options[:scripts_pdf]
@scripts_override = options[:scripts_override]
end
|
#init_fonts(options) ⇒ Object
100
101
102
103
104
105
106
107
|
# File 'lib/isodoc/init.rb', line 100
def init_fonts(options)
@normalfontsize = options[:normalfontsize]
@smallerfontsize = options[:smallerfontsize]
@monospacefontsize = options[:monospacefontsize]
@footnotefontsize = options[:footnotefontsize]
@fontist_fonts = options[:fonts]
@fontlicenseagreement = options[:fontlicenseagreement]
end
|
#init_i18n(options) ⇒ Object
61
62
63
64
65
66
67
|
# File 'lib/isodoc/init.rb', line 61
def init_i18n(options)
@i18nyaml = options[:i18nyaml]
@lang = options[:language] || "en"
@script = options[:script] || "Latn"
@locale = options[:locale]
@localizenumber = options[:localizenumber]
end
|
#init_locations(options) ⇒ Object
69
70
71
72
73
74
75
76
77
|
# File 'lib/isodoc/init.rb', line 69
def init_locations(options)
@libdir ||= File.dirname(__FILE__)
@baseassetpath = options[:baseassetpath]
@tmpimagedir_suffix = tmpimagedir_suffix
@tmpfilesdir_suffix = tmpfilesdir_suffix
@sourcefilename = options[:sourcefilename]
@files_to_delete = []
@tempfile_cache = []
end
|
#init_processing ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/isodoc/init.rb', line 79
def init_processing
@termdomain = ""
@termexample = false
@note = false
@sourcecode = false
@footnotes = []
@comments = []
@in_footnote = false
@in_comment = false
@in_table = false
@in_figure = false
@seen_footnote = Set.new
@c = HTMLEntities.new
@openmathdelim = "`"
@closemathdelim = "`"
@maxwidth = 1200
@maxheight = 800
@bookmarks_allocated = { "X" => true }
@fn_bookmarks = {}
end
|
#init_rendering(options) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/isodoc/init.rb', line 41
def init_rendering(options)
@ulstyle = options[:ulstyle]
@olstyle = options[:olstyle]
@datauriimage = options[:datauriimage]
@suppressheadingnumbers = options[:suppressheadingnumbers]
@break_up_urls_in_tables = options[:breakupurlsintables]
@suppressasciimathdup = options[:suppressasciimathdup]
@aligncrosselements = options[:aligncrosselements]
@modspecidentifierbase = options[:modspecidentifierbase]
@sourcehighlighter = options[:sourcehighlighter]
@output_formats = options[:output_formats] || {}
end
|
#init_stylesheets(options) ⇒ Object
121
122
123
124
125
126
127
|
# File 'lib/isodoc/init.rb', line 121
def init_stylesheets(options)
@htmlstylesheet_name = options[:htmlstylesheet]
@wordstylesheet_name = options[:wordstylesheet]
@htmlstylesheet_override_name = options[:htmlstylesheet_override]
@wordstylesheet_override_name = options[:wordstylesheet_override]
@standardstylesheet_name = options[:standardstylesheet]
end
|
#init_toc(options) ⇒ Object
129
130
131
132
133
134
135
|
# File 'lib/isodoc/init.rb', line 129
def init_toc(options)
@htmlToClevels = 2
@wordToClevels = 2
@tocfigures = options[:tocfigures]
@toctables = options[:toctables]
@tocrecommendations = options[:tocrecommendations]
end
|
#l10n(expr, lang = @lang, script = @script, locale = @locale) ⇒ Object
17
18
19
|
# File 'lib/isodoc/init.rb', line 17
def l10n(expr, lang = @lang, script = @script, locale = @locale)
@i18n.l10n(expr, lang, script, locale)
end
|
#load_scss_paths(filename) ⇒ Object
96
97
98
99
100
101
102
103
104
|
# File 'lib/isodoc/css.rb', line 96
def load_scss_paths(filename)
require "sassc-embedded"
require "isodoc/sassc_importer"
[File.join(Gem.loaded_specs["isodoc"].full_gem_path,
"lib", "isodoc"),
File.dirname(filename)].each do |name|
SassC.load_paths << name
end
end
|
#localpath(path) ⇒ Object
19
20
21
22
23
24
|
# File 'lib/isodoc/css.rb', line 19
def localpath(path)
return path if %r{^[A-Z]:|^/|^file:/}.match?(path)
return path unless (@sourcedir || @localdir) && path
File.expand_path(File.join((@sourcedir || @localdir), path))
end
|
3
4
5
|
# File 'lib/isodoc/init.rb', line 3
def metadata_init(lang, script, locale, i18n)
@meta = Metadata.new(lang, script, locale, i18n)
end
|
#middle_clause(_docxml = nil) ⇒ Object
154
155
156
157
|
# File 'lib/isodoc/convert.rb', line 154
def middle_clause(_docxml = nil)
"//clause[parent::sections][not(@type = 'scope')]" \
"[not(descendant::terms)][not(descendant::references)]"
end
|
#omit_docid_prefix(prefix) ⇒ Object
161
162
163
164
165
|
# File 'lib/isodoc/init.rb', line 161
def omit_docid_prefix(prefix)
prefix.nil? || prefix.empty? and return true
%w(ISO IEC IEV ITU W3C BIPM csd metanorma repository metanorma-ordinal)
.include? prefix
end
|
#options_preprocess(options) ⇒ Object
32
33
34
35
36
37
38
39
|
# File 'lib/isodoc/init.rb', line 32
def options_preprocess(options)
options.merge!(default_fonts(options)) do |_, old, new|
old || new
end.merge!(default_file_locations(options)) do |_, old, new|
old || new
end
options
end
|
#populate_css ⇒ Object
run this after @meta is populated
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/isodoc/css.rb', line 27
def populate_css
@htmlstylesheet = generate_css(localpath(@htmlstylesheet_name), true)
@wordstylesheet = generate_css(localpath(@wordstylesheet_name), false)
@standardstylesheet =
generate_css(localpath(@standardstylesheet_name), false)
@htmlstylesheet_override_name and
@htmlstylesheet_override = File.open(localpath(@htmlstylesheet_override_name))
@wordstylesheet_override_name and
@wordstylesheet_override = File.open(localpath(@wordstylesheet_override_name))
end
|
#precompiled_style_or_original(stylesheet_path) ⇒ Object
Check if already compiled version(.css) exists,
if not, return original scss file. During release
we compile scss into css files in order to not depend on scss
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/isodoc/css.rb', line 6
def precompiled_style_or_original(stylesheet_path)
return stylesheet_path if stylesheet_path.nil? ||
File.extname(stylesheet_path) == ".css"
basename = File.basename(stylesheet_path, ".*")
compiled_path = File.join(File.dirname(stylesheet_path),
"#{basename}.css")
return stylesheet_path unless File.file?(compiled_path)
compiled_path
end
|
#preprocess_css(stylesheet, html) ⇒ Object
126
127
128
129
130
131
132
133
|
# File 'lib/isodoc/css.rb', line 126
def preprocess_css(stylesheet, html)
stylesheet = populate_template(stylesheet, :word)
html and stylesheet.gsub!(/(\s|\{)mso-[^:]+:[^;]+;/m, "\\1")
!html and stylesheet.gsub!(/--/, "-DOUBLE_HYPHEN_ESCAPE-")
!html and stylesheet.gsub!(%r<([a-z])\.([0-9])(?=[^{}]*{)>m,
"\\1.__WORD__\\2")
stylesheet
end
|
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/isodoc/css.rb', line 64
def (is_html_css)
b = options[:bodyfont] || "Arial"
h = options[:headerfont] || "Arial"
m = options[:monospacefont] || "Courier New"
ns = options[:normalfontsize] || (is_html_css ? "1.0em" : "12.0pt")
ms = options[:monospacefontsize] || (is_html_css ? "0.8em" : "11.0pt")
ss = options[:smallerfontsize] || (is_html_css ? "0.9em" : "10.0pt")
fs = options[:footnotefontsize] || (is_html_css ? "0.9em" : "9.0pt")
"$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n"\
"$normalfontsize: #{ns};\n$monospacefontsize: #{ms};\n"\
"$smallerfontsize: #{ss};\n$footnotefontsize: #{fs};\n"
end
|
#swap_renderer(oldklass, newklass, file, input_filename, debug) ⇒ Object
use a different class than self for rendering, as a result of document-specific criteria but pass on any singleton methods defined on top of the self instance
168
169
170
171
172
173
174
175
176
177
|
# File 'lib/isodoc/convert.rb', line 168
def swap_renderer(oldklass, newklass, file, input_filename, debug)
ref = oldklass oldklass.singleton_methods.each do |x|
newklass.define_singleton_method(x) do |*args|
ref.public_send(x, *args)
end
end
oldklass.singleton_methods.empty? or
newklass.convert_init(file, input_filename, debug)
end
|
#target_pdf(node) ⇒ Object
159
160
161
162
163
|
# File 'lib/isodoc/convert.rb', line 159
def target_pdf(node)
if node["target"].include?("#") then node["target"].sub("#", ".pdf#")
else "##{node['target']}"
end
end
|
#tmpfilesdir_suffix ⇒ Object
72
73
74
|
# File 'lib/isodoc/convert.rb', line 72
def tmpfilesdir_suffix
"_#{SecureRandom.hex(8)}_files"
end
|
#tmpimagedir_suffix ⇒ Object
68
69
70
|
# File 'lib/isodoc/convert.rb', line 68
def tmpimagedir_suffix
"_#{SecureRandom.hex(8)}_images"
end
|
#toc_init(docxml) ⇒ Object
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/isodoc/init.rb', line 21
def toc_init(docxml)
@doctype = docxml.at(ns("//bibdata/ext/doctype"))&.text
@xrefs.klass.doctype = @doctype
x = "//metanorma-extension/presentation-metadata" \
"[name[text() = 'TOC Heading Levels']]/value"
n = docxml.at(ns(x.sub("TOC", "DOC TOC"))) and
@wordToClevels = n.text.to_i
n = docxml.at(ns(x.sub("TOC", "HTML TOC"))) and
@htmlToClevels = n.text.to_i
end
|
#write_css(filename, stylesheet) ⇒ Object
117
118
119
120
121
122
123
124
|
# File 'lib/isodoc/css.rb', line 117
def write_css(filename, stylesheet)
Tempfile.open([File.basename(filename, ".*"), "css"],
mode: File::BINARY | File::SHARE_DELETE,
encoding: "utf-8") do |f|
f.write(stylesheet)
f
end
end
|
#xref_init(lang, script, _klass, i18n, options) ⇒ Object
7
8
9
10
|
# File 'lib/isodoc/init.rb', line 7
def xref_init(lang, script, _klass, i18n, options)
html = HtmlConvert.new(language: @lang, script: @script)
@xrefs = Xref.new(lang, script, html, i18n, options)
end
|