lib/asciidoctor/m3d/converter.rb in asciidoctor-m3d-0.2.5 vs lib/asciidoctor/m3d/converter.rb in asciidoctor-m3d-0.2.7

- old
+ new

@@ -1,8 +1,9 @@ require "asciidoctor" require "asciidoctor/m3d/version" -require "asciidoctor/m3d/m3dconvert" +require "isodoc/m3d/m3dhtmlconvert" +require "isodoc/m3d/m3dwordconvert" require "asciidoctor/iso/converter" module Asciidoctor module M3d M3D_NAMESPACE = "https://open.ribose.com/standards/m3d" @@ -31,11 +32,11 @@ end end def metadata_committee(node, xml) xml.editorialgroup do |a| - a.technical_committee node.attr("technical-committee"), + a.committee node.attr("technical-committee"), **attr_code(type: node.attr("technical-committee-type")) end end def title(node, xml) @@ -45,11 +46,11 @@ end end end def metadata_status(node, xml) - xml.status **{ format: "plain" } { |s| s << node.attr("status") } + xml.status(**{ format: "plain" }) { |s| s << node.attr("status") } end def metadata_id(node, xml) xml.docidentifier { |i| i << node.attr("docnumber") } end @@ -81,18 +82,30 @@ validate(ret1) ret1.root.add_namespace(nil, M3D_NAMESPACE) ret1 end + def doctype(node) + d = node.attr("doctype") + unless %w{policy best-practices supporting-document report}.include? d + warn "#{d} is not a legal document type: reverting to 'report'" + d = "report" + end + d + end + def document(node) init(node) ret1 = makexml(node) ret = ret1.to_xml(indent: 2) - 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") + 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") + end @files_to_delete.each { |f| system "rm #{f}" } ret end def validate(doc) @@ -123,29 +136,32 @@ def style(n, t) return end - def html_converter(_node) - M3dConvert.new( - htmlstylesheet: generate_css(html_doc_path("htmlstyle.scss"), true), - standardstylesheet: generate_css(html_doc_path("m3d.scss"), true), - htmlcoverpage: html_doc_path("html_m3d_titlepage.html"), - htmlintropage: html_doc_path("html_m3d_intro.html"), - scripts: html_doc_path("scripts.html"), + def html_converter(node) + IsoDoc::M3d::Convert.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 - def default_fonts(node) - b = node.attr("body-font") || - (node.attr("script") == "Hans" ? '"SimSun",serif' : - '"Overpass",sans-serif') - h = node.attr("header-font") || - (node.attr("script") == "Hans" ? '"SimHei",sans-serif' : - '"Overpass",sans-serif') - m = node.attr("monospace-font") || '"Space Mono",monospace' - "$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n" + def word_converter(node) + IsoDoc::M3d::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"), + ) end def inline_quoted(node) noko do |xml| case node.type @@ -166,9 +182,8 @@ xml << node.text end end end.join end - end end end