Class: Asciidoctor::Csd::Converter
- Inherits:
-
ISO::Converter
- Object
- ISO::Converter
- Asciidoctor::Csd::Converter
- Defined in:
- lib/asciidoctor/csd/converter.rb
Overview
A Converter implementation that generates CSD 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
- #inline_quoted(node) ⇒ Object
- #literal(node) ⇒ Object
- #makexml(node) ⇒ 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_status(node, xml) ⇒ Object
- #pdf_convert(filename) ⇒ Object
- #sections_cleanup(x) ⇒ Object
- #style(n, t) ⇒ Object
- #title(node, xml) ⇒ Object
- #title_validate(root) ⇒ Object
- #validate(doc) ⇒ Object
Instance Method Details
#doctype(node) ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/asciidoctor/csd/converter.rb', line 86 def doctype(node) d = node.attr("doctype") unless %w{presentation code proposal standard report}.include? d warn "#{d} is not a legal document type: reverting to 'standard'" d = "standard" end d end |
#document(node) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/asciidoctor/csd/converter.rb', line 102 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 pdf_convert(filename.sub(/\.xml$/, "")) end @files_to_delete.each { |f| system "rm #{f}" } ret end |
#html_converter(node) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/asciidoctor/csd/converter.rb', line 143 def html_converter(node) IsoDoc::Csd::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"), ) end |
#inline_quoted(node) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/asciidoctor/csd/converter.rb', line 155 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
123 124 125 126 127 128 129 130 |
# File 'lib/asciidoctor/csd/converter.rb', line 123 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
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/asciidoctor/csd/converter.rb', line 73 def makexml(node) result = ["<?xml version='1.0' encoding='UTF-8'?>\n<csd-standard>"] @draft = node.attributes.has_key?("draft") result << noko { |ixml| front node, ixml } result << noko { |ixml| middle node, ixml } result << "</csd-standard>" result = textcleanup(result.flatten * "\n") ret1 = cleanup(Nokogiri::XML(result)) validate(ret1) ret1.root.add_namespace(nil, CSD_NAMESPACE) ret1 end |
#metadata_author(node, xml) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/asciidoctor/csd/converter.rb', line 16 def (node, xml) xml.contributor do |c| c.role **{ type: "author" } c.organization do |a| a.name "CalConnect" end end end |
#metadata_committee(node, xml) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/asciidoctor/csd/converter.rb', line 34 def (node, xml) xml.editorialgroup do |a| a.technical_committee node.attr("technical-committee"), **attr_code(type: node.attr("technical-committee-type")) end end |
#metadata_copyright(node, xml) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/asciidoctor/csd/converter.rb', line 57 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 "CalConnect" end end end end |
#metadata_id(node, xml) ⇒ Object
53 54 55 |
# File 'lib/asciidoctor/csd/converter.rb', line 53 def (node, xml) xml.docidentifier { |i| i << node.attr("docnumber") } end |
#metadata_publisher(node, xml) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/asciidoctor/csd/converter.rb', line 25 def (node, xml) xml.contributor do |c| c.role **{ type: "publisher" } c.organization do |a| a.name "CalConnect" end end end |
#metadata_status(node, xml) ⇒ Object
49 50 51 |
# File 'lib/asciidoctor/csd/converter.rb', line 49 def (node, xml) xml.status(**{ format: "plain" }) { |s| s << node.attr("status") } end |
#pdf_convert(filename) ⇒ Object
95 96 97 98 99 100 |
# File 'lib/asciidoctor/csd/converter.rb', line 95 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 |
#sections_cleanup(x) ⇒ Object
132 133 134 135 136 137 |
# File 'lib/asciidoctor/csd/converter.rb', line 132 def sections_cleanup(x) super x.xpath("//*[@inline-header]").each do |h| h.delete("inline-header") end end |
#style(n, t) ⇒ Object
139 140 141 |
# File 'lib/asciidoctor/csd/converter.rb', line 139 def style(n, t) return end |
#title(node, xml) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/asciidoctor/csd/converter.rb', line 41 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
69 70 71 |
# File 'lib/asciidoctor/csd/converter.rb', line 69 def title_validate(root) nil end |
#validate(doc) ⇒ Object
117 118 119 120 121 |
# File 'lib/asciidoctor/csd/converter.rb', line 117 def validate(doc) content_validate(doc) schema_validate(formattedstr_strip(doc.dup), File.join(File.dirname(__FILE__), "csd.rng")) end |