asciidoctor-rsd 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,82 @@
1
+ require "isodoc"
2
+
3
+ module IsoDoc
4
+ module Rsd
5
+ # A {Converter} implementation that generates CSAND output, and a document
6
+ # schema encapsulation of the document for validation
7
+ class Metadata < IsoDoc::Metadata
8
+ def initialize(lang, script, labels)
9
+ super
10
+ set(:status, "XXX")
11
+ end
12
+
13
+ def title(isoxml, _out)
14
+ main = isoxml&.at(ns("//title[@language='en']"))&.text
15
+ set(:doctitle, main)
16
+ end
17
+
18
+ def subtitle(_isoxml, _out)
19
+ nil
20
+ end
21
+
22
+ def author(isoxml, _out)
23
+ set(:tc, "XXXX")
24
+ tc = isoxml.at(ns("//editorialgroup/technical-committee"))
25
+ set(:tc, tc.text) if tc
26
+ end
27
+
28
+ def docid(isoxml, _out)
29
+ docnumber = isoxml.at(ns("//bibdata/docidentifier"))
30
+ docstatus = isoxml.at(ns("//bibdata/status"))
31
+ dn = docnumber&.text
32
+ if docstatus
33
+ set(:status, status_print(docstatus.text))
34
+ abbr = status_abbr(docstatus.text)
35
+ dn = "#{dn}(#{abbr})" unless abbr.empty?
36
+ end
37
+ set(:docnumber, dn)
38
+ end
39
+
40
+ def status_print(status)
41
+ status.split(/-/).map{ |w| w.capitalize }.join(" ")
42
+ end
43
+
44
+ def status_abbr(status)
45
+ case status
46
+ when "working-draft" then "wd"
47
+ when "committee-draft" then "cd"
48
+ when "draft-standard" then "d"
49
+ else
50
+ ""
51
+ end
52
+ end
53
+
54
+ def version(isoxml, _out)
55
+ super
56
+ revdate = get[:revdate]
57
+ set(:revdate_monthyear, monthyr(revdate))
58
+ end
59
+
60
+ MONTHS = {
61
+ "01": "January",
62
+ "02": "February",
63
+ "03": "March",
64
+ "04": "April",
65
+ "05": "May",
66
+ "06": "June",
67
+ "07": "July",
68
+ "08": "August",
69
+ "09": "September",
70
+ "10": "October",
71
+ "11": "November",
72
+ "12": "December",
73
+ }.freeze
74
+
75
+ def monthyr(isodate)
76
+ m = /(?<yr>\d\d\d\d)-(?<mo>\d\d)/.match isodate
77
+ return isodate unless m && m[:yr] && m[:mo]
78
+ return "#{MONTHS[m[:mo].to_sym]} #{m[:yr]}"
79
+ end
80
+ end
81
+ end
82
+ end
@@ -1,66 +1,89 @@
1
1
  require "isodoc"
2
+ require_relative "metadata"
3
+ require_relative "rsdhtmlrender"
2
4
 
3
- module Asciidoctor
5
+ module IsoDoc
4
6
  module Rsd
5
- # A {Converter} implementation that generates RSD output, and a document
7
+ # A {Converter} implementation that generates CSAND output, and a document
6
8
  # schema encapsulation of the document for validation
7
- class RsdConvert < IsoDoc::Convert
8
- def initialize(options)
9
- super
10
- set_metadata(:status, "XXX")
9
+ class Convert < IsoDoc::Convert
10
+ def html_doc_path(file)
11
+ File.join(File.dirname(__FILE__), File.join("html", file))
11
12
  end
12
13
 
13
- def init_metadata
14
+ def initialize(options)
14
15
  super
16
+ @htmlstylesheet = generate_css(html_doc_path("htmlstyle.scss"), true, default_fonts(options))
17
+ @htmlcoverpage = html_doc_path("html_rsd_titlepage.html")
18
+ @htmlintropage = html_doc_path("html_rsd_intro.html")
19
+ @scripts = html_doc_path("scripts.html")
20
+ system "cp #{html_doc_path('logo.jpg')} logo.jpg"
21
+ @files_to_delete << "logo.jpg"
15
22
  end
