Module: IsoDoc::Ogc::BaseConvert

Included in:
HtmlConvert, PdfConvert, WordConvert
Defined in:
lib/isodoc/ogc/base_convert.rb

Constant Summary collapse

SUBMITTINGORGS =
"//bibdata/contributor[role/@type = 'author']/organization/name".freeze
REQ_TBL_ATTR =
{ valign: "top", class: "example_label",
style: "width:100.0pt;padding:0 0 0 1em;margin-left:0pt" }.freeze
MIDDLE_CLAUSE =
"//clause[parent::sections][not(xmlns:title = 'Scope' or xmlns:title = 'Conformance')]"\
"[not(descendant::terms)]".freeze

Instance Method Summary collapse

Instance Method Details

#abstract(isoxml, out) ⇒ Object



108
109
110
111
112
113
114
115
116
# File 'lib/isodoc/ogc/base_convert.rb', line 108

def abstract(isoxml, out)
  f = isoxml.at(ns("//preface/abstract")) || return
  @prefacenum += 1
  page_break(out)
  out.div **attr_code(id: f["id"]) do |s|
    clause_name(get_anchors[f["id"]][:label], @abstract_lbl, s, class: "AbstractTitle")
    f.elements.each { |e| parse(e, s) unless e.name == "title" }
  end
end

#anchor_names(docxml) ⇒ Object



144
145
146
147
148
149
# File 'lib/isodoc/ogc/base_convert.rb', line 144

def anchor_names(docxml)
  super
  recommendation_anchor_names(docxml)
  requirement_anchor_names(docxml)
  permission_anchor_names(docxml)
end

#annex_name(annex, name, div) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/isodoc/ogc/base_convert.rb', line 8

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

#cleanup(docxml) ⇒ Object



30
31
32
33
# File 'lib/isodoc/ogc/base_convert.rb', line 30

def cleanup(docxml)
  super
  term_cleanup(docxml)
end

#conformance(isoxml, out, num) ⇒ Object

def clause_names(docxml, sect_num)

  docxml.xpath(ns(self.class::MIDDLE_CLAUSE)).each_with_index do |c, i|
    section_names(c, (i + sect_num), 1)
  end
end


298
299
300
301
302
303
304
305
306
307
308
# File 'lib/isodoc/ogc/base_convert.rb', line 298

def conformance(isoxml, out, num)
  f = isoxml.at(ns("//clause[title = 'Conformance']")) or return num
  out.div **attr_code(id: f["id"]) do |div|
    num = num + 1
    clause_name(num, "Conformance", div, nil)
    f.elements.each do |e|
      parse(e, div) unless e.name == "title"
    end
  end
  num
end

#error_parse(node, out) ⇒ Object



134
135
136
137
138
139
140
141
142
# File 'lib/isodoc/ogc/base_convert.rb', line 134

def error_parse(node, out)
  case node.name
  when "recommendation" then recommendation_parse(node, out)
  when "requirement" then requirement_parse(node, out)
  when "permission" then permission_parse(node, out)
  else
    super
  end
end

#example_parse(node, out) ⇒ Object



128
129
130
131
132
# File 'lib/isodoc/ogc/base_convert.rb', line 128

def example_parse(node, out)
  name = node.at(ns("./name"))
  sourcecode_name_parse(node, out, name) if name
  super
end

#fileloc(loc) ⇒ Object



26
27
28
# File 'lib/isodoc/ogc/base_convert.rb', line 26

def fileloc(loc)
  File.join(File.dirname(__FILE__), loc)
end

#foreword(isoxml, out) ⇒ Object



118
119
120
121
122
123
124
125
126
# File 'lib/isodoc/ogc/base_convert.rb', line 118

def foreword(isoxml, out)
  f = isoxml.at(ns("//foreword")) || return
  @prefacenum += 1
  page_break(out)
  out.div **attr_code(id: f["id"]) do |s|
    clause_name(get_anchors[f["id"]][:label], @foreword_lbl, s, class: "ForewordTitle")
    f.elements.each { |e| parse(e, s) unless e.name == "title" }
  end
end

#info(isoxml, out) ⇒ Object



44
45
46
47
# File 'lib/isodoc/ogc/base_convert.rb', line 44

def info(isoxml, out)
  @meta.keywords isoxml, out
  super
end

#initial_anchor_names(d) ⇒ Object



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/isodoc/ogc/base_convert.rb', line 255

def initial_anchor_names(d)
  @prefacenum = 0
  preface_names(d.at(ns("//preface/abstract")))
  @prefacenum += 1 if d.at(ns("//keyword"))
  preface_names(d.at(ns("//foreword")))
  #preface_names(d.at(ns("//introduction")))
  @prefacenum += 1 if d.at(ns(SUBMITTINGORGS))
  preface_names(d.at(ns("//submitters")))
  sequential_asset_names(d.xpath(ns("//preface/abstract | //foreword | //introduction | //submitters")))
  n = section_names(d.at(ns("//clause[title = 'Scope']")), 0, 1)
  n = section_names(d.at(ns("//clause[title = 'Conformance']")), n, 1)
  n = section_names(d.at(ns(
    "//references[title = 'Normative References' or title = 'Normative references']")), n, 1)
  n = section_names(d.at(ns("//sections/terms | "\
                            "//sections/clause[descendant::terms]")), n, 1)
  n = section_names(d.at(ns("//sections/definitions")), n, 1)
  middle_section_asset_names(d)
  clause_names(d, n)
  termnote_anchor_names(d)
  termexample_anchor_names(d)
