Class: IsoDoc::Gb::WordConvert
- Inherits:
-
WordConvert
- Object
- WordConvert
- IsoDoc::Gb::WordConvert
show all
- Includes:
- BaseConvert, Init
- Defined in:
- lib/isodoc/gb/word_convert.rb
Overview
A Converter implementation that generates GB output, and a document schema encapsulation of the document for validation
Constant Summary
collapse
- ENDLINE =
"<v:line\n alt=\"\" style='position:absolute;left:0;text-align:left;z-index:251662848;\n mso-wrap-edited:f;mso-width-percent:0;mso-height-percent:0;\n mso-width-percent:0;mso-height-percent:0'\n from=\"6.375cm,20.95pt\" to=\"10.625cm,20.95pt\"\n strokeweight=\"1.5pt\"/>\n".freeze
Constants included
from BaseConvert
BaseConvert::EXAMPLE_TBL_ATTR
Instance Method Summary
collapse
Methods included from Init
#i18n_init, #metadata_init, #xref_init
#clausedelimspace, #cleanup, #deprecated_term_parse, #error_parse, #example_cleanup, #example_p_parse, #example_parse, #example_parse1, #example_span_label, #formula_dl_parse, #formula_parse1, #formula_where, #middle, #node_begins_with_para, #note_delim, #note_parse, #note_parse_table, #note_parse_table1, #omit_docid_prefix, #scss_fontheader, #string_parse, #termnote_parse, #termref_render, #termref_resolve, #textcleanup
Constructor Details
#initialize(options) ⇒ WordConvert
Returns a new instance of WordConvert.
10
11
12
13
14
15
16
17
|
# File 'lib/isodoc/gb/word_convert.rb', line 10
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
#colophon(body, docxml) ⇒ Object
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/isodoc/gb/word_convert.rb', line 106
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])
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
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/isodoc/gb/word_convert.rb', line 41
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
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/isodoc/gb/word_convert.rb', line 19
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
62
63
64
|
# File 'lib/isodoc/gb/word_convert.rb', line 62
def end_line(_isoxml, out)
out.parent.add_child(ENDLINE)
end
|
#example_table_parse(node, out) ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/isodoc/gb/word_convert.rb', line 71
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|
node.at(ns("./name")).children.each { |n| parse(n, td) }
end
tr.td **{ valign: "top", class: "example" } do |td|
node.children.each { |n| parse(n, td) unless n.name == "name" }
end
end
end
end
|
#fonts_options ⇒ Object
31
32
33
34
35
36
37
38
39
|
# File 'lib/isodoc/gb/word_convert.rb', line 31
def fonts_options
default_font_options = default_fonts(options)
{
bodyfont: options[:bodyfont] || default_font_options[:bodyfont],
headerfont: options[:headerfont] || default_font_options[:headerfont],
monospacefont: options[:monospacefont] || default_font_options[:monospacefont],
titlefont: options[:titlefont] || default_font_options[:titlefont]
}
end
|
#make_body(xml, docxml) ⇒ Object
96
97
98
99
100
101
102
103
104
|
# File 'lib/isodoc/gb/word_convert.rb', line 96
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
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/isodoc/gb/word_convert.rb', line 84
def populate_template(docxml, format)
meta = @meta.get.merge(@i18n.get).merge(@meta.fonts_options || {})
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
|
#word_cleanup(docxml) ⇒ Object
66
67
68
69
|
# File 'lib/isodoc/gb/word_convert.rb', line 66
def word_cleanup(docxml)
@cleanup.title_cleanup(docxml.at('//div[@class="WordSection2"]'))
super
end
|