Skip to content

Commit

Permalink
Merge pull request #64 from metanorma/features/inherit-generic
Browse files Browse the repository at this point in the history
Features/inherit generic
  • Loading branch information
opoudjis committed Nov 9, 2020
2 parents 2d4fb4f + a25fbe2 commit 012346f
Show file tree
Hide file tree
Showing 19 changed files with 142 additions and 189 deletions.
2 changes: 1 addition & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ _Formerly known as_ `asciidoctor-m3d`.

== Functionality

This gem processes http://asciidoctor.org/[Asciidoctor] documents following
This gem processes https://www.metanorma.com[Metanorma documents] following
a template for generating M3AAWG documents.

The gem currently inherits from the https://github.com/metanorma/metanorma-standoc
Expand Down
53 changes: 4 additions & 49 deletions lib/asciidoctor/m3aawg/converter.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,14 @@
require "asciidoctor"
require "metanorma/m3aawg/version"
require "isodoc/m3aawg/html_convert"
require "isodoc/m3aawg/word_convert"
require "isodoc/m3aawg/pdf_convert"
require "asciidoctor/standoc/converter"
require "fileutils"
require_relative "./validate.rb"
require 'asciidoctor/generic/converter'

module Asciidoctor
module M3AAWG

# A {Converter} implementation that generates M3D output, and a document
# schema encapsulation of the document for validation
class Converter < Standoc::Converter
class Converter < Asciidoctor::Generic::Converter
XML_ROOT_TAG = "m3d-standard".freeze
XML_NAMESPACE = "https://www.metanorma.org/ns/m3d".freeze

register_for "m3aawg"

def default_publisher
"Messaging Malware and Mobile Anti-Abuse Working Group"
end

def metadata_committee(node, xml)
return unless node.attr("technical-committee")
xml.editorialgroup do |a|
Expand All @@ -36,37 +23,15 @@ def metadata_committee(node, xml)
end
end

def metadata_id(node, xml)
docstatus = node.attr("status")
dn = node.attr("docnumber")
if docstatus
abbr = IsoDoc::M3AAWG::Metadata.new("en", "Latn", @i18n).
stage_abbr(docstatus)
dn = "#{dn}(#{abbr})" unless abbr.empty?
end
node.attr("copyright-year") and dn += ":#{node.attr("copyright-year")}"
xml.docidentifier dn, **{type: "M3AAWG"}
xml.docnumber { |i| i << node.attr("docnumber") }
end

def title_validate(root)
nil
def configuration
Metanorma::M3AAWG.configuration
end

def makexml(node)
@draft = node.attributes.has_key?("draft")
super
end

def doctype(node)
d = super
unless %w{policy best-practices supporting-document report}.include? d
@log.add("Document Attributes", nil, "#{d} is not a legal document type: reverting to 'report'")
d = "report"
end
d
end

def outputs(node, ret)
File.open(@filename + ".xml", "w:UTF-8") { |f| f.write(ret) }
presentation_xml_converter(node).convert(@filename + ".xml")
Expand All @@ -75,23 +40,13 @@ def outputs(node, ret)
pdf_converter(node)&.convert(@filename + ".presentation.xml", nil, false, "#{@filename}.pdf")
end

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

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

def style(n, t)
return
end

def presentation_xml_converter(node)
IsoDoc::M3AAWG::PresentationXMLConvert.new(html_extract_attributes(node))
end
Expand Down
22 changes: 0 additions & 22 deletions lib/asciidoctor/m3aawg/validate.rb

This file was deleted.

14 changes: 2 additions & 12 deletions lib/isodoc/m3aawg/base_convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,8 @@
module IsoDoc
module M3AAWG
module BaseRender
def cleanup(docxml)
super
term_cleanup(docxml)
end

def term_cleanup(docxml)
docxml.xpath("//p[@class = 'Terms']").each do |d|
h2 = d.at("./preceding-sibling::*[@class = 'TermNum'][1]")
h2.add_child("&nbsp;")
h2.add_child(d.remove)
end
docxml
def configuration
Metanorma::M3AAWG.configuration
end
end
end
Expand Down
38 changes: 7 additions & 31 deletions lib/isodoc/m3aawg/html_convert.rb
Original file line number Diff line number Diff line change
@@ -1,35 +1,18 @@
require "isodoc"
require "isodoc/generic/html_convert"
require_relative "base_convert"
require_relative "init"

module IsoDoc
module M3AAWG
# A {Converter} implementation that generates CSAND output, and a document
# schema encapsulation of the document for validation
class HtmlConvert < IsoDoc::HtmlConvert
def initialize(options)
@libdir = File.dirname(__FILE__)
super
end

def default_fonts(options)
{
bodyfont: (options[:script] == "Hans" ? '"SimSun",serif' :
'"Overpass",sans-serif'),
headerfont: (options[:script] == "Hans" ? '"SimHei",sans-serif' :
'"Overpass",sans-serif'),
monospacefont: '"Space Mono",monospace'
}
class HtmlConvert < IsoDoc::Generic::HtmlConvert
def configuration
Metanorma::M3AAWG.configuration
end

def default_file_locations(_options)
{
htmlstylesheet: html_doc_path("htmlstyle.scss"),
htmlcoverpage: html_doc_path("html_m3d_titlepage.html"),
htmlintropage: html_doc_path("html_m3d_intro.html"),
standardstylesheet: nil,
scripts: html_doc_path("scripts.html"),
}
def initialize(options)
#require "byebug"; byebug
super
end