end

#keywords(_docxml, out) ⇒ Object



59
60
61
62
63
64
65
66
67
68
# File 'lib/isodoc/ogc/base_convert.rb', line 59

def keywords(_docxml, out)
  kw = @meta.get[:keywords]
  kw.empty? and return
  @prefacenum += 1
  out.div **{ class: "Section3" } do |div|
    clause_name(RomanNumerals.to_roman(@prefacenum).downcase, "Keywords", div,  class: "IntroTitle")
    div.p "The following are keywords to be used by search engines and document catalogues."
    div.p kw.join(", ")
  end
end

#load_yaml(lang, script) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/isodoc/ogc/base_convert.rb', line 49

def load_yaml(lang, script)
  y = if @i18nyaml then YAML.load_file(@i18nyaml)
      elsif lang == "en"
        YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml"))
      else
        YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml"))
      end
  super.merge(y)
end

#middle(isoxml, out) ⇒ Object

def clause(isoxml, out, num)

  isoxml.xpath(ns(self.class::MIDDLE_CLAUSE)).each do |c|
    out.div **attr_code(id: c["id"]) do |div|
      num = num + 1
      clause_name(num,
                  c&.at(ns("./title"))&.content, div, nil)
      c.elements.each do |e|
        parse(e, div) unless e.name == "title"
      end
    end
  end
end


325
326
327
328
329
330
331
332
333
334
335
# File 'lib/isodoc/ogc/base_convert.rb', line 325

def middle(isoxml, out)
  middle_title(out)
  i = scope isoxml, out, 0
  i = conformance isoxml, out, i
  i = norm_ref isoxml, out, i
  i = terms_defs isoxml, out, i
  i = symbols_abbrevs isoxml, out, i
  clause isoxml, out
  annex isoxml, out
  bibliography isoxml, out
end

#middle_section_asset_names(d) ⇒ Object



281
282
283
284
285
286
287
288
# File 'lib/isodoc/ogc/base_convert.rb', line 281

def middle_section_asset_names(d)
  middle_sections = "//clause[title = 'Scope' or title = 'Conformance'] | "\
    "//foreword | //introduction | "\
    "//references[title = 'Normative References' or title = 'Normative references'] | "\
    "//sections/terms | "\
    "//sections/definitions | //clause[parent::sections]"
  sequential_asset_names(d.xpath(ns(middle_sections)))
end

#permission_anchor_names(docxml) ⇒ Object



163
164
165
166
167
# File 'lib/isodoc/ogc/base_convert.rb', line 163

def permission_anchor_names(docxml)
  docxml.xpath(ns("//permission")).each_with_index do |x, i|
    @anchors[x["id"]] = anchor_struct(i+1, nil, "Permission", "permission")
  end
end

#permission_label(node, out) ⇒ Object



246
247
248
249
250
251
252
253
# File 'lib/isodoc/ogc/base_convert.rb', line 246

def permission_label(node, out)
  n = get_anchors[node["id"]]
  label = (n.nil? || n[:label].empty?) ?
    "Permission" : l10n("#{"Permission"} #{n[:label]}")
  out.p **{class: "RecommendationTitle" } do |p|
    p << label
  end
end

#permission_parse(node, out) ⇒ Object



232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/isodoc/ogc/base_convert.rb', line 232

def permission_parse(node, out)
  out.table **recommend_table_attr(node) do |t|
    t.tr do |tr|
      tr.td **REQ_TBL_ATTR do |td|
        permission_label(node, td)
      end
      tr.td **{ valign: "top", class: "recommend" } do |td|
        recommend_name_parse(node, td)
        node.children.each { |n| parse(n, td) unless n.name == "name" }
      end
    end
  end
end

#preface_names(clause) ⇒ Object



97
98
99
100
101
102
103
104
105
106
# File 'lib/isodoc/ogc/base_convert.rb', line 97

def preface_names(clause)
  return if clause.nil?
  @prefacenum += 1
  @anchors[clause["id"]] =
    { label: RomanNumerals.to_roman(@prefacenum).downcase,
      level: 1, xref: preface_clause_name(clause), type: "clause" }
  clause.xpath(ns("./clause | ./terms | ./term | ./definitions")).each_with_index do |c, i|
    section_names1(c, "#{@prefacenum}.#{i + 1}", 2)
  end
end

#recommend_name_parse(node, div) ⇒ Object



179
180
181
182
183
184
# File 'lib/isodoc/ogc/base_convert.rb', line 179