16
23
 
17
- def title(isoxml, _out)
18
- main = isoxml&.at(ns("//title[@language='en']"))&.text
19
- set_metadata(:doctitle, main)
24
+ def default_fonts(options)
25
+ b = options[:bodyfont] ||
26
+ (options[:script] == "Hans" ? '"SimSun",serif' :
27
+ '"Overpass",sans-serif')
28
+ h = options[:headerfont] ||
29
+ (options[:script] == "Hans" ? '"SimHei",sans-serif' :
30
+ '"Overpass",sans-serif')
31
+ m = options[:monospacefont] || '"Space Mono",monospace'
32
+ "$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n"
20
33
  end
21
34
 
22
- def subtitle(_isoxml, _out)
23
- nil
35
+ def metadata_init(lang, script, labels)
36
+ @meta = Metadata.new(lang, script, labels)
24
37
  end
25
38
 
26
- def author(isoxml, _out)
27
- set_metadata(:tc, "XXXX")
28
- tc = isoxml.at(ns("//editorialgroup/technical-committee"))
29
- set_metadata(:tc, tc.text) if tc
30
- end
39
+ def html_head()
40
+ <<~HEAD.freeze
41
+ <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
31
42
 
43
+ <!--TOC script import-->
44
+ <script type="text/javascript" src="https://cdn.rawgit.com/jgallen23/toc/0.3.2/dist/toc.min.js"></script>
45
+
46
+ <!--Google fonts-->
47
+ <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i|Space+Mono:400,700" rel="stylesheet">
48
+ <link href="https://fonts.googleapis.com/css?family=Overpass:300,300i,600,900" rel="stylesheet">
49
+ <!--Font awesome import for the link icon-->
50
+ <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.8/css/solid.css" integrity="sha384-v2Tw72dyUXeU3y4aM2Y0tBJQkGfplr39mxZqlTBDUZAb9BGoC40+rdFCG0m10lXk" crossorigin="anonymous">
51
+ <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.8/css/fontawesome.css" integrity="sha384-q3jl8XQu1OpdLgGFvNRnPdj5VIlCvgsDQTQB6owSOHWlAurxul7f+JpUOVdAiJ5P" crossorigin="anonymous">
52
+ <style class="anchorjs"></style>
53
+ HEAD
54
+ end
32
55
 
33
- def docid(isoxml, _out)
34
- docnumber = isoxml.at(ns("//bibdata/docidentifier"))
35
- docstatus = isoxml.at(ns("//bibdata/status"))
36
- dn = docnumber&.text
37
- if docstatus
38
- set_metadata(:status, status_print(docstatus.text))
39
- abbr = status_abbr(docstatus.text)
40
- dn = "#{dn}(#{abbr})" unless abbr.empty?
56
+ def make_body(xml, docxml)
57
+ body_attr = { lang: "EN-US", link: "blue", vlink: "#954F72", "xml:lang": "EN-US", class: "container" }
58
+ xml.body **body_attr do |body|
59
+ make_body1(body, docxml)
60
+ make_body2(body, docxml)
61
+ make_body3(body, docxml)
41
62
  end
42
- set_metadata(:docnumber, dn)
43
63
  end
44
64
 
45
- def status_print(status)
46
- status.split(/-/).map{ |w| w.capitalize }.join(" ")
65
+ def html_toc(docxml)
66
+ docxml
47
67
  end
48
68
 
49
- def status_abbr(status)
50
- case status
51
- when "working-draft" then "wd"
52
- when "committee-draft" then "cd"
53
- when "draft-standard" then "d"
54
- else
55
- ""
69
+ def annex_name(annex, name, div)
70
+ div.h1 **{ class: "Annex" } do |t|
71
+ t << "#{get_anchors[annex['id']][:label]} "
72
+ t << "<b>#{name.text}</b>"
56
73
  end
57
74
  end
58
75
 