def colophon(body, docxml)
Expand All @@ -45,13 +28,6 @@ def colophon(body, docxml)
end
end

def googlefonts()
<<~HEAD.freeze
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i|Space+Mono:400,700" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Overpass:300,300i,600,900" rel="stylesheet">
HEAD
end

def make_body(xml, docxml)
body_attr = { lang: "EN-US", link: "blue", vlink: "#954F72",
"xml:lang": "EN-US", class: "container" }
Expand Down
7 changes: 3 additions & 4 deletions lib/isodoc/m3aawg/i18n.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
module IsoDoc
module M3AAWG
class I18n < IsoDoc::I18n
def load_yaml1(lang, script)
y = YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml"))
super.merge(y)
class I18n < IsoDoc::Generic::I18n
def configuration
Metanorma::M3AAWG.configuration
end
end
end
Expand Down
7 changes: 2 additions & 5 deletions lib/isodoc/m3aawg/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@ def metadata_init(lang, script, labels)
end

def xref_init(lang, script, klass, labels, options)
@xrefs = Xref.new(lang, script, HtmlConvert.new(language: lang, script: script), labels, options)
html = HtmlConvert.new(language: lang, script: script)
@xrefs = Xref.new(lang, script, html, labels, options)
end

def i18n_init(lang, script, i18nyaml = nil)
@i18n = I18n.new(lang, script, i18nyaml || @i18nyaml)
end

def fileloc(loc)
File.join(File.dirname(__FILE__), loc)
end
end
end
end
Expand Down
22 changes: 5 additions & 17 deletions lib/isodoc/m3aawg/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

module IsoDoc
module M3AAWG
# A {Converter} implementation that generates CSAND output, and a document
# schema encapsulation of the document for validation
class Metadata < IsoDoc::Metadata
class Metadata < IsoDoc::Generic::Metadata
def configuration
Metanorma::M3AAWG.configuration
end

def initialize(lang, script, labels)
super
here = File.dirname(__FILE__)
Expand Down Expand Up @@ -34,20 +36,6 @@ def docid(isoxml, _out)
docnumber = isoxml.at(ns("//bibdata/docidentifier"))
set(:docnumber, docnumber&.text)
end

def stage_abbr(status)
case status
when "working-draft" then "wd"
when "committee-draft" then "cd"
when "draft-standard" then "d"
else
""
end
end

def unpublished(status)
!%w(published withdrawn).include? status.downcase
end
end
end
end
17 changes: 11 additions & 6 deletions lib/isodoc/m3aawg/presentation_xml_convert.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
require_relative "init"
require "metanorma-generic"
require "isodoc"

module IsoDoc
module M3AAWG
class PresentationXMLConvert < IsoDoc::PresentationXMLConvert
class PresentationXMLConvert < IsoDoc::Generic::PresentationXMLConvert
def configuration
Metanorma::M3AAWG.configuration
end

def annex1(f)
lbl = @xrefs.anchor(f['id'], :label)
if t = f.at(ns("./title"))
t.children = "<strong>#{t.children.to_xml}</strong>"
lbl = @xrefs.anchor(f['id'], :label)
if t = f.at(ns("./title"))
t.children = "<strong>#{t.children.to_xml}</strong>"
end
prefix_name(f, "<br/>", lbl, "title")
end
prefix_name(f, "<br/>", lbl, "title")
end

include Init
end
Expand Down
39 changes: 4 additions & 35 deletions lib/isodoc/m3aawg/word_convert.rb
Original file line number Diff line number Diff line change
@@ -1,39 +1,13 @@
require "isodoc"
require_relative "base_convert"
require "isodoc/generic/word_convert"
require_relative "init"

module IsoDoc
module M3AAWG
# A {Converter} implementation that generates GB output, and a document
# schema encapsulation of the document for validation

class WordConvert < IsoDoc::WordConvert
def initialize(options)
@libdir = File.dirname(__FILE__)
super
end

def default_fonts(options)
{
bodyfont: (options[:script] == "Hans" ? '"SimSun",serif' : '"Garamond",serif'),
headerfont: (options[:script] == "Hans" ? '"SimHei",sans-serif' : '"Garamond",serif'),
monospacefont: '"Courier New",monospace'
}
end

def default_file_locations(_options)
{
htmlstylesheet: html_doc_path("htmlstyle.scss"),
htmlcoverpage: html_doc_path("html_m3d_titlepage.html"),
htmlintropage: html_doc_path("html_m3d_intro.html"),
scripts: html_doc_path("scripts.html"),
wordstylesheet: html_doc_path("wordstyle.scss"),
standardstylesheet: html_doc_path("m3d.scss"),
header: html_doc_path("header.html"),
wordintropage: html_doc_path("word_m3d_intro.html"),
ulstyle: "l3",
olstyle: "l2",
}
class WordConvert < IsoDoc::Generic::WordConvert
def configuration
Metanorma::M3AAWG.configuration
end

def colophon(body, docxml)
Expand All @@ -51,11 +25,6 @@ def make_body(xml, docxml)
end
end

def title(isoxml, _out)
main = isoxml&.at(ns("//title[@language='en']"))&.text
set_metadata(:doctitle, main)
end

include BaseRender
include Init
end
Expand Down
5 changes: 5 additions & 0 deletions lib/isodoc/m3aawg/xref.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
require "metanorma-generic"

module IsoDoc
module M3AAWG
class Xref < IsoDoc::Xref
def configuration
Metanorma::M3AAWG.configuration
end
end
end
end
Loading

0 comments on commit 012346f

Please sign in to comment.