metanorma-sample 1.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/.hound.yml +3 -0
  4. data/.rubocop.yml +10 -0
  5. data/.travis.yml +16 -0
  6. data/CODE_OF_CONDUCT.md +74 -0
  7. data/Gemfile +4 -0
  8. data/LICENSE +25 -0
  9. data/README.adoc +13 -0
  10. data/Rakefile +6 -0
  11. data/asciidoctor-metanorma_sample.gemspec +46 -0
  12. data/bin/console +14 -0
  13. data/bin/rspec +18 -0
  14. data/bin/setup +8 -0
  15. data/lib/asciidoctor-sample.rb +11 -0
  16. data/lib/asciidoctor/sample.rb +7 -0
  17. data/lib/asciidoctor/sample/biblio.rng +890 -0
  18. data/lib/asciidoctor/sample/converter.rb +162 -0
  19. data/lib/asciidoctor/sample/isodoc.rng +1091 -0
  20. data/lib/asciidoctor/sample/isostandard.rng +1068 -0
  21. data/lib/asciidoctor/sample/pdf.js +31 -0
  22. data/lib/asciidoctor/sample/sample.rng +196 -0
  23. data/lib/isodoc/sample/html/header.html +184 -0
  24. data/lib/isodoc/sample/html/html_sample_intro.html +8 -0
  25. data/lib/isodoc/sample/html/html_sample_titlepage.html +106 -0
  26. data/lib/isodoc/sample/html/htmlstyle.scss +1038 -0
  27. data/lib/isodoc/sample/html/logo.jpg +0 -0
  28. data/lib/isodoc/sample/html/sample.scss +644 -0
  29. data/lib/isodoc/sample/html/scripts.html +82 -0
  30. data/lib/isodoc/sample/html/scripts.pdf.html +70 -0
  31. data/lib/isodoc/sample/html/word_sample_intro.html +72 -0
  32. data/lib/isodoc/sample/html/word_sample_titlepage.html +75 -0
  33. data/lib/isodoc/sample/html/wordstyle.scss +1105 -0
  34. data/lib/isodoc/sample/html_convert.rb +120 -0
  35. data/lib/isodoc/sample/metadata.rb +74 -0
  36. data/lib/isodoc/sample/pdf_convert.rb +117 -0
  37. data/lib/isodoc/sample/word_convert.rb +98 -0
  38. data/lib/metanorma/sample.rb +7 -0
  39. data/lib/metanorma/sample/processor.rb +43 -0
  40. data/lib/metanorma/sample/version.rb +5 -0
  41. metadata +310 -0