76
+ def annex_name_lbl(clause, num)
77
+ obl = l10n("(#{@inform_annex_lbl})")
78
+ obl = l10n("(#{@norm_annex_lbl})") if clause["obligation"] == "normative"
79
+ l10n("<b>#{@annex_lbl} #{num}</b> #{obl}")
80
+ end
81
+
59
82
  def pre_parse(node, out)
60
83
  out.pre node.text # content.gsub(/</, "&lt;").gsub(/>/, "&gt;")
61
84
  end
62
85
 
63
- def term_defs_boilerplate(div, source, term)
86
+ def term_defs_boilerplate(div, source, term, preface)
64
87
  if source.empty? && term.nil?
65
88
  div << @no_terms_boilerplate
66
89
  else
@@ -85,49 +108,22 @@ module Asciidoctor
85
108
  end
86
109
  end
87
110
 
88
- HEAD = <<~HEAD.freeze
89
- <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
90
-
91
- <!--TOC script import-->
92
- <script type="text/javascript" src="https://cdn.rawgit.com/jgallen23/toc/0.3.2/dist/toc.min.js"></script>
93
-
94
- <!--Google fonts-->
95
- <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i|Space+Mono:400,700" rel="stylesheet">
96
- <link href="https://fonts.googleapis.com/css?family=Overpass:300,300i,600,900" rel="stylesheet">
97
- <!--Font awesome import for the link icon-->
98
- <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.8/css/solid.css" integrity="sha384-v2Tw72dyUXeU3y4aM2Y0tBJQkGfplr39mxZqlTBDUZAb9BGoC40+rdFCG0m10lXk" crossorigin="anonymous">
99
- <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.8/css/fontawesome.css" integrity="sha384-q3jl8XQu1OpdLgGFvNRnPdj5VIlCvgsDQTQB6owSOHWlAurxul7f+JpUOVdAiJ5P" crossorigin="anonymous">
100
- HEAD
101
-
102
- BUTTON = '<button onclick="topFunction()" id="myBtn" '\
103
- 'title="Go to top">Top</button>'.freeze
104
-
105
-
106
- def html_main(docxml)
107
- d = docxml.at('//div[@class="WordSection3"]')
108
- s = d.replace("<main></main>")
109
- s.first.children = d
110
- s.first.children.first.previous = BUTTON
111
+ def fileloc(loc)
112
+ File.join(File.dirname(__FILE__), loc)
111
113
  end
112
114
 
113
- def html_preface(docxml)
115
+ def cleanup(docxml)
114
116
  super
115
- docxml.at("//head").add_child(HEAD)
116
- html_main(docxml)
117
- docxml
117
+ term_cleanup(docxml)
118
118
  end
119
119
 
120
- def make_body(xml, docxml)
121
- body_attr = { lang: "EN-US", link: "blue", vlink: "#954F72", "xml:lang": "EN-US", class: "container" }
122
- xml.body **body_attr do |body|
123
- make_body1(body, docxml)
124
- make_body2(body, docxml)
125
- make_body3(body, docxml)
120
+ def term_cleanup(docxml)
121
+ docxml.xpath("//p[@class = 'Terms']").each do |d|
122
+ h2 = d.at("./preceding-sibling::*[@class = 'TermNum'][1]")
123
+ h2.add_child("&nbsp;")
124
+ h2.add_child(d.remove)
126
125
  end
127
- end
128
-
129
- def html_toc(docxml)
130
- docxml
126
+ docxml
131
127
  end
132
128
  end
133
129
  end
