Class: Asciidoctor::Rsd::Converter
- Inherits:
-
Standoc::Converter
- Object
- Standoc::Converter
- Asciidoctor::Rsd::Converter
- 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
- #doctype(node) ⇒ Object
- #document(node) ⇒ Object
- #html_converter(node) ⇒ Object
-
#initialize(backend, opts) ⇒ Converter
constructor
A new instance of Converter.
- #makexml(node) ⇒ Object
- #metadata(node, xml) ⇒ Object
- #metadata_author(node, xml) ⇒ Object
- #metadata_committee(node, xml) ⇒ Object
- #metadata_copyright(node, xml) ⇒ Object
- #metadata_id(node, xml) ⇒ Object
- #metadata_publisher(node, xml) ⇒ Object
- #metadata_security(node, xml) ⇒ Object
- #metadata_status(node, xml) ⇒ Object
- #pdf_convert(filename) ⇒ Object
- #rsd_html_path(file) ⇒ Object
- #sections_cleanup(x) ⇒ Object
- #style(n, t) ⇒ Object
- #title_validate(root) ⇒ Object
- #validate(doc) ⇒ Object
- #word_converter(node) ⇒ Object
Constructor Details
#initialize(backend, opts) ⇒ Converter
Returns a new instance of Converter.
18 19 20 21 |
# File 'lib/asciidoctor/rsd/converter.rb', line 18 def initialize(backend, opts) super @libdir = File.dirname(__FILE__) end |
Instance Method Details
#doctype(node) ⇒ Object
110 111 112 113 114 115 116 117 118 |
# File 'lib/asciidoctor/rsd/converter.rb', line 110 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
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/asciidoctor/rsd/converter.rb', line 127 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| FileUtils.rm f } ret end |
#html_converter(node) ⇒ Object
164 165 166 |
# File 'lib/asciidoctor/rsd/converter.rb', line 164 def html_converter(node) IsoDoc::Rsd::HtmlConvert.new(html_extract_attributes(node)) end |
#makexml(node) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/asciidoctor/rsd/converter.rb', line 97 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
88 89 90 91 |
# File 'lib/asciidoctor/rsd/converter.rb', line 88 def (node, xml) super (node, xml) end |
#metadata_author(node, xml) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/asciidoctor/rsd/converter.rb', line 23 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
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/asciidoctor/rsd/converter.rb', line 41 def (node, xml) xml.editorialgroup do |a| a.committee node.attr("committee"), **attr_code(type: node.attr("committee-type")) i = 2 while node.attr("committee_#{i}") do a.committee node.attr("committee_#{i}"), **attr_code(type: node.attr("committee-type_#{i}")) i += 1 end end end |
#metadata_copyright(node, xml) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/asciidoctor/rsd/converter.rb', line 71 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
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/asciidoctor/rsd/converter.rb', line 58 def (node, xml) docstatus = node.attr("status") dn = node.attr("docnumber") if docstatus abbr = IsoDoc::Rsd::Metadata.new("en", "Latn", {}). status_abbr(docstatus) dn = "#{dn}(#{abbr})" unless abbr.empty? end node.attr("copyright-year") and dn += ":#{node.attr("copyright-year")}" xml.docidentifier dn, **{type: "rsd"} xml.docnumber { |i| i << node.attr("docnumber") } end |
#metadata_publisher(node, xml) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/asciidoctor/rsd/converter.rb', line 32 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
83 84 85 86 |
# File 'lib/asciidoctor/rsd/converter.rb', line 83 def (node, xml) security = node.attr("security") || return xml.security security end |
#metadata_status(node, xml) ⇒ Object
54 55 56 |
# File 'lib/asciidoctor/rsd/converter.rb', line 54 def (node, xml) xml.status(**{ format: "plain" }) { |s| s << node.attr("status") } end |
#pdf_convert(filename) ⇒ Object
120 121 122 123 124 125 |
# File 'lib/asciidoctor/rsd/converter.rb', line 120 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
149 150 151 |
# File 'lib/asciidoctor/rsd/converter.rb', line 149 def rsd_html_path(file) File.join(File.dirname(__FILE__), File.join("html", file)) end |
#sections_cleanup(x) ⇒ Object
153 154 155 156 157 158 |
# File 'lib/asciidoctor/rsd/converter.rb', line 153 def sections_cleanup(x) super x.xpath("//*[@inline-header]").each do |h| h.delete("inline-header") end end |
#style(n, t) ⇒ Object
160 161 162 |
# File 'lib/asciidoctor/rsd/converter.rb', line 160 def style(n, t) return end |
#title_validate(root) ⇒ Object
93 94 95 |
# File 'lib/asciidoctor/rsd/converter.rb', line 93 def title_validate(root) nil end |
#validate(doc) ⇒ Object
143 144 145 146 147 |
# File 'lib/asciidoctor/rsd/converter.rb', line 143 def validate(doc) content_validate(doc) schema_validate(formattedstr_strip(doc.dup), File.join(File.dirname(__FILE__), "rsd.rng")) end |
#word_converter(node) ⇒ Object
168 169 170 |
# File 'lib/asciidoctor/rsd/converter.rb', line 168 def word_converter(node) IsoDoc::Rsd::WordConvert.new(doc_extract_attributes(node)) end |