Module: Asciidoctor::Standoc::Section

Included in:
Converter
Defined in:
lib/asciidoctor/standoc/section.rb,
lib/asciidoctor/standoc/ref_sect.rb

Instance Method Summary collapse

Instance Method Details

#abstract_parse(attrs, xml, node) ⇒ Object



123
124
125
126
127
# File 'lib/asciidoctor/standoc/section.rb', line 123

def abstract_parse(attrs, xml, node)
  xml.abstract **attr_code(attrs) do |xml_section|
    xml_section << node.content
  end
end

#acknowledgements_parse(attrs, xml, node) ⇒ Object



238
239
240
241
242
243
244
# File 'lib/asciidoctor/standoc/section.rb', line 238

def acknowledgements_parse(attrs, xml, node)
  xml.acknowledgements **attr_code(attrs) do |xml_section|
    xml_section.title { |t| t << node.title || @i18n.acknowledgements }
    content = node.content
    xml_section << content
  end
end

#annex_parse(attrs, xml, node) ⇒ Object



144
145
146
147
148
149
150
151
# File 'lib/asciidoctor/standoc/section.rb', line 144

def annex_parse(attrs, xml, node)
  attrs["inline-header".to_sym] = node.option? "inline-header"
  set_obligation(attrs, node)
  xml.annex **attr_code(attrs) do |xml_section|
    xml_section.title { |name| name << node.title }
    xml_section << node.content
  end
end

#bibitem_parse(attrs, xml, node) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/asciidoctor/standoc/ref_sect.rb', line 31

def bibitem_parse(attrs, xml, node)
  norm_ref = @norm_ref
  biblio = @biblio
  @biblio = false
  @norm_ref = false
  clause_parse(attrs, xml, node)
  @biblio = biblio
  @norm_ref = norm_ref
end

#bibliography_parse(attrs, xml, node) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/asciidoctor/standoc/ref_sect.rb', line 18

def bibliography_parse(attrs, xml, node)
  node.option? "bibitem" and return bibitem_parse(attrs, xml, node)
  node.attr("style") == "bibliography" or
    @log.add("AsciiDoc Input", node, "Section not marked up as [bibliography]!")
  @biblio = true
  xml.references **attr_code(attrs.merge(normative: false)) do |xml_section|
    title = node.level == 1 ? "Bibliography" : node.title
    xml_section.title { |t| t << title }
    xml_section << node.content
  end
  @biblio = false
end

#clause_parse(attrs, xml, node) ⇒ Object



133
134
135
136
137
138
139
140
141
142
# File 'lib/asciidoctor/standoc/section.rb', line 133

def clause_parse(attrs, xml, node)
  attrs["inline-header".to_sym] = node.option? "inline-header"
  attrs[:bibitem] = true if node.option? "bibitem"
  attrs[:level] = node.attr("level")
  set_obligation(attrs, node)
  xml.send "clause", **attr_code(attrs) do |xml_section|
    xml_section.title { |n| n << node.title } unless node.title.nil?
    xml_section << node.content
  end
end

#emend_biblio(xml, code, title, usrlbl) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/asciidoctor/standoc/ref_sect.rb', line 78

def emend_biblio(xml, code, title, usrlbl)
  unless xml.at("/bibitem/docidentifier[not(@type = 'DOI')][text()]")
    @log.add("Bibliography", nil,
             "ERROR: No document identifier retrieved for #{code}")
    xml.root << "<docidentifier>#{code}</docidentifier>"
  end
  unless xml.at("/bibitem/title[text()]")
    @log.add("Bibliography", nil,
             "ERROR: No title retrieved for #{code}")
    xml.root << "<title>#{title || "(MISSING TITLE)"}</title>"
  end
  usrlbl and xml.at("/bibitem/docidentifier").next =
    "<docidentifier type='metanorma'>#{mn_code(usrlbl)}</docidentifier>"
end

#fetch_ref(xml, code, year, **opts) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/asciidoctor/standoc/ref_sect.rb', line 64

def fetch_ref(xml, code, year, **opts)
  return nil if opts[:no_year]
  code = code.sub(/^\([^)]+\)/, "")
  #require "byebug"; byebug if opts[:lang] == "fr"
  hit = @bibdb&.fetch(code, year, opts)
  return nil if hit.nil?
  xml.parent.add_child(smart_render_xml(hit, code, opts))
  xml