@@ -0,0 +1,68 @@
1
+ module IsoDoc
2
+ module Rsd
3
+ # A {Converter} implementation that generates CSAND output, and a document
4
+ # schema encapsulation of the document for validation
5
+ class Convert < IsoDoc::Convert
6
+ def annex_name(annex, name, div)
7
+ div.h1 **{ class: "Annex" } do |t|
8
+ t << "#{get_anchors[annex['id']][:label]} "
9
+ t << "<b>#{name.text}</b>"
10
+ end
11
+ end
12
+
13
+ def annex_name_lbl(clause, num)
14
+ obl = l10n("(#{@inform_annex_lbl})")
15
+ obl = l10n("(#{@norm_annex_lbl})") if clause["obligation"] == "normative"
16
+ l10n("<b>#{@annex_lbl} #{num}</b> #{obl}")
17
+ end
18
+
19
+ def pre_parse(node, out)
20
+ out.pre node.text # content.gsub(/</, "&lt;").gsub(/>/, "&gt;")
21
+ end
22
+
23
+ def term_defs_boilerplate(div, source, term, preface)
24
+ if source.empty? && term.nil?
25
+ div << @no_terms_boilerplate
26
+ else
27
+ div << term_defs_boilerplate_cont(source, term)
28
+ end
29
+ end
30
+
31
+ def i18n_init(lang, script)
32
+ super
33
+ @annex_lbl = "Appendix"
34
+ end
35
+
36
+ def error_parse(node, out)
37
+ # catch elements not defined in ISO
38
+ case node.name
39
+ when "pre"
40
+ pre_parse(node, out)
41
+ when "keyword"
42
+ out.span node.text, **{ class: "keyword" }
43
+ else
44
+ super
45
+ end
46
+ end
47
+
48
+ def fileloc(loc)
49
+ File.join(File.dirname(__FILE__), loc)
50
+ end
51
+
52
+ def cleanup(docxml)
53
+ super
54
+ term_cleanup(docxml)
55
+ end
56
+
57
+ def term_cleanup(docxml)
58
+ docxml.xpath("//p[@class = 'Terms']").each do |d|
59
+ h2 = d.at("./preceding-sibling::*[@class = 'TermNum'][1]")
60
+ h2.add_child("&nbsp;")
61
+ h2.add_child(d.remove)
62
+ end
63
+ docxml
64
+ end
65
+ end
66
+ end
67
+ end
68
+
@@ -0,0 +1,88 @@
1
+ require "isodoc"
2
+ require_relative "rsdwordrender"
3
+ require_relative "metadata"
4
+
5
+ module IsoDoc
6
+ module Rsd
7
+ # A {Converter} implementation that generates GB output, and a document
8
+ # schema encapsulation of the document for validation
9
+
10
+ class WordConvert < IsoDoc::WordConvert
11
+ def html_doc_path(file)
12
+ File.join(File.dirname(__FILE__), File.join("html", file))
13
+ end
14
+
15
+ def initialize(options)
16
+ super
17
+ @wordstylesheet = generate_css(html_doc_path("wordstyle.scss"), false, default_fonts(options))
18
+ @standardstylesheet = generate_css(html_doc_path("rsd.scss"), false, default_fonts(options))
19
+ @header = html_doc_path("header.html")
20
+ @wordcoverpage = html_doc_path("word_rsd_titlepage.html")
21
+ @wordintropage = html_doc_path("word_rsd_intro.html")
22
+ @ulstyle = "l3"
23
+ @olstyle = "l2"
24
+ system "cp #{html_doc_path('logo.jpg')} logo.jpg"
25
+ end
26
+
27
+ def default_fonts(options)
28
+ b = options[:bodyfont] ||
29
+ (options[:script] == "Hans" ? '"SimSun",serif' :
30
+ '"Garamond",serif')
31
+ h = options[:headerfont] ||
32
+ (options[:script] == "Hans" ? '"SimHei",sans-serif' :
33
+ '"Garamond",serif')
34
+ m = options[:monospacefont] || '"Courier New",monospace'
35
+ "$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n"
36
+ end
37
+
38
+ def metadata_init(lang, script, labels)
39
+ @meta = Metadata.new(lang, script, labels)
40
+ end
41
+
42
+ def make_body(xml, docxml)
43
+ body_attr = { lang: "EN-US", link: "blue", vlink: "#954F72" }
44
+ xml.body **body_attr do |body|
45
+ make_body1(body, docxml)
46
+ make_body2(body, docxml)
47
+ make_body3(body, docxml)
48
+ end
49
+ end
50
+
51
+ def make_body2(body, docxml)
52
+ body.div **{ class: "WordSection2" } do |div2|
53
+ info docxml, div2
54
+ div2.p { |p| p << "&nbsp;" } # placeholder
55
+ end
56
+ body.br **{ clear: "all", style: "page-break-before:auto;mso-break-type:section-break;" }
57
+ end
58
+
59
+ def title(isoxml, _out)
60
+ main = isoxml&.at(ns("//title[@language='en']"))&.text
61
+ set_metadata(:doctitle, main)
62
+ end
63
+
64
+ def generate_header(filename, dir)
65
+ return unless @header
66
+ template = Liquid::Template.parse(File.read(@header, encoding: "UTF-8"))
67
+ meta = @meta.get
68
+ meta[:filename] = filename
69
+ params = meta.map { |k, v| [k.to_s, v] }.to_h
70
+ File.open("header.html", "w") { |f| f.write(template.render(params)) }
71
+ @files_to_delete << "header.html"
72
+ end
73
+
74
+ def header_strip(h)
75
+ h = h.to_s.gsub(%r{<br/>}, " ").sub(/<\/?h[12][^>]*>/, "")
76
+ h1 = to_xhtml_fragment(h.dup)
77
+ h1.traverse do |x|
78
+ x.replace(" ") if x.name == "span" &&
79
+ /mso-tab-count/.match?(x["style"])
80
+ x.remove if x.name == "span" && x["class"] == "MsoCommentReference"
81
+ x.remove if x.name == "a" && x["epub:type"] == "footnote"
82
+ x.replace(x.children) if x.name == "a"
83
+ end
84
+ from_xhtml(h1)
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,68 @@
1
+ module IsoDoc
2
+ module Rsd
3
+ # A {Converter} implementation that generates CSAND output, and a document
4
+ # schema encapsulation of the document for validation
5
+ class WordConvert < IsoDoc::WordConvert
6
+ def annex_name(annex, name, div)
7
+ div.h1 **{ class: "Annex" } do |t|
8
+ t << "#{get_anchors[annex['id']][:label]} "
9
+ t << "<b>#{name.text}</b>"
10
+ end
11
+ end
12
+
13
+ def annex_name_lbl(clause, num)
14
+ obl = l10n("(#{@inform_annex_lbl})")
15
+ obl = l10n("(#{@norm_annex_lbl})") if clause["obligation"] == "normative"
16
+ l10n("<b>#{@annex_lbl} #{num}</b> #{obl}")
17
+ end
18
+
19
+ def pre_parse(node, out)
20
+ out.pre node.text # content.gsub(/</, "&lt;").gsub(/>/, "&gt;")
21
+ end
22
+
23
+ def term_defs_boilerplate(div, source, term, preface)
24
+ if source.empty? && term.nil?
25
+ div << @no_terms_boilerplate
26
+ else
27
+ div << term_defs_boilerplate_cont(source, term)
28
+ end
29
+ end
30
+
31
+ def i18n_init(lang, script)
32
+ super
33
+ @annex_lbl = "Appendix"
34
+ end
35
+
36
+ def error_parse(node, out)
37
+ # catch elements not defined in ISO
38
+ case node.name
39
+ when "pre"
40
+ pre_parse(node, out)
41
+ when "keyword"
42
+ out.span node.text, **{ class: "keyword" }
43
+ else
44
+ super
45
+ end
46
+ end
47
+
48
+ def fileloc(loc)
49
+ File.join(File.dirname(__FILE__), loc)
50
+ end
51
+
52
+ def cleanup(docxml)
53
+ super
54
+ term_cleanup(docxml)
55
+ end
56
+
57
+ def term_cleanup(docxml)
58
+ docxml.xpath("//p[@class = 'Terms']").each do |d|
59
+ h2 = d.at("./preceding-sibling::*[@class = 'TermNum'][1]")
60
+ h2.add_child("&nbsp;")
61
+ h2.add_child(d.remove)
62
+ end
63
+ docxml
64
+ end
65
+ end
66
+ end
67
+ end
68
+