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 
 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, #clausedelimspace, #cleanup, #deprecated_term_parse, #error_parse, #example_cleanup, #example_label, #example_p_parse, #example_parse, #example_parse1, #example_span_label, #extract_fonts, #foreword, #formula_dl_parse, #formula_parse, #formula_where, #i18n_init, #metadata_init, #middle, #node_begins_with_para, #note_parse, #note_parse1, #omit_docid_prefix, #string_parse, #termnote_parse, #termref_render, #termref_resolve, #textcleanup

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



85
86
87
88
89
90
# File 'lib/isodoc/gb/gbwordconvert.rb', line 85

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

#colophon(body, docxml) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/isodoc/gb/gbwordconvert.rb', line 102

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

#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



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

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

#make_body(xml, docxml) ⇒ Object



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

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

#populate_template(docxml, format) ⇒ Object



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

def populate_template(docxml, format)
  meta = @meta.get.merge(@labels)
   = @common.(meta[:gbprefix], meta[:gbscope], format, @localdir)
  logofile = @meta.(meta[:gbprefix])
  meta[:standard_agency_formatted] =
    @common.format_agency(meta[:standard_agency], format, @localdir)
  meta[:standard_logo] = 
  template = liquid(docxml)
template.render(meta.map { |k, v| [k.to_s, empty2nil(v)] }.to_h).
  gsub('&lt;', '&#x3c;').gsub('&gt;', '&#x3e;').gsub('&amp;', '&#x26;')
end

#word_cleanup(docxml) ⇒ Object



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

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