Module: Metanorma::Standoc::Base
- Included in:
- Converter
- Defined in:
- lib/metanorma/converter/base.rb,
lib/metanorma/converter/init.rb,
lib/metanorma/converter/render.rb
Constant Summary collapse
- FONTS_MANIFEST =
"fonts-manifest".freeze
Instance Attribute Summary collapse
-
#log ⇒ Object
Returns the value of attribute log.
Instance Method Summary collapse
- #absolute_path_pdf_attributes(pdf_options) ⇒ Object
- #biblio_cutoff(node) ⇒ Object
- #clean_abort(msg, file = nil) ⇒ Object
- #clean_exit ⇒ Object
- #cleanup(result) ⇒ Object
- #cleanup_class ⇒ Object
- #cleanup_log_filter_error_log(locations) ⇒ Object
- #default_fonts(node) ⇒ Object
- #default_svg_conform_profile ⇒ Object
- #doc_converter(node) ⇒ Object
- #doc_extract_attributes(node) ⇒ Object
- #doctype(node) ⇒ Object
- #document(node) ⇒ Object
- #document1(node) ⇒ Object
- #document_scheme(node) ⇒ Object
- #document_scheme_metadata(node) ⇒ Object
- #draft? ⇒ Boolean
- #extract_log_filter_error_loc(node) ⇒ Object
- #flex_attr_name(node, attr) ⇒ Object
- #fonts_manifest_option(node) ⇒ Object
- #front(node, xml) ⇒ Object
- #html_converter(node) ⇒ Object
- #html_extract_attributes(node) ⇒ Object
- #i18nyaml_path(node) ⇒ Object
- #in_isolated_conversion? ⇒ Boolean
- #init(node) ⇒ Object
- #init_bib_db(node) ⇒ Object
- #init_bib_log ⇒ Object
- #init_biblio(node) ⇒ Object
- #init_i18n(node) ⇒ Object
- #init_image(node) ⇒ Object
- #init_log(node) ⇒ Object
- #init_math(node) ⇒ Object
- #init_metadata(node) ⇒ Object
- #init_misc(node) ⇒ Object
- #init_output(node) ⇒ Object
- #init_processing(node) ⇒ Object
- #init_reqt(node) ⇒ Object
- #init_toc(node) ⇒ Object
- #init_vars ⇒ Object
- #init_xref(node) ⇒ Object
- #insert_xml_cr(doc) ⇒ Object
- #makexml(node) ⇒ Object
- #makexml1(node) ⇒ Object
- #metadata_attrs(node) ⇒ Object
- #middle(node, xml) ⇒ Object
- #numberfmt_formula(node) ⇒ Object
- #outputs(node, ret) ⇒ Object
- #pdf_converter(node) ⇒ Object
- #pdf_extract_attributes(node) ⇒ Object
- #presentation_xml_converter(node) ⇒ Object
- #relaton_render_path(node) ⇒ Object
- #requirements_processor ⇒ Object
- #schema_version ⇒ Object
- #toc_default ⇒ Object
- #validate_class ⇒ Object
- #version ⇒ Object
- #xml_namespace ⇒ Object
- #xml_root_tag ⇒ Object
Instance Attribute Details
#log ⇒ Object
Returns the value of attribute log.
25 26 27 |
# File 'lib/metanorma/converter/base.rb', line 25 def log @log end |
Instance Method Details
#absolute_path_pdf_attributes(pdf_options) ⇒ Object
123 124 125 126 127 128 129 130 |
# File 'lib/metanorma/converter/render.rb', line 123 def absolute_path_pdf_attributes() %i(pdfstylesheet pdfstylesheet_override).each do |x| [x] or next (Pathname.new [x]).absolute? or [x] = File.join(File.(@localdir), [x]) end end |
#biblio_cutoff(node) ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/metanorma/converter/init.rb', line 198 def biblio_cutoff(node) dates = %w(revdate published-date accessed-date created-date implemented-date confirmed-date updated-date issued-date circulated-date unchanged-date copyright-year) .each_with_object([]) do |k, m| date = node.attr(k) or next m << date end dates.empty? and return nil complete_and_compare_dates(dates) end |
#clean_abort(msg, file = nil) ⇒ Object
83 84 85 86 87 88 89 90 |
# File 'lib/metanorma/converter/base.rb', line 83 def clean_abort(msg, file = nil) if file doc = to_xml(file) File.open("#{@filename}.xml.abort", "w:UTF-8") { |f| f.write(doc) } end clean_exit abort(msg) end |
#clean_exit ⇒ Object
77 78 79 80 81 |
# File 'lib/metanorma/converter/base.rb', line 77 def clean_exit !@novalid && @local_log and @log.write("#{@output_dir}#{@filename}.err.html") @files_to_delete.each { |f| FileUtils.rm f } end |
#cleanup(result) ⇒ Object
120 121 122 123 124 125 126 127 128 129 |
# File 'lib/metanorma/converter/base.rb', line 120 def cleanup(result) ret1 = Nokogiri::XML(result) @nocleanup and return ret1 cleanup_processor = cleanup_class.new(self) ret1 = cleanup_processor.cleanup(ret1) @log = cleanup_processor.log # Sync log back from cleanup @files_to_delete = cleanup_processor.files_to_delete ret1.root.add_namespace(nil, xml_namespace) ret1 end |
#cleanup_class ⇒ Object
131 132 133 134 135 |
# File 'lib/metanorma/converter/base.rb', line 131 def cleanup_class Object.const_get( self.class.name.sub(/::Converter$/, "::Cleanup"), ) end |
#cleanup_log_filter_error_log(locations) ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/metanorma/converter/init.rb', line 88 def cleanup_log_filter_error_log(locations) locations.each do |loc| loc[:to] ||= loc[:from] loc[:error_ids] ||= [] loc[:error_ids] &&= Array(loc[:error_ids]) end end |
#default_fonts(node) ⇒ Object
143 144 145 146 147 148 149 150 |
# File 'lib/metanorma/converter/render.rb', line 143 def default_fonts(node) b = node.attr("body-font") || (node.attr("script") == "Hans" ? '"Source Han Sans",serif' : '"Cambria",serif') h = node.attr("header-font") || (node.attr("script") == "Hans" ? '"Source Han Sans",sans-serif' : '"Cambria",serif') m = node.attr("monospace-font") || '"Courier New",monospace' "$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n" end |
#default_svg_conform_profile ⇒ Object
105 106 107 |
# File 'lib/metanorma/converter/init.rb', line 105 def default_svg_conform_profile :metanorma end |
#doc_converter(node) ⇒ Object
132 133 134 |
# File 'lib/metanorma/converter/render.rb', line 132 def doc_converter(node) IsoDoc::WordConvert.new(doc_extract_attributes(node)) end |
#doc_extract_attributes(node) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/metanorma/converter/render.rb', line 64 def doc_extract_attributes(node) i18nyaml = i18nyaml_path(node) relaton_render_config = relaton_render_path(node) attrs = { script: flex_attr_name(node, "script"), bodyfont: flex_attr_name(node, "body-font"), headerfont: flex_attr_name(node, "header-font"), monospacefont: flex_attr_name(node, "monospace-font"), i18nyaml: i18nyaml, relatonrenderconfig: relaton_render_config, scope: flex_attr_name(node, "scope"), wordstylesheet: flex_attr_name(node, "word-stylesheet"), wordstylesheet_override: flex_attr_name(node, "word-stylesheet-override"), standardstylesheet: flex_attr_name(node, "standard-stylesheet"), header: flex_attr_name(node, "header"), wordcoverpage: flex_attr_name(node, "wordcoverpage"), wordintropage: flex_attr_name(node, "wordintropage"), ulstyle: flex_attr_name(node, "ulstyle"), olstyle: flex_attr_name(node, "olstyle"), htmltoclevels: @htmltoclevels, doctoclevels: @doctoclevels, pdftoclevels: @pdftoclevels, breakupurlsintables: flex_attr_name(node, "break-up-urls-in-tables"), suppressasciimathdup: flex_attr_name(node, "suppress-asciimath-dup"), bare: flex_attr_name(node, "bare"), baseassetpath: flex_attr_name(node, "base-asset-path"), aligncrosselements: flex_attr_name(node, "align-cross-elements"), tocfigures: @tocfigures, toctables: @toctables, tocrecommendations: @tocrecommendations, fonts: flex_attr_name(node, "fonts"), fontlicenseagreement: flex_attr_name(node, "font-license-agreement"), } if fonts_manifest = node.attr(FONTS_MANIFEST) attrs[IsoDoc::XslfoPdfConvert::MN2PDF_FONT_MANIFEST] = fonts_manifest end attrs end |
#doctype(node) ⇒ Object
145 146 147 148 149 150 |
# File 'lib/metanorma/converter/base.rb', line 145 def doctype(node) ret = node.attr("doctype")&.gsub(/\s+/, "-")&.downcase || @default_doctype ret = @default_doctype if ret == "article" ret end |
#document(node) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/metanorma/converter/base.rb', line 35 def document(node) ret = document1(node) clean_exit ret rescue StandardError => e @log.add("STANDOC_50", nil, params: [e.]) clean_exit raise e end |
#document1(node) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/metanorma/converter/base.rb', line 45 def document1(node) init(node) ret = to_xml(makexml(node)) outputs(node, ret) unless node.attr("nodoc") || !node.attr("docfile") ret end |
#document_scheme(node) ⇒ Object
183 184 185 |
# File 'lib/metanorma/converter/base.rb', line 183 def document_scheme(node) node.attr("document-scheme") end |
#document_scheme_metadata(node) ⇒ Object
177 178 179 180 181 |
# File 'lib/metanorma/converter/base.rb', line 177 def (node) a = document_scheme(node) or return "" "<presentation-metadata><document-scheme>" \ "#{a}</document-scheme></presentation-metadata>" end |
#draft? ⇒ Boolean
141 142 143 |
# File 'lib/metanorma/converter/base.rb', line 141 def draft? @draft end |
#extract_log_filter_error_loc(node) ⇒ Object
82 83 84 85 86 |
# File 'lib/metanorma/converter/init.rb', line 82 def extract_log_filter_error_loc(node) locations = JSON.parse(node.attr("log-filter-error-loc") || "[]") locations = [locations] unless locations.is_a?(Array) locations.map { |loc| loc.transform_keys(&:to_sym) } end |
#flex_attr_name(node, attr) ⇒ Object
4 5 6 7 8 |
# File 'lib/metanorma/converter/render.rb', line 4 def flex_attr_name(node, attr) node.attr(attr) || node.attr(attr.sub("pdf-", "pdf")) || node.attr(attr.delete("-").sub(/override$/, "-override")) || node.attr(attr.delete("-").sub(/override$/, "_override")) end |
#fonts_manifest_option(node) ⇒ Object
163 164 165 166 167 |
# File 'lib/metanorma/converter/render.rb', line 163 def fonts_manifest_option(node) if node.attr(FONTS_MANIFEST) { mn2pdf: { font_manifest: node.attr(FONTS_MANIFEST) } } end end |
#front(node, xml) ⇒ Object
152 153 154 155 156 |
# File 'lib/metanorma/converter/base.rb', line 152 def front(node, xml) xml.bibdata **attr_code(type: "standard") do |b| node, b end end |
#html_converter(node) ⇒ Object
54 55 56 |
# File 'lib/metanorma/converter/render.rb', line 54 def html_converter(node) IsoDoc::HtmlConvert.new(html_extract_attributes(node)) end |
#html_extract_attributes(node) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/metanorma/converter/render.rb', line 10 def html_extract_attributes(node) i18nyaml = i18nyaml_path(node) relaton_render_config = relaton_render_path(node) { script: flex_attr_name(node, "script"), bodyfont: flex_attr_name(node, "body-font"), headerfont: flex_attr_name(node, "header-font"), monospacefont: flex_attr_name(node, "monospace-font"), i18nyaml: i18nyaml, relatonrenderconfig: relaton_render_config, scope: flex_attr_name(node, "scope"), htmlstylesheet: flex_attr_name(node, "html-stylesheet"), htmlstylesheet_override: flex_attr_name(node, "html-stylesheet-override"), htmlcoverpage: flex_attr_name(node, "html-coverpage"), htmlintropage: flex_attr_name(node, "html-intropage"), scripts: flex_attr_name(node, "scripts"), scripts_override: flex_attr_name(node, "scripts-override"), scripts_pdf: flex_attr_name(node, "scripts-pdf"), datauriimage: flex_attr_name(node, "data-uri-image") != "false", htmltoclevels: @htmltoclevels, doctoclevels: @doctoclevels, pdftoclevels: @pdftoclevels, breakupurlsintables: flex_attr_name(node, "break-up-urls-in-tables"), suppressasciimathdup: flex_attr_name(node, "suppress-asciimath-dup") == "true", bare: flex_attr_name(node, "bare"), sectionsplit: flex_attr_name(node, "sectionsplit"), sectionsplit_filename: flex_attr_name(node, "sectionsplit-filename"), baseassetpath: flex_attr_name(node, "base-asset-path"), aligncrosselements: flex_attr_name(node, "align-cross-elements"), tocfigures: @tocfigures, toctables: @toctables, tocrecommendations: @tocrecommendations, fonts: flex_attr_name(node, "fonts"), fontlicenseagreement: flex_attr_name(node, "font-license-agreement"), localizenumber: flex_attr_name(node, "localize-number"), modspecidentifierbase: flex_attr_name(node, "modspec-identifier-base"), sourcehighlighter: flex_attr_name(node, "source-highlighter") != "false", } end |
#i18nyaml_path(node) ⇒ Object
147 148 149 150 151 152 153 |
# File 'lib/metanorma/converter/init.rb', line 147 def i18nyaml_path(node) if ret = node.attr("i18nyaml") (Pathname.new ret).absolute? or ret = File.join(@localdir, ret) end ret end |
#in_isolated_conversion? ⇒ Boolean
137 138 139 |
# File 'lib/metanorma/converter/base.rb', line 137 def in_isolated_conversion? !@isolated_conversion_stack.empty? end |
#init(node) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/metanorma/converter/init.rb', line 8 def init(node) init_vars init_misc(node) init_processing(node) # feeds init_i18n init_log(node) init_image(node) init_reqt(node) init_toc(node) init_output(node) # feeds init_biblio init_i18n(node) init_biblio(node) init_math(node) init_xref(node) (node) end |
#init_bib_db(node) ⇒ Object
184 185 186 187 188 |
# File 'lib/metanorma/converter/init.rb', line 184 def init_bib_db(node) @bibdb = nil @local_bibdb = ::Metanorma::Standoc::LocalBiblio.new(node, @localdir, self) end |
#init_bib_log ⇒ Object
190 191 192 193 194 195 196 |
# File 'lib/metanorma/converter/init.rb', line 190 def init_bib_log @relaton_log = StringIO.new relaton_logger = Relaton::Logger::Log .new(@relaton_log, levels: %i(info warn error fatal unknown), formatter: Relaton::Logger::FormatterJSON) Relaton.logger_pool[:my_logger] = relaton_logger end |
#init_biblio(node) ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/metanorma/converter/init.rb', line 172 def init_biblio(node) @no_isobib_cache = node.attr("no-isobib-cache") @no_isobib = node.attr("no-isobib") @flush_caches = node.attr("flush-caches") @sort_biblio = node.attr("sort-biblio") != "false" init_bib_db(node) init_bib_caches(node) init_iev_caches(node) init_bib_log @biblio_cutoff = biblio_cutoff(node) end |
#init_i18n(node) ⇒ Object
163 164 165 166 167 168 169 170 |
# File 'lib/metanorma/converter/init.rb', line 163 def init_i18n(node) @lang = node.attr("language") || "en" @script = node.attr("script") || Metanorma::Utils.default_script(node.attr("language")) @locale = node.attr("locale") @isodoc = isodoc(@lang, @script, @locale, i18nyaml_path(node)) @i18n = @isodoc.i18n end |
#init_image(node) ⇒ Object
96 97 98 99 100 101 102 103 |
# File 'lib/metanorma/converter/init.rb', line 96 def init_image(node) @datauriimage = node.attr("data-uri-image") != "false" @datauriattachment = node.attr("data-uri-attachment") != "false" @dataurimaxsize = node.attr("data-uri-maxsize")&.to_i || 13981013 @svg_conform_profile = node.attr("svg-conform-profile")&.sub(/^:/, "") || default_svg_conform_profile end |
#init_log(node) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/metanorma/converter/init.rb', line 70 def init_log(node) @log or return @semantic_headless and return severity = node.attr("log-filter-severity")&.to_i || 4 category = csv_split(node.attr("log-filter-category"), ",") error_ids = csv_split(node.attr("log-filter-error-ids"), ",") locations = cleanup_log_filter_error_log( extract_log_filter_error_loc(node), ) @log.suppress_log = { severity:, category:, error_ids:, locations: } end |
#init_math(node) ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/metanorma/converter/init.rb', line 210 def init_math(node) @keepasciimath = node.attr("mn-keep-asciimath") && node.attr("mn-keep-asciimath") != "false" @numberfmt_default = kv_parse(@c.decode(node.attr("number-presentation"))) numberfmt_formula(node) @numberfmt_prof = node.attributes.each_with_object({}) do |(k, v), m| p = /^number-presentation-profile-(.*)$/.match(k) or next m[p[1]] = kv_parse(@c.decode(v)) end end |
#init_metadata(node) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/metanorma/converter/init.rb', line 24 def (node) @doctype = doctype(node) @draft = node.attributes.has_key?("draft") @document_scheme = document_scheme(node) @default_doctype = "standard" @stage_published = node.attr("docstage-published") @metadata_attrs = (node) end |
#init_misc(node) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/metanorma/converter/init.rb', line 44 def init_misc(node) @index_terms = node.attr("index-terms") @boilerplateauthority = node.attr("boilerplate-authority") @embed_hdr = node.attr("embed_hdr") @embed_id = node.attr("embed_id") @source_linenums = node.attr("source-linenums-option") == "true" # feeds log @semantic_headless = node.attr("semantic-metadata-headless") == "true" end |
#init_output(node) ⇒ Object
137 138 139 140 141 142 143 144 145 |
# File 'lib/metanorma/converter/init.rb', line 137 def init_output(node) @fontheader = default_fonts(node) @files_to_delete = [] @filename = if node.attr("docfile") File.basename(node.attr("docfile"))&.gsub(/\.adoc$/, "") else "" end @output_dir = outputdir node end |
#init_processing(node) ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/metanorma/converter/init.rb', line 59 def init_processing(node) @localdir = Metanorma::Utils::localdir(node) @novalid = node.attr("novalid") @nocleanup = node.attr("nocleanup") @isolated_conversion_stack = [] @smartquotes = node.attr("smartquotes") != "false" @sourcecode_markup_start = node.attr("sourcecode-markup-start") || "{{{" @sourcecode_markup_end = node.attr("sourcecode-markup-end") || "}}}" @blockunnumbered = csv_split(node.attr("block-unnumbered"), ",") end |
#init_reqt(node) ⇒ Object
109 110 111 112 113 114 115 116 |
# File 'lib/metanorma/converter/init.rb', line 109 def init_reqt(node) @default_requirement_model = node.attr("requirements-model") || default_requirement_model @default_requirement_render = node.attr("requirements-render") conv = presentation_xml_converter(EmptyAttr.new) @reqt_models = requirements_processor .new({ default: @default_requirement_model, conv: conv }) end |
#init_toc(node) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/metanorma/converter/init.rb', line 118 def init_toc(node) @htmltoclevels = node.attr("toclevels-html") || node.attr("htmltoclevels") || node.attr("toclevels") || toc_default[:html_levels] @doctoclevels = node.attr("toclevels-doc") || node.attr("doctoclevels") || node.attr("toclevels") || toc_default[:word_levels] @pdftoclevels = node.attr("toclevels-pdf") || node.attr("toclevels") || toc_default[:pdf_levels] @toclevels = node.attr("toclevels") || toc_default[:html_levels] @tocfigures = node.attr("toc-figures") @toctables = node.attr("toc-tables") @tocrecommendations = node.attr("toc-recommendations") end |
#init_vars ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/metanorma/converter/init.rb', line 33 def init_vars @fn_number ||= 0 @refids = Set.new @anchors = {} @seen_headers = [] @seen_headers_canonical = [] @embed_hdr = [] @reqt_model = nil @preface = true end |
#init_xref(node) ⇒ Object
53 54 55 56 57 |
# File 'lib/metanorma/converter/init.rb', line 53 def init_xref(node) @xrefstyle = node.attr("xrefstyle") @erefstyle = node.attr("erefstyle") @originstyle = node.attr("originstyle") end |
#insert_xml_cr(doc) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/metanorma/converter/base.rb', line 52 def insert_xml_cr(doc) doc.gsub(%r{(</(clause|table|figure|p|bibitem|ul|ol|dl|dt|dd|li|example| sourcecode|formula|quote|references|annex|appendix|title|name|note| thead|tbody|tfoot|th|td|form|requirement|recommendation|permission| imagemap|svgmap|preferred|admitted|related|domain|deprecates| letter-symbol|graphical-symbol|expression|subject|abbreviation-type| pronunciation|grammar|term|terms|termnote|termexample|source| origin|termref|modification)>)}x, "\\1\n") .gsub(%r{(<(title|name))}, "\n\\1") .gsub(%r{(<sourcecode[^<>]*>)\s+(<name[^<>]*>[^<]+</name>)\s+}, "\\1\\2") end |
#makexml(node) ⇒ Object
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/metanorma/converter/base.rb', line 103 def makexml(node) result = makexml1(node) ret1 = cleanup(result) unless @novalid || in_isolated_conversion? validate_processor = validate_class.new(self) validate_processor.validate(ret1) @files_to_delete = validate_processor.files_to_delete end ret1 end |
#makexml1(node) ⇒ Object
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/metanorma/converter/base.rb', line 92 def makexml1(node) result = [<<~XML, <?xml version='1.0' encoding='UTF-8'?> <#{xml_root_tag} type='semantic' version='#{version}' schema-version='#{schema_version}' flavor='#{processor.new.asciidoctor_backend}'> XML noko { |ixml| front node, ixml }, noko { |ixml| middle node, ixml }, "</#{xml_root_tag}>"] insert_xml_cr(textcleanup(result)) end |
#metadata_attrs(node) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/metanorma/converter/base.rb', line 164 def (node) out = node.attributes.each_with_object([]) do |(k, v), ret| %w(presentation semantic).each do |t| /^#{t}-metadata-/.match?(k) or next k = k.sub(/^#{t}-metadata-/, "") csv_split(v.gsub("&#", "&#"), ",", encode: false)&.each do |c| ret << "<#{t}-metadata><#{k}>#{c}</#{k}></#{t}-metadata>" end end end.join out + (node) end |
#middle(node, xml) ⇒ Object
158 159 160 161 162 |
# File 'lib/metanorma/converter/base.rb', line 158 def middle(node, xml) xml.sections do |s| s << node.content if node.blocks? end end |
#numberfmt_formula(node) ⇒ Object
222 223 224 225 226 227 228 229 230 231 |
# File 'lib/metanorma/converter/init.rb', line 222 def numberfmt_formula(node) @numberfmt_formula = node.attr("number-presentation-formula") @numberfmt_formula.nil? || @numberfmt_formula == "number-presentation" and @numberfmt_formula = @c.decode(node.attr("number-presentation")) @numberfmt_formula == "nil" and @numberfmt_formula = nil @numberfmt_formula == "default" and @numberfmt_formula = "notation='basic'" @numberfmt_formula = @c.decode(@numberfmt_formula) end |
#outputs(node, ret) ⇒ Object
152 153 154 155 156 157 158 159 160 161 |
# File 'lib/metanorma/converter/render.rb', line 152 def outputs(node, ret) File.open("#{@filename}.xml", "w:UTF-8") { |f| f.write(ret) } presentation_xml_converter(node).convert("#{@filename}.xml") html_converter(node).convert("#{@filename}.presentation.xml", nil, false, "#{@filename}.html") doc_converter(node).convert("#{@filename}.presentation.xml", nil, false, "#{@filename}.doc") pdf_converter(node)&.convert("#{@filename}.presentation.xml", nil, false, "#{@filename}.pdf") end |
#pdf_converter(node) ⇒ Object
58 59 60 61 62 |
# File 'lib/metanorma/converter/render.rb', line 58 def pdf_converter(node) return nil if flex_attr_name(node, "no-pdf") IsoDoc::Standoc::PdfConvert.new(pdf_extract_attributes(node)) end |
#pdf_extract_attributes(node) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/metanorma/converter/render.rb', line 106 def pdf_extract_attributes(node) = %w(pdf-encrypt pdf-encryption-length pdf-user-password pdf-owner-password pdf-allow-copy-content pdf-allow-edit-content pdf-allow-fill-in-forms pdf-allow-assemble-document pdf-allow-edit-annotations pdf-allow-print pdf-allow-print-hq pdfkeystore pdfkeystorepassword pdf-allow-access-content pdf-encrypt-metadata fonts pdf-stylesheet pdf-stylesheet-override pdf-portfolio font-license-agreement).each_with_object({}) do |x, m| m[x.delete("-").sub(/override$/, "_override").to_sym] = flex_attr_name(node, x) end absolute_path_pdf_attributes() .merge(fonts_manifest_option(node) || {}) end |
#presentation_xml_converter(node) ⇒ Object
136 137 138 139 140 141 |
# File 'lib/metanorma/converter/render.rb', line 136 def presentation_xml_converter(node) IsoDoc::PresentationXMLConvert .new(html_extract_attributes(node) .merge(output_formats: ::Metanorma::Standoc::Processor.new .output_formats)) end |
#relaton_render_path(node) ⇒ Object
155 156 157 158 159 160 161 |
# File 'lib/metanorma/converter/init.rb', line 155 def relaton_render_path(node) if ret = node.attr("relaton-render-config") (Pathname.new ret).absolute? or ret = File.join(@localdir, ret) end ret end |
#requirements_processor ⇒ Object
233 234 235 |
# File 'lib/metanorma/converter/init.rb', line 233 def requirements_processor Metanorma::Requirements end |
#schema_version ⇒ Object
70 71 72 73 74 75 |
# File 'lib/metanorma/converter/base.rb', line 70 def schema_version f = File.read(File.join(File.dirname(__FILE__), "..", "validate", "isodoc.rng")) m = / VERSION (v\S+)/.match(f) m[1] end |
#toc_default ⇒ Object
133 134 135 |
# File 'lib/metanorma/converter/init.rb', line 133 def toc_default { word_levels: 2, html_levels: 2, pdf_levels: 2 } end |
#validate_class ⇒ Object
114 115 116 117 118 |
# File 'lib/metanorma/converter/base.rb', line 114 def validate_class Object.const_get( self.class.name.sub(/::Converter$/, "::Validate"), ) end |
#version ⇒ Object
65 66 67 68 |
# File 'lib/metanorma/converter/base.rb', line 65 def version flavour = self.class.name.sub(/::Converter$/, "").sub(/^.+::/, "") Metanorma.versioned(Metanorma, flavour)[-1]::VERSION end |
#xml_namespace ⇒ Object
31 32 33 |
# File 'lib/metanorma/converter/base.rb', line 31 def xml_namespace "https://www.metanorma.org/ns/standoc" end |
#xml_root_tag ⇒ Object
27 28 29 |
# File 'lib/metanorma/converter/base.rb', line 27 def xml_root_tag "metanorma" end |