Class: IsoDoc::Gb::WordConvert

Inherits:
WordConvert
  • Object
show all
Includes:
BaseConvert
Defined in:
lib/isodoc/gb/gbwordconvert.rb

Overview

A Converter implementation that generates GB output, and a document schema encapsulation of the document for validation

Constant Summary collapse

ENDLINE =
<<~END.freeze
<v:line id="_x0000_s1026"
 alt="" style='position:absolute;left:0;text-align:left;z-index:251662848;
 mso-wrap-edited:f;mso-width-percent:0;mso-height-percent:0;
 mso-width-percent:0;mso-height-percent:0'
 from="6.375cm,20.95pt" to="10.625cm,20.95pt"
 strokeweight="1.5pt"/>
END

Constants included from BaseConvert

BaseConvert::EXAMPLE_TBL_ATTR

Instance Method Summary collapse

Methods included from BaseConvert

#clause_name, #clause_parse_title, #cleanup, #deprecated_term_parse, #error_parse, #example_cleanup, #example_label, #example_p_parse, #example_parse, #example_parse1, #extract_fonts, #foreword, #formula_dl_parse, #formula_parse, #formula_where, #i18n_init, #metadata_init, #middle, #note_parse, #omit_docid_prefix, #string_parse, #termnote_parse, #termref_render, #termref_resolve

Constructor Details

#initialize(options) ⇒ WordConvert

Returns a new instance of WordConvert.



9
10
11
12
13
14
15
16
# File 'lib/isodoc/gb/gbwordconvert.rb', line 9

def initialize(options)
  @common = IsoDoc::Gb::Common.new(options)
  @standardclassimg = options[:standardclassimg]
  @libdir = File.dirname(__FILE__)
  super
  @lang = "zh"
  @script = "Hans"
end

Instance Method Details

#annex_name(annex, name, div) ⇒ Object



88
89
90
91
92
93
# File 'lib/isodoc/gb/gbwordconvert.rb', line 88

def annex_name(annex, name, div)
  div.h1 **{ class: "Annex" } do |t|
    t << "#{anchor(annex['id'], :label)}<br/><br/>"
    name&.children&.each { |c2| parse(c2, t) }
  end
end

#default_file_locations(options) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/isodoc/gb/gbwordconvert.rb', line 30

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

#default_fonts(options) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/isodoc/gb/gbwordconvert.rb', line 18

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

#end_line(_isoxml, out) ⇒ Object



51
52
53
# File 'lib/isodoc/gb/gbwordconvert.rb', line 51

def end_line(_isoxml, out)
  out.parent.add_child(ENDLINE)
end

#example_table_parse(node, out) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/isodoc/gb/gbwordconvert.rb', line 62

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

#populate_template(docxml, format) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/isodoc/gb/gbwordconvert.rb', line 75

def populate_template(docxml, format)
  meta = @meta.get.merge(@labels)
   = @common.(meta[:gbprefix], meta[:gbscope], format, @localdir)
  logofile = @meta.(meta[:gbprefix])
  @files_to_delete << logofile + ".gif" unless logofile.nil?
  docxml = termref_resolve(docxml)
  meta[:standard_agency_formatted] =
    @common.format_agency(meta[:standard_agency], format, @localdir)
  meta[:standard_logo] = 
  template = Liquid::Template.parse(docxml)
  template.render(meta.map { |k, v| [k.to_s, v] }.to_h)
end

#term_defs_boilerplate(div, source, term, preface) ⇒ Object



95
96
97
98
99
# File 'lib/isodoc/gb/gbwordconvert.rb', line 95

def term_defs_boilerplate(div, source, term, preface)
  (source.empty? && term.nil?) and div << @no_terms_boilerplate or
    div << term_defs_boilerplate_cont(source, term)
  #div << @term_def_boilerplate unless preface
end

#word_cleanup(docxml) ⇒ Object



55
56
57
58
59
60
# File 'lib/isodoc/gb/gbwordconvert.rb', line 55

def word_cleanup(docxml)
  word_preface(docxml)
  word_annex_cleanup(docxml)
  @cleanup.title_cleanup(docxml.at('//div[@class="WordSection2"]'))
  docxml
end