Class: Asciidoctor::Rsd::Converter

Inherits:
ISO::Converter
  • Object
show all
Defined in:
lib/asciidoctor/rsd/converter.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(backend, opts) ⇒ Converter

Returns a new instance of Converter.



17
18
19
20
# File 'lib/asciidoctor/rsd/converter.rb', line 17

def initialize(backend, opts)
  super
  @libdir = File.dirname(__FILE__)
end

Instance Method Details

#doctype(node) ⇒ Object



102
103
104
105
106
107
108
109
110
# File 'lib/asciidoctor/rsd/converter.rb', line 102

def doctype(node)
  d = node.attr("doctype")
  unless %w{policy-and-procedures best-practices supporting-document
    report legal directives proposal standard}.include? d
    warn "#{d} is not a legal document type: reverting to 'standard'"
    d = "standard"
  end
  d
end

#document(node) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/asciidoctor/rsd/converter.rb', line 119

def document(node)
  init(node)
  ret1 = makexml(node)
  ret = ret1.to_xml(indent: 2)
  unless node.attr("nodoc") || !node.attr("docfile")
    filename = node.attr("docfile").gsub(/\.adoc/, ".xml").
      gsub(%r{^.*/}, "")
    File.open(filename, "w") { |f| f.write(ret) }
    html_converter(node).convert filename unless node.attr("nodoc")
    word_converter(node).convert filename unless node.attr("nodoc")
    pdf_convert(filename.sub(/\.xml$/, "")) unless node.attr("nodoc")
  end
  @files_to_delete.each { |f| system "rm #{f}" }
  ret
end

#html_converter(node) ⇒ Object



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/asciidoctor/rsd/converter.rb', line 165

def html_converter(node)
  IsoDoc::Rsd::HtmlConvert.new(
      script: node.attr("script"),
      bodyfont: node.attr("body-font"),
      headerfont: node.attr("header-font"),
      monospacefont: node.attr("monospace-font"),
      titlefont: node.attr("title-font"),
      i18nyaml: node.attr("i18nyaml"),
      scope: node.attr("scope"),
      htmlstylesheet: node.attr("htmlstylesheet"),
      htmlcoverpage: node.attr("htmlcoverpage"),
      htmlintropage: node.attr("htmlintropage"),
      scripts: node.attr("scripts"),
  )
end

#inline_quoted(node) ⇒ Object



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/asciidoctor/rsd/converter.rb', line 200

def inline_quoted(node)
  noko do |xml|
    case node.type
    when :emphasis then xml.em node.text
    when :strong then xml.strong node.text
    when :monospaced then xml.tt node.text
    when :double then xml << "\"#{node.text}\""
    when :single then xml << "'#{node.text}'"
    when :superscript then xml.sup node.text
    when :subscript then xml.sub node.text
    when :asciimath then stem_parse(node.text, xml)
    else
      case node.role
      when "strike" then xml.strike node.text
      when "smallcap" then xml.smallcap node.text
      when "keyword" then xml.keyword node.text
      else
        xml << node.text
      end
    end
  end.join
end

#literal(node) ⇒ Object



145
146
147
148
149
150
151
152
# File 'lib/asciidoctor/rsd/converter.rb', line 145

def literal(node)
  noko do |xml|
    xml.figure **id_attr(node) do |f|
      figure_title(node, f)
      f.pre node.lines.join("\n")
    end
  end
end

#makexml(node) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/asciidoctor/rsd/converter.rb', line 89

def makexml(node)
  result = ["<?xml version='1.0' encoding='UTF-8'?>\n<rsd-standard>"]
  @draft = node.attributes.has_key?("draft")
  result << noko { |ixml| front node, ixml }
  result << noko { |ixml| middle node, ixml }
  result << "</rsd-standard>"
  result = textcleanup(result.flatten * "\n")
  ret1 = cleanup(Nokogiri::XML(result))
  validate(ret1)
  ret1.root.add_namespace(nil, RSD_NAMESPACE)
  ret1
end

#metadata(node, xml) ⇒ Object



80
81
82
83
# File 'lib/asciidoctor/rsd/converter.rb', line 80

def (node, xml)
  super
  (node, xml)
end

#metadata_author(node, xml) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/asciidoctor/rsd/converter.rb', line 22

def (node, xml)
  xml.contributor do |c|
    c.role **{ type: "author" }
    c.organization do |a|
      a.name "Ribose"
    end
  end