@@ -0,0 +1,120 @@
1
+ require "isodoc"
2
+ require_relative "metadata"
3
+ require "fileutils"
4
+
5
+ module IsoDoc
6
+ module Sample
7
+
8
+ # A {Converter} implementation that generates HTML output, and a document
9
+ # schema encapsulation of the document for validation
10
+ #
11
+ class HtmlConvert < IsoDoc::HtmlConvert
12
+ def initialize(options)
13
+ @libdir = File.dirname(__FILE__)
14
+ super
15
+ FileUtils.cp html_doc_path('logo.jpg'), "logo.jpg"
16
+ @files_to_delete << "logo.jpg"
17
+ end
18
+
19
+ def default_fonts(options)
20
+ {
21
+ bodyfont: (options[:script] == "Hans" ? '"SimSun",serif' : '"Overpass",sans-serif'),
22
+ headerfont: (options[:script] == "Hans" ? '"SimHei",sans-serif' : '"Overpass",sans-serif'),
23
+ monospacefont: '"Space Mono",monospace'
24
+ }
25
+ end
26
+
27
+ def default_file_locations(_options)
28
+ {
29
+ htmlstylesheet: html_doc_path("htmlstyle.scss"),
30
+ htmlcoverpage: html_doc_path("html_sample_titlepage.html"),
31
+ htmlintropage: html_doc_path("html_sample_intro.html"),
32
+ scripts: html_doc_path("scripts.html"),
33
+ }
34
+ end
35
+
36
+
37
+ def metadata_init(lang, script, labels)
38
+ @meta = Metadata.new(lang, script, labels)
39
+ end
40
+
41
+ def html_head
42
+ <<~HEAD.freeze
43
+ <title>{{ doctitle }}</title>
44
+ <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
45
+
46
+ <!--TOC script import-->
47
+ <script type="text/javascript" src="https://cdn.rawgit.com/jgallen23/toc/0.3.2/dist/toc.min.js"></script>
48
+
49
+ <!--Google fonts-->
50
+ <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i|Space+Mono:400,700" rel="stylesheet">
51
+ <link href="https://fonts.googleapis.com/css?family=Overpass:300,300i,600,900" rel="stylesheet">
52
+ <!--Font awesome import for the link icon-->
53
+ <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.8/css/solid.css" integrity="sha384-v2Tw72dyUXeU3y4aM2Y0tBJQkGfplr39mxZqlTBDUZAb9BGoC40+rdFCG0m10lXk" crossorigin="anonymous">
54
+ <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.8/css/fontawesome.css" integrity="sha384-q3jl8XQu1OpdLgGFvNRnPdj5VIlCvgsDQTQB6owSOHWlAurxul7f+JpUOVdAiJ5P" crossorigin="anonymous">
55
+ <style class="anchorjs"></style>
56
+ HEAD
57
+ end
58
+
59
+ def make_body(xml, docxml)
60
+ body_attr = { lang: "EN-US", link: "blue", vlink: "#954F72", "xml:lang": "EN-US", class: "container" }
61
+ xml.body **body_attr do |body|
62
+ make_body1(body, docxml)
63
+ make_body2(body, docxml)
64
+ make_body3(body, docxml)
65
+ end
66
+ end
67
+
68
+ def html_toc(docxml)
69
+ docxml
70
+ end
71
+
72
+ def annex_name(annex, name, div)
73
+ div.h1 **{ class: "Annex" } do |t|
74
+ t << "#{get_anchors[annex['id']][:label]} "
75
+ t.br
76
+ t.b do |b|
77
+ name&.children&.each { |c2| parse(c2, b) }
78
+ end
79
+ end
80
+ end
81
+
82
+ def term_defs_boilerplate(div, source, term, preface)
83
+ if source.empty? && term.nil?
84
+ div << @no_terms_boilerplate
85
+ else
86
+ div << term_defs_boilerplate_cont(source, term)
87
+ end
88
+ end
89
+
90
+ def i18n_init(lang, script)
91
+ super
92
+ @annex_lbl = "Appendix"
93
+ end
94
+
95
+ def fileloc(loc)
96
+ File.join(File.dirname(__FILE__), loc)
97
+ end
98
+
99
+ def cleanup(docxml)
100
+ super
101
+ term_cleanup(docxml)
102
+ end
103
+
104
+ def term_cleanup(docxml)
105
+ docxml.xpath("//p[@class = 'Terms']").each do |d|
106
+ h2 = d.at("./preceding-sibling::*[@class = 'TermNum'][1]")
107
+ h2.add_child("&nbsp;")
108
+ h2.add_child(d.remove)
109
+ end
110
+ docxml
111
+ end
112
+
113
+ def info(isoxml, out)
114
+ @meta.security isoxml, out
115
+ super
116
+ end
117
+ end
118
+ end
119
+ end
120
+
@@ -0,0 +1,74 @@
1
+ require "isodoc"
2
+
3
+ module IsoDoc
4
+ module Sample
5
+
6
+ class Metadata < IsoDoc::Metadata
7
+ def initialize(lang, script, labels)
8
+ super
9
+ set(:status, "XXX")
10
+ end
11
+
12
+ def title(isoxml, _out)
13
+ main = isoxml&.at(ns("//bibdata/title[@language='en']"))&.text
14
+ set(:doctitle, main)
15
+ end
16
+
17
+ def subtitle(_isoxml, _out)
18
+ nil
19
+ end
20
+
21
+ def author(isoxml, _out)
22
+ tc = isoxml.at(ns("//bibdata/editorialgroup/committee"))
23
+ set(:tc, tc.text) if tc
24
+ end
25
+
26
+ def docid(isoxml, _out)
27
+ docnumber = isoxml.at(ns("//bibdata/docidentifier"))
28
+ set(:docnumber, docnumber&.text)
29
+ end
30
+
31
+ def status_abbr(status)
32
+ case status
33
+ when "working-draft" then "wd"
34
+ when "committee-draft" then "cd"
35
+ when "draft-standard" then "d"
36
+ else
37
+ ""
38
+ end
39
+ end
40
+
41
+ def version(isoxml, _out)
42
+ super
43
+ revdate = get[:revdate]
44
+ set(:revdate_monthyear, monthyr(revdate))
45
+ end
46
+
47
+ MONTHS = {
48
+ "01": "January",
49
+ "02": "February",
50
+ "03": "March",
51
+ "04": "April",
52
+ "05": "May",
53
+ "06": "June",
54
+ "07": "July",
55
+ "08": "August",
56
+ "09": "September",
57
+ "10": "October",
58
+ "11": "November",
59
+ "12": "December",
60
+ }.freeze
61
+
62
+ def monthyr(isodate)
63
+ m = /(?<yr>\d\d\d\d)-(?<mo>\d\d)/.match isodate
64
+ return isodate unless m && m[:yr] && m[:mo]
65
+ return "#{MONTHS[m[:mo].to_sym]} #{m[:yr]}"
66
+ end
67
+
68
+ def security(isoxml, _out)
69
+ security = isoxml.at(ns("//bibdata/security")) || return
70
+ set(:security, security.text)
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,117 @@
1
+ require "isodoc"
2
+ require_relative "metadata"
3
+ require "fileutils"
4
+
5
+ module IsoDoc
6
+ module Sample
7
+ # A {Converter} implementation that generates PDF HTML output, and a
8
+ # document schema encapsulation of the document for validation
9
+ class PdfConvert < IsoDoc::PdfConvert
10
+ def initialize(options)
11
+ @libdir = File.dirname(__FILE__)
12
+ super
13
+ FileUtils.cp html_doc_path('logo.jpg'), "logo.jpg"
14
+ @files_to_delete << "logo.jpg"
15
+ end
16
+
17
+ def default_fonts(options)
18
+ {
19
+ bodyfont: (options[:script] == "Hans" ? '"SimSun",serif' : '"Overpass",sans-serif'),
20
+ headerfont: (options[:script] == "Hans" ? '"SimHei",sans-serif' : '"Overpass",sans-serif'),
21
+ monospacefont: '"Space Mono",monospace'
22
+ }
23
+ end
24
+
25
+ def default_file_locations(_options)
26
+ {
27
+ htmlstylesheet: html_doc_path("htmlstyle.scss"),
28
+ htmlcoverpage: html_doc_path("html_sample_titlepage.html"),
29
+ htmlintropage: html_doc_path("html_sample_intro.html"),
30
+ scripts_pdf: html_doc_path("scripts.pdf.html"),
31
+ }
32
+ end
33
+
34
+ def metadata_init(lang, script, labels)
35
+ @meta = Metadata.new(lang, script, labels)
36
+ end
37
+
38
+ def html_head()
39
+ <<~HEAD.freeze
40
+ <title>{{ doctitle }}</title>
41
+ <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
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
55
+
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)
62
+ end
63
+ end
64
+
65
+ def html_toc(docxml)
66
+ docxml
67
+ end
68
+
69
+ def annex_name(annex, name, div)
70
+ div.h1 **{ class: "Annex" } do |t|
71
+ t << "#{get_anchors[annex['id']][:label]} "
72
+ t.br
73
+ t.b do |b|
74
+ name&.children&.each { |c2| parse(c2, b) }
75
+ end
76
+ end
77
+ end
78
+
79
+ def term_defs_boilerplate(div, source, term, preface)
80
+ if source.empty? && term.nil?
81
+ div << @no_terms_boilerplate
82
+ else
83
+ div << term_defs_boilerplate_cont(source, term)
84
+ end
85
+ end
86
+
87
+ def i18n_init(lang, script)
88
+ super
89
+ @annex_lbl = "Appendix"
90
+ end
91
+
92
+ def fileloc(loc)
93
+ File.join(File.dirname(__FILE__), loc)
94
+ end
95
+
96
+ def cleanup(docxml)
97
+ super
98
+ term_cleanup(docxml)
99
+ end
100
+
101
+ def term_cleanup(docxml)
102
+ docxml.xpath("//p[@class = 'Terms']").each do |d|
103
+ h2 = d.at("./preceding-sibling::*[@class = 'TermNum'][1]")
104
+ h2.add_child("&nbsp;")
105
+ h2.add_child(d.remove)
106
+ end
107
+ docxml
108
+ end
109
+
110
+ def info(isoxml, out)
111
+ @meta.security isoxml, out
112
+ super
113
+ end
114
+ end
115
+ end
116
+ end
117
+
@@ -0,0 +1,98 @@
1
+ require "isodoc"
2
+ require_relative "metadata"
3
+ require "fileutils"
4
+
5
+ module IsoDoc
6
+ module Sample
7
+ # A {Converter} implementation that generates Word output, and a document
8
+ # schema encapsulation of the document for validation
9
+
10
+ class WordConvert < IsoDoc::WordConvert
11
+ def initialize(options)
12
+ @libdir = File.dirname(__FILE__)
13
+ super
14
+ FileUtils.cp html_doc_path('logo.jpg'), "logo.jpg"
15
+ end
16
+
17
+ def default_fonts(options)
18
+ {
19
+ bodyfont: (options[:script] == "Hans" ? '"SimSun",serif' : '"Arial",sans-serif'),
20
+ headerfont: (options[:script] == "Hans" ? '"SimHei",sans-serif' : '"Arial",sans-serif'),
21
+ monospacefont: '"Courier New",monospace'
22
+ }
23
+ end
24
+
25
+ def default_file_locations(_options)
26
+ {
27
+ wordstylesheet: html_doc_path("wordstyle.scss"),
28
+ standardstylesheet: html_doc_path("sample.scss"),
29
+ header: html_doc_path("header.html"),
30
+ wordcoverpage: html_doc_path("word_sample_titlepage.html"),
31
+ wordintropage: html_doc_path("word_sample_intro.html"),
32
+ ulstyle: "l3",
33
+ olstyle: "l2",
34
+ }
35
+ end
36
+
37
+ def metadata_init(lang, script, labels)
38
+ @meta = Metadata.new(lang, script, labels)
39
+ end
40
+
41
+ def make_body(xml, docxml)
42
+ body_attr = { lang: "EN-US", link: "blue", vlink: "#954F72" }
43
+ xml.body **body_attr do |body|
44
+ make_body1(body, docxml)
45
+ make_body2(body, docxml)
46
+ make_body3(body, docxml)
47
+ end
48
+ end
49
+
50
+ def info(isoxml, out)
51
+ @meta.security isoxml, out
52
+ super
53
+ end
54
+
55
+ def annex_name(annex, name, div)
56
+ div.h1 **{ class: "Annex" } do |t|
57
+ t << "#{get_anchors[annex['id']][:label]} "
58
+ t.br
59
+ t.b do |b|
60
+ name&.children&.each { |c2| parse(c2, b) }
61
+ end
62
+ end
63
+ end
64
+
65
+ def term_defs_boilerplate(div, source, term, preface)
66
+ if source.empty? && term.nil?
67
+ div << @no_terms_boilerplate
68
+ else
69
+ div << term_defs_boilerplate_cont(source, term)
70
+ end
71
+ end
72
+
73
+ def i18n_init(lang, script)
74
+ super
75
+ @annex_lbl = "Appendix"
76
+ end
77
+
78
+ def fileloc(loc)
79
+ File.join(File.dirname(__FILE__), loc)
80
+ end
81
+
82
+ def cleanup(docxml)
83
+ super
84
+ term_cleanup(docxml)
85
+ end
86
+
87
+ def term_cleanup(docxml)
88
+ docxml.xpath("//p[@class = 'Terms']").each do |d|
89
+ h2 = d.at("./preceding-sibling::*[@class = 'TermNum'][1]")
90
+ h2.add_child("&nbsp;")
91
+ h2.add_child(d.remove)
92
+ end
93
+ docxml
94
+ end
95
+
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,7 @@
1
+ require_relative "./sample/processor"
2
+
3
+ module Metanorma
4
+ module Sample
5
+
6
+ end
7
+ end
@@ -0,0 +1,43 @@
1
+ require "metanorma/processor"
2
+
3
+ module Metanorma
4
+ module Sample
5
+ class Processor < Metanorma::Processor
6
+
7
+ def initialize
8
+ @short = :sample
9
+ @input_format = :asciidoc
10
+ @asciidoctor_backend = :sample
11
+ end
12
+
13
+ def output_formats
14
+ super.merge(
15
+ html: "html",
16
+ doc: "doc",
17
+ pdf: "pdf"
18
+ )
19
+ end
20
+
21
+ def version
22
+ "Metanorma::Sample #{Metanorma::Sample::VERSION}"
23
+ end
24
+
25
+ def input_to_isodoc(file, filename)
26
+ Metanorma::Input::Asciidoc.new.process(file, filename, @asciidoctor_backend)
27
+ end
28
+
29
+ def output(isodoc_node, outname, format, options={})
30
+ case format
31
+ when :html
32
+ IsoDoc::Sample::HtmlConvert.new(options).convert(outname, isodoc_node)
33
+ when :doc
34
+ IsoDoc::Sample::WordConvert.new(options).convert(outname, isodoc_node)
35
+ when :pdf
36
+ IsoDoc::Sample::PdfConvert.new(options).convert(outname, isodoc_node)
37
+ else
38
+ super
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end