require_relative "gbbaseconvert" require "isodoc" module IsoDoc module Gb # A {Converter} implementation that generates GB output, and a document # schema encapsulation of the document for validation class WordConvert < IsoDoc::WordConvert def initialize(options) @common = IsoDoc::Gb::Common.new(options) @standardclassimg = options[:standardclassimg] @libdir = File.dirname(__FILE__) super @lang = "zh" @script = "Hans" end def default_fonts(options) script = options[:script] || "Hans" scope = options[:scope] || "national" { bodyfont: (script == "Hans" ? '"SimSun",serif' : '"Cambria",serif'), headerfont: (script == "Hans" ? '"SimHei",sans-serif' : '"Calibri",sans-serif'), monospacefont: '"Courier New",monospace', titlefont: (scope == "national" ? (script != "Hans" ? '"Cambria",serif' : '"SimSun",serif' ) : (script == "Hans" ? '"SimHei",sans-serif' : '"Calibri",sans-serif' )) } end def default_file_locations(options) { wordstylesheet: html_doc_path("wordstyle.scss"), standardstylesheet: html_doc_path("gb.scss"), header: html_doc_path("header.html"), wordcoverpage: html_doc_path("word_gb_titlepage.html"), wordintropage: html_doc_path("word_gb_intro.html"), ulstyle: "l7", olstyle: "l10", } end ENDLINE = <<~END.freeze END def end_line(_isoxml, out) out.parent.add_child(ENDLINE) end def word_cleanup(docxml) @cleanup.title_cleanup(docxml.at('//div[@class="WordSection2"]')) super end def example_table_parse(node, out) out.table **attr_code(id: node["id"], class: "example") do |t| t.tr do |tr| tr.td **EXAMPLE_TBL_ATTR do |td| td << l10n(example_label(node) + ":") end tr.td **{ valign: "top", class: "example" } do |td| node.children.each { |n| parse(n, td) } end end end end def populate_template(docxml, format) meta = @meta.get.merge(@labels) logo = @common.format_logo(meta[:gbprefix], meta[:gbscope], format, @localdir) logofile = @meta.standard_logo(meta[:gbprefix]) meta[:standard_agency_formatted] = @common.format_agency(meta[:standard_agency], format, @localdir) meta[:standard_logo] = logo template = liquid(docxml) template.render(meta.map { |k, v| [k.to_s, empty2nil(v)] }.to_h). gsub('<', '<').gsub('>', '>').gsub('&', '&') end def annex_name(annex, name, div) div.h1 **{ class: "Annex" } do |t| t << "#{anchor(annex['id'], :label)}

" name&.children&.each { |c2| parse(c2, t) } end end def make_body(xml, docxml) body_attr = { lang: "EN-US", link: "blue", vlink: "#954F72" } xml.body **body_attr do |body| make_body1(body, docxml) make_body2(body, docxml) make_body3(body, docxml) colophon(body, docxml) end end def colophon(body, docxml) body.br **{ clear: "all", style: "page-break-before:left;"\ "mso-break-type:section-break" } body.div **{ class: "colophon" } do |div| div.p **{ class: "colophon" } do |p| p << l10n(@meta.get[:standard_class]) # TODO break up into lines if needed end div.p **{ class: "colophon" } do |p| p << l10n("#{@meta.get[:docsubtitlezh]}") end div.p **{ class: "colophon" } do |p| p << l10n("#{@meta.get[:docidentifier]}") end end end include BaseConvert end end end