end

#metadata_committee(node, xml) ⇒ Object



40
41
42
43
44
45
# File 'lib/asciidoctor/rsd/converter.rb', line 40

def (node, xml)
  xml.editorialgroup do |a|
    a.committee node.attr("committee"),
      **attr_code(type: node.attr("committee-type"))
  end
end


63
64
65
66
67
68
69
70
71
72
73
# File 'lib/asciidoctor/rsd/converter.rb', line 63

def (node, xml)
  from = node.attr("copyright-year") || Date.today.year
  xml.copyright do |c|
    c.from from
    c.owner do |owner|
      owner.organization do |o|
        o.name "Ribose"
      end
    end
  end
end

#metadata_id(node, xml) ⇒ Object



59
60
61
# File 'lib/asciidoctor/rsd/converter.rb', line 59

def (node, xml)
  xml.docidentifier { |i| i << node.attr("docnumber") }
end

#metadata_publisher(node, xml) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/asciidoctor/rsd/converter.rb', line 31

def (node, xml)
  xml.contributor do |c|
    c.role **{ type: "publisher" }
    c.organization do |a|
      a.name "Ribose"
    end
  end
end

#metadata_security(node, xml) ⇒ Object



75
76
77
78
# File 'lib/asciidoctor/rsd/converter.rb', line 75

def (node, xml)
  security = node.attr("security") || return
  xml.security security
end

#metadata_status(node, xml) ⇒ Object



55
56
57
# File 'lib/asciidoctor/rsd/converter.rb', line 55

def (node, xml)
  xml.status(**{ format: "plain" }) { |s| s << node.attr("status") }
end

#pdf_convert(filename) ⇒ Object



112
113
114
115
116
117
# File 'lib/asciidoctor/rsd/converter.rb', line 112

def pdf_convert(filename)
  url = "#{Dir.pwd}/#{filename}.html"
  pdfjs = File.join(File.dirname(__FILE__), 'pdf.js')
  system "export NODE_PATH=$(npm root --quiet -g);
          node #{pdfjs} file://#{url} #{filename}.pdf"
end

#rsd_html_path(file) ⇒ Object



141
142
143
# File 'lib/asciidoctor/rsd/converter.rb', line 141

def rsd_html_path(file)
  File.join(File.dirname(__FILE__), File.join("html", file))
end

#sections_cleanup(x) ⇒ Object



154
155
156
157
158
159
# File 'lib/asciidoctor/rsd/converter.rb', line 154

def sections_cleanup(x)
  super
  x.xpath("//*[@inline-header]").each do |h|
    h.delete("inline-header")
  end
end

#style(n, t) ⇒ Object



161
162
163
# File 'lib/asciidoctor/rsd/converter.rb', line 161

def style(n, t)
  return
end

#title(node, xml) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/asciidoctor/rsd/converter.rb', line 47

def title(node, xml)
  ["en"].each do |lang|
    xml.title **{ language: lang, format: "plain" } do |t|
      t << asciidoc_sub(node.attr("title"))
    end
  end
end

#title_validate(root) ⇒ Object



85
86
87
# File 'lib/asciidoctor/rsd/converter.rb', line 85

def title_validate(root)
  nil
end

#validate(doc) ⇒ Object



135
136
137
138
139
# File 'lib/asciidoctor/rsd/converter.rb', line 135

def validate(doc)
  content_validate(doc)
  schema_validate(formattedstr_strip(doc.dup),
                  File.join(File.dirname(__FILE__), "rsd.rng"))
end

#word_converter(node) ⇒ Object



181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/asciidoctor/rsd/converter.rb', line 181

def word_converter(node)
  IsoDoc::Rsd::WordConvert.new(
    script: node.attr("script"),
    bodyfont: node.attr("body-font"),
    headerfont: node.attr("header-font"),
    monospacefont: node.attr("monospace-font"),
    titlefont: node.attr("title-font"),
    i18nyaml: node.attr("i18nyaml"),
    scope: node.attr("scope"),
    wordstylesheet: node.attr("wordstylesheet"),
    standardstylesheet: node.attr("standardstylesheet"),
    header: node.attr("header"),
    wordcoverpage: node.attr("wordcoverpage"),
    wordintropage: node.attr("wordintropage"),
    ulstyle: node.attr("ulstyle"),
    olstyle: node.attr("olstyle"),
  )
end