def recommend_name_parse(node, div)
  name = node&.at(ns("./name"))&.text or return
  div.p do |p|
    p.b name
  end
end

#recommend_table_attr(node) ⇒ Object



169
170
171
172
173
# File 'lib/isodoc/ogc/base_convert.rb', line 169

def recommend_table_attr(node)
  attr_code(id: node["id"], class: "recommend",
            cellspacing: 0, cellpadding: 0,
            style: "border-collapse:collapse" )
end

#recommendation_anchor_names(docxml) ⇒ Object



151
152
153
154
155
# File 'lib/isodoc/ogc/base_convert.rb', line 151

def recommendation_anchor_names(docxml)
  docxml.xpath(ns("//recommendation")).each_with_index do |x, i|
    @anchors[x["id"]] = anchor_struct(i+1, nil, "Recommendation", "recommendation")
  end
end

#recommendation_label(node, out) ⇒ Object



200
201
202
203
204
205
206
207
# File 'lib/isodoc/ogc/base_convert.rb', line 200

def recommendation_label(node, out)
  n = get_anchors[node["id"]]
  label = (n.nil? || n[:label].empty?) ?
    "Recommendation" : l10n("#{"Recommendation"} #{n[:label]}")
  out.p **{class: "RecommendationTitle" } do |p|
    p << label
  end
end

#recommendation_parse(node, out) ⇒ Object



186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/isodoc/ogc/base_convert.rb', line 186

def recommendation_parse(node, out)
  out.table **recommend_table_attr(node) do |t|
    t.tr do |tr|
      tr.td **REQ_TBL_ATTR do |td|
        recommendation_label(node, td)
      end
      tr.td **{ valign: "top", class: "recommend" } do |td|
        recommend_name_parse(node, td)
        node.children.each { |n| parse(n, td) unless n.name == "name" }
      end
    end
  end
end

#requirement_anchor_names(docxml) ⇒ Object



157
158
159
160
161
# File 'lib/isodoc/ogc/base_convert.rb', line 157

def requirement_anchor_names(docxml)
  docxml.xpath(ns("//requirement")).each_with_index do |x, i|
    @anchors[x["id"]] = anchor_struct(i+1, nil, "Requirement", "requirement")
  end
end

#requirement_label(node, out) ⇒ Object



223
224
225
226
227
228
229
230
# File 'lib/isodoc/ogc/base_convert.rb', line 223

def requirement_label(node, out)
  n = get_anchors[node["id"]]
  label = (n.nil? || n[:label].empty?) ?
    "Requirement" : l10n("#{"Requirement"} #{n[:label]}")
  out.p **{class: "RecommendationTitle" } do |p|
    p << label
  end
end

#requirement_parse(node, out) ⇒ Object



209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/isodoc/ogc/base_convert.rb', line 209

def requirement_parse(node, out)
  out.table **recommend_table_attr(node) do |t|
    t.tr do |tr|
      tr.td **REQ_TBL_ATTR do |td|
        requirement_label(node, td)
      end
      tr.td **{ valign: "top", class: "recommend" } do |td|
        recommend_name_parse(node, td)
        node.children.each { |n| parse(n, td) unless n.name == "name" }
      end
    end
  end
end

#submitters(docxml, out) ⇒ Object



89
90
91
92
93
94
95
# File 'lib/isodoc/ogc/base_convert.rb', line 89

def submitters(docxml, out)
  f = docxml.at(ns("//submitters")) || return
  out.div **{ class: "Section3" } do |div|
    clause_name(get_anchors[f['id']][:label], "Submitters", div,  class: "IntroTitle")
    f.elements.each { |e| parse(e, div) unless e.name == "title" }
  end
end

#submittingorgs(docxml, out) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/isodoc/ogc/base_convert.rb', line 73

def submittingorgs(docxml, out)
  orgs = []
  docxml.xpath(ns(SUBMITTINGORGS)).each { |org| orgs << org.text }
  return if orgs.empty?
  @prefacenum += 1
  out.div **{ class: "Section3" } do |div|
    clause_name(RomanNumerals.to_roman(@prefacenum).downcase, "Submitting Organizations", div,  class: "IntroTitle")
    div.p "The following organizations submitted this Document to the Open Geospatial Consortium (OGC):"
    div.ul do |ul|
      orgs.each do |org|
        ul.li org
      end
    end
  end
end

#term_cleanup(docxml) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/isodoc/ogc/base_convert.rb', line 35

def term_cleanup(docxml)
  docxml.xpath("//p[@class = 'Terms']").each do |d|
    h2 = d.at("./preceding-sibling::*[@class = 'TermNum'][1]")
    h2.add_child("&nbsp;")
    h2.add_child(d.remove)
  end
  docxml
end

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



18
19
20
21
22
23
24
# File 'lib/isodoc/ogc/base_convert.rb', line 18

def term_defs_boilerplate(div, source, term, preface)
  if source.empty? && term.nil?
    div << @no_terms_boilerplate
  else
    div << term_defs_boilerplate_cont(source, term)
  end
end