rescue RelatonBib::RequestError
  @log.add("Bibliography", nil, "Could not retrieve #{code}: "\
           "no access to online site")
  nil
end

#foreword_parse(attrs, xml, node) ⇒ Object



230
231
232
233
234
235
236
# File 'lib/asciidoctor/standoc/section.rb', line 230

def foreword_parse(attrs, xml, node)
  xml.foreword **attr_code(attrs) do |xml_section|
    xml_section.title { |t| t << node.title }
    content = node.content
    xml_section << content
  end
end

#global_ievcache_nameObject



53
54
55
# File 'lib/asciidoctor/standoc/ref_sect.rb', line 53

def global_ievcache_name
  "#{Dir.home}/.iev/cache"
end

#in_biblio?Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/asciidoctor/standoc/ref_sect.rb', line 4

def in_biblio?
  @biblio
end

#in_norm_ref?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/asciidoctor/standoc/ref_sect.rb', line 8

def in_norm_ref?
  @norm_ref
end

#in_terms?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/asciidoctor/standoc/section.rb', line 12

def in_terms?
  @term_def
end

#init_bib_caches(node) ⇒ Object



105
106
107
108
109
110
111
112
113
114
# File 'lib/asciidoctor/standoc/ref_sect.rb', line 105

def init_bib_caches(node)
  return if @no_isobib
  global = !@no_isobib_cache && !node.attr("local-cache-only")
  local = node.attr("local-cache") || node.attr("local-cache-only")
  local = nil if @no_isobib_cache
  @bibdb = Relaton::DbCache.init_bib_caches(
    local_cache: local,
    flush_caches: node.attr("flush-caches"),
    global_cache: global)
end

#init_iev_caches(node) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/asciidoctor/standoc/ref_sect.rb', line 116

def init_iev_caches(node)
  unless (@no_isobib_cache || @no_isobib)
    node.attr("local-cache-only") or
      @iev_globalname = global_ievcache_name
    @iev_localname = local_ievcache_name(node.attr("local-cache") ||
                                         node.attr("local-cache-only"))
    if node.attr("flush-caches")
      FileUtils.rm_f @iev_globalname unless @iev_globalname.nil?
      FileUtils.rm_f @iev_localname unless @iev_localname.nil?
    end
  end
  #@iev = Iev::Db.new(globalname, localname) unless @no_isobib
end

#introduction_parse(attrs, xml, node) ⇒ Object



222
223
224
225
226
227
228
# File 'lib/asciidoctor/standoc/section.rb', line 222

def introduction_parse(attrs, xml, node)
  xml.introduction **attr_code(attrs) do |xml_section|
    xml_section.title { |t| t << @i18n.introduction }
    content = node.content
    xml_section << content
  end
end

#local_ievcache_name(cachename) ⇒ Object



57
58
59
60
61
62
# File 'lib/asciidoctor/standoc/ref_sect.rb', line 57

def local_ievcache_name(cachename)
  return nil if cachename.nil?
  cachename += "_iev" unless cachename.empty?
  cachename = "iev" if cachename.empty?
  "#{cachename}/cache"
end

#nonterm_symbols_parse(attrs, xml, node) ⇒ Object



153
154
155
156
157
158
# File 'lib/asciidoctor/standoc/section.rb', line 153

def nonterm_symbols_parse(attrs, xml, node)
  defs = @definitions
  @definitions = false
  clause_parse(attrs, xml, node)
  @definitions = defs
end

#nonterm_term_def_subclause_parse(attrs, xml, node) ⇒ Object



183
184
185
186
187
188
# File 'lib/asciidoctor/standoc/section.rb', line 183

def nonterm_term_def_subclause_parse(attrs, xml, node)
  defs = @term_def
  @term_def = false
  clause_parse(attrs, xml, node)
  @term_def = defs
end

#norm_ref_parse(attrs, xml, node) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/asciidoctor/standoc/ref_sect.rb', line 41

def norm_ref_parse(attrs, xml, node)
  node.option? "bibitem" and return bibitem_parse(attrs, xml, node)
  node.attr("style") == "bibliography" or
    @log.add("AsciiDoc Input", node, "Section not marked up as [bibliography]!")
  @norm_ref = true
  xml.references **attr_code(attrs.merge(normative: true)) do |xml_section|
    xml_section.title { |t| t << "Normative References" }
    xml_section << node.content
  end
  @norm_ref = false
end

#preamble(node) ⇒ Object



113
114
115
116
117
118
119
120
121
# File 'lib/asciidoctor/standoc/section.rb', line 113

def preamble(node)
  noko do |xml|
    xml.foreword **attr_code(section_attributes(node)) do |xml_abstract|
      xml_abstract.title { |t| t << (node.blocks[0].title || @i18n.foreword) }
      content = node.content
      xml_abstract << content
    end
  end.join("\n")
end

#reference(node) ⇒ Object



12
13
14
15
16
# File 'lib/asciidoctor/standoc/ref_sect.rb', line 12

def reference(node)
  noko do |xml|
    node.items.each { |item| reference1(node, item.text, xml) }
  end.join
end

#scope_parse(attrs, xml, node) ⇒ Object



129
130
131
# File 'lib/asciidoctor/standoc/section.rb', line 129

def scope_parse(attrs, xml, node)
  clause_parse(attrs.merge(type: "scope"), xml, node)
end

#section(node) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/asciidoctor/standoc/section.rb', line 66

def section(node)
  a = section_attributes(node)
  noko do |xml|
    case sectiontype(node)
    when "introduction" then introduction_parse(a, xml, node)
    when "foreword" then foreword_parse(a, xml, node)
    when "scope" then scope_parse(a, xml, node)
    when "normative references" then norm_ref_parse(a, xml, node)
    when "terms and definitions"
      @term_def = true
      term_def_parse(a, xml, node, true)
      @term_def = false
    when "symbols and abbreviated terms"
      symbols_parse(symbols_attrs(node, a), xml, node)
    when "acknowledgements"
      acknowledgements_parse(a, xml, node)
    when "bibliography" 
      bibliography_parse(a, xml, node)
    else
      if @term_def then term_def_subclause_parse(a, xml, node)
      elsif @definitions then symbols_parse(a, xml, node)
      elsif @norm_ref then norm_ref_parse(a, xml, node)
      elsif @biblio then bibliography_parse(a, xml, node)
      elsif node.attr("style") == "bibliography" && sectiontype(node, false) == "normative references"
        norm_ref_parse(a, xml, node)
      elsif node.attr("style") == "bibliography" && sectiontype(node, false) == "bibliography"
        bibliography_parse(a, xml, node)
      elsif node.attr("style") == "bibliography"
        bibliography_parse(a, xml, node)
      elsif node.attr("style") == "abstract" 
        abstract_parse(a, xml, node)
      elsif node.attr("style") == "appendix" && node.level == 1
        annex_parse(a, xml, node)
      else
        clause_parse(a, xml, node)
      end
    end
  end.join("\n")
end

#section_attributes(node) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/asciidoctor/standoc/section.rb', line 48

def section_attributes(node)
  ret = { id: Utils::anchor_or_uuid(node),
    language: node.attributes["language"],
    script: node.attributes["script"],
    annex: (
      ((node.attr("style") == "appendix" || node.role == "appendix") && 
       node.level == 1) ? true : nil
    ),
    preface: (
      (node.role == "preface" || node.attr("style") == "preface") ?
      true : nil) }
  return ret unless node.attributes["change"]
  ret.merge(change: node.attributes["change"],
            path: node.attributes["path"],
            path_end: node.attributes["path_end"],
            title: node.attributes["title"])
end

#sectiontype(node, level = true) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/asciidoctor/standoc/section.rb', line 21

def sectiontype(node, level = true)
  ret = sectiontype1(node)
  ret1 = sectiontype_streamline(ret)
  return ret1 if "symbols and abbreviated terms" == ret1
  return nil unless !level || node.level == 1
  return nil if @seen_headers.include? ret
  @seen_headers << ret
  ret1
end

#sectiontype1(node) ⇒ Object



16
17
18
19
# File 'lib/asciidoctor/standoc/section.rb', line 16

def sectiontype1(node)
  node&.attr("heading")&.downcase ||
    node.title.gsub(/<[^>]+>/, "").downcase
end

#sectiontype_streamline(ret) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/asciidoctor/standoc/section.rb', line 31

def sectiontype_streamline(ret)
  case ret
  when "terms and definitions",
    "terms, definitions, symbols and abbreviated terms",
    "terms, definitions, symbols and abbreviations",
    "terms, definitions and symbols",
    "terms, definitions and abbreviations",
    "terms, definitions and abbreviated terms"
    "terms and definitions"
  when "symbols and abbreviated terms",
    "symbols", "abbreviated terms", "abbreviations"
    "symbols and abbreviated terms"
  else
    ret
  end
end

#set_obligation(attrs, node) ⇒ Object



106
107
108
109
110
111
# File 'lib/asciidoctor/standoc/section.rb', line 106

def set_obligation(attrs, node)
  attrs[:obligation] = node.attributes.has_key?("obligation") ?
                         node.attr("obligation") :
                       node.parent.attributes.has_key?("obligation") ?
                         node.parent.attr("obligation") : "normative"
end

#smart_render_xml(x, code, opts) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
# File 'lib/asciidoctor/standoc/ref_sect.rb', line 93

def smart_render_xml(x, code, opts)
  x.respond_to? :to_xml or return nil
  xstr = x.to_xml(lang: opts[:lang])
  xml = Nokogiri::XML(xstr)
  emend_biblio(xml, code, opts[:title], opts[:usrlbl])
  xml.xpath("//date").each { |d| Utils::endash_date(d) }
  xml.traverse do |n|
    n.text? and n.replace(Utils::smartformat(n.text))
  end
  xml.to_xml.sub(/<\?[^>]+>/, "")
end

#symbols_attrs(node, a) ⇒ Object



160
161
162
163
164
165
166
167
# File 'lib/asciidoctor/standoc/section.rb', line 160

def symbols_attrs(node, a)
  case sectiontype1(node)
  when "symbols" then a.merge(type: "symbols")
  when "abbreviated terms", "abbreviations" then a.merge(type: "abbreviated_terms")
  else
    a
  end
end

#symbols_parse(attr, xml, node) ⇒ Object



169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/asciidoctor/standoc/section.rb', line 169

def symbols_parse(attr, xml, node)
  node.role == "nonterm" and return nonterm_symbols_parse(attr, xml, node)
  xml.definitions **attr_code(attr) do |xml_section|
    xml_section.title { |t| t << node.title }
    defs = @definitions
    termdefs = @term_def
    @definitions = true
    @term_def = false
    xml_section << node.content
    @definitions = defs
    @term_def = termdefs
  end
end

#term_def_parse(attrs, xml, node, toplevel) ⇒ Object



212
213
214
215
216
217
218
219
220
# File 'lib/asciidoctor/standoc/section.rb', line 212

def term_def_parse(attrs, xml, node, toplevel)
  xml.terms **attr_code(attrs) do |section|
    section.title { |t| t << node.title }
    (s = node.attr("source")) && s.split(/,/).each do |s1|
      section.termdocsource(nil, **attr_code(bibitemid: s1))
    end
    section << node.content
  end
end

#term_def_subclause_parse(attrs, xml, node) ⇒ Object

subclause contains subclauses



191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/asciidoctor/standoc/section.rb', line 191

def term_def_subclause_parse(attrs, xml, node)
  node.role == "nonterm"  and
    return nonterm_term_def_subclause_parse(attrs, xml, node)
  st = sectiontype(node, false)
  return symbols_parse(attrs, xml, node) if @definitions
  sub = node.find_by(context: :section) { |s| s.level == node.level + 1 }
  sub.empty? || (return term_def_parse(attrs, xml, node, false))
  st == "symbols and abbreviated terms" and
    (return symbols_parse(attrs, xml, node))
  st == "terms and definitions" and
    return clause_parse(attrs, xml, node)
  term_def_subclause_parse1(attrs, xml, node)
end

#term_def_subclause_parse1(attrs, xml, node) ⇒ Object



205
206
207
208
209
210
# File 'lib/asciidoctor/standoc/section.rb', line 205

def term_def_subclause_parse1(attrs, xml, node)
  xml.term **attr_code(attrs) do |xml_section|
    xml_section.preferred { |name| name << node.title }
    xml_section << node.content
  end
end