metanorma-generic 1.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/macos.yml +39 -0
- data/.github/workflows/ubuntu.yml +39 -0
- data/.github/workflows/windows.yml +42 -0
- data/.gitignore +1 -0
- data/.hound.yml +3 -0
- data/.rubocop.ribose.yml +66 -0
- data/.rubocop.tb.yml +650 -0
- data/.rubocop.yml +10 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +11 -0
- data/LICENSE +25 -0
- data/README.adoc +52 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/rspec +17 -0
- data/bin/setup +8 -0
- data/lib/asciidoctor/generic.rb +7 -0
- data/lib/asciidoctor/generic/basicdoc.rng +1059 -0
- data/lib/asciidoctor/generic/biblio.rng +1142 -0
- data/lib/asciidoctor/generic/converter.rb +172 -0
- data/lib/asciidoctor/generic/generic.rng +79 -0
- data/lib/asciidoctor/generic/isodoc.rng +1033 -0
- data/lib/asciidoctor/generic/reqt.rng +171 -0
- data/lib/asciidoctor/generic/rsd.rng +225 -0
- data/lib/isodoc/generic.rb +10 -0
- data/lib/isodoc/generic/base_convert.rb +59 -0
- data/lib/isodoc/generic/html/generic.scss +766 -0
- data/lib/isodoc/generic/html/header.html +253 -0
- data/lib/isodoc/generic/html/html_generic_intro.html +8 -0
- data/lib/isodoc/generic/html/html_generic_titlepage.html +106 -0
- data/lib/isodoc/generic/html/htmlstyle.scss +710 -0
- data/lib/isodoc/generic/html/logo.jpg +0 -0
- data/lib/isodoc/generic/html/scripts.html +84 -0
- data/lib/isodoc/generic/html/scripts.pdf.html +72 -0
- data/lib/isodoc/generic/html/word_generic_intro.html +72 -0
- data/lib/isodoc/generic/html/word_generic_titlepage.html +75 -0
- data/lib/isodoc/generic/html/wordstyle.scss +1157 -0
- data/lib/isodoc/generic/html_convert.rb +63 -0
- data/lib/isodoc/generic/metadata.rb +48 -0
- data/lib/isodoc/generic/pdf_convert.rb +64 -0
- data/lib/isodoc/generic/word_convert.rb +56 -0
- data/lib/metanorma-generic.rb +8 -0
- data/lib/metanorma/generic.rb +88 -0
- data/lib/metanorma/generic/processor.rb +71 -0
- data/lib/metanorma/generic/version.rb +5 -0
- data/metanorma-generic.gemspec +43 -0
- data/metanorma.yml.example +19 -0
- metadata +276 -0
@@ -0,0 +1,63 @@
|
|
1
|
+
require_relative "base_convert"
|
2
|
+
require "isodoc"
|
3
|
+
|
4
|
+
module IsoDoc
|
5
|
+
module Generic
|
6
|
+
|
7
|
+
# A {Converter} implementation that generates HTML output, and a document
|
8
|
+
# schema encapsulation of the document for validation
|
9
|
+
#
|
10
|
+
class HtmlConvert < IsoDoc::HtmlConvert
|
11
|
+
def initialize(options)
|
12
|
+
@libdir = File.dirname(__FILE__)
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
class << self
|
17
|
+
attr_accessor :_file
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.inherited( k )
|
21
|
+
k._file = caller_locations.first.absolute_path
|
22
|
+
end
|
23
|
+
|
24
|
+
def default_fonts(options)
|
25
|
+
{
|
26
|
+
bodyfont: (options[:script] == "Hans" ? '"SimSun",serif'
|
27
|
+
: configuration.html_bodyfont || '"Overpass",sans-serif'),
|
28
|
+
headerfont: (options[:script] == "Hans" ? '"SimHei",sans-serif' :
|
29
|
+
configuration.html_headerfont || '"Overpass",sans-serif'),
|
30
|
+
monospacefont: configuration.html_monospacefont || '"Space Mono",monospace'
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
def default_file_locations(_options)
|
35
|
+
{
|
36
|
+
htmlstylesheet: baselocation(configuration.htmlstylesheet) ||
|
37
|
+
html_doc_path("htmlstyle.scss"),
|
38
|
+
htmlcoverpage: baselocation(configuration.htmlcoverpage) ||
|
39
|
+
html_doc_path("html_generic_titlepage.html"),
|
40
|
+
htmlintropage: baselocation(configuration.htmlintropage) ||
|
41
|
+
html_doc_path("html_generic_intro.html"),
|
42
|
+
scripts: baselocation(configuration.scripts) ||
|
43
|
+
html_doc_path("scripts.html"),
|
44
|
+
i18nyaml: baselocation(configuration.i18nyaml)
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
def configuration
|
49
|
+
Metanorma::Generic.configuration
|
50
|
+
end
|
51
|
+
|
52
|
+
def googlefonts
|
53
|
+
<<~HEAD.freeze
|
54
|
+
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i|Space+Mono:400,700" rel="stylesheet">
|
55
|
+
<link href="https://fonts.googleapis.com/css?family=Overpass:300,300i,600,900" rel="stylesheet">
|
56
|
+
HEAD
|
57
|
+
end
|
58
|
+
|
59
|
+
include BaseConvert
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require "isodoc"
|
2
|
+
|
3
|
+
module IsoDoc
|
4
|
+
module Generic
|
5
|
+
|
6
|
+
class Metadata < IsoDoc::Metadata
|
7
|
+
def initialize(lang, script, labels)
|
8
|
+
super
|
9
|
+
here = File.dirname(__FILE__)
|
10
|
+
default_logo_path = File.expand_path(File.join(here, "html", "logo.jpg"))
|
11
|
+
set(:logo, baselocation(configuration.logo_path) || default_logo_path)
|
12
|
+
end
|
13
|
+
|
14
|
+
class << self
|
15
|
+
attr_accessor :_file
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.inherited( k )
|
19
|
+
k._file = caller_locations.first.absolute_path
|
20
|
+
end
|
21
|
+
|
22
|
+
def baselocation(loc)
|
23
|
+
return nil if loc.nil?
|
24
|
+
File.expand_path(File.join(File.dirname(self.class::_file || __FILE__), "..", "..", "..", loc))
|
25
|
+
end
|
26
|
+
|
27
|
+
def configuration
|
28
|
+
Metanorma::Generic.configuration
|
29
|
+
end
|
30
|
+
|
31
|
+
def author(isoxml, _out)
|
32
|
+
super
|
33
|
+
tc = isoxml.at(ns("//bibdata/ext/editorialgroup/committee"))
|
34
|
+
set(:tc, tc.text) if tc
|
35
|
+
end
|
36
|
+
|
37
|
+
def stage_abbr(status)
|
38
|
+
return super unless configuration.stage_abbreviations
|
39
|
+
Hash(configuration.stage_abbreviations).dig(status)
|
40
|
+
end
|
41
|
+
|
42
|
+
def unpublished(status)
|
43
|
+
stages = configuration&.published_stages || ["published"]
|
44
|
+
!(Array(stages).map { |m| m.downcase }.include? status.downcase)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require_relative "base_convert"
|
2
|
+
require "isodoc"
|
3
|
+
|
4
|
+
module IsoDoc
|
5
|
+
module Generic
|
6
|
+
# A {Converter} implementation that generates PDF HTML output, and a
|
7
|
+
# document schema encapsulation of the document for validation
|
8
|
+
class PdfConvert < IsoDoc::PdfConvert
|
9
|
+
def initialize(options)
|
10
|
+
@libdir = File.dirname(__FILE__)
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
class << self
|
15
|
+
attr_accessor :_file
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.inherited( k )
|
19
|
+
k._file = caller_locations.first.absolute_path
|
20
|
+
end
|
21
|
+
|
22
|
+
def default_fonts(options)
|
23
|
+
{
|
24
|
+
bodyfont: (options[:script] == "Hans" ? '"SimSun",serif'
|
25
|
+
: configuration.html_bodyfont || '"Overpass",sans-serif'),
|
26
|
+
headerfont: (options[:script] == "Hans" ? '"SimHei",sans-serif' :
|
27
|
+
configuration.html_headerfont || '"Overpass",sans-serif'),
|
28
|
+
monospacefont: configuration.html_monospacefont || '"Space Mono",monospace'
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def default_file_locations(_options)
|
33
|
+
{
|
34
|
+
htmlstylesheet: baselocation(configuration.htmlstylesheet) ||
|
35
|
+
html_doc_path("htmlstyle.scss"),
|
36
|
+
htmlcoverpage: baselocation(configuration.htmlcoverpage) ||
|
37
|
+
html_doc_path("html_generic_titlepage.html"),
|
38
|
+
htmlintropage: baselocation(configuration.htmlintropage) ||
|
39
|
+
html_doc_path("html_generic_intro.html"),
|
40
|
+
scripts_pdf: baselocation(configuration.scripts_pdf) ||
|
41
|
+
html_doc_path("scripts.pdf.html")
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
def googlefonts
|
46
|
+
<<~HEAD.freeze
|
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
|
+
HEAD
|
50
|
+
end
|
51
|
+
|
52
|
+
def html_toc(docxml)
|
53
|
+
docxml
|
54
|
+
end
|
55
|
+
|
56
|
+
def configuration
|
57
|
+
Metanorma::Generic.configuration
|
58
|
+
end
|
59
|
+
|
60
|
+
include BaseConvert
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require_relative "base_convert"
|
2
|
+
require "isodoc"
|
3
|
+
|
4
|
+
module IsoDoc
|
5
|
+
module Generic
|
6
|
+
# A {Converter} implementation that generates Word output, and a document
|
7
|
+
# schema encapsulation of the document for validation
|
8
|
+
|
9
|
+
class WordConvert < IsoDoc::WordConvert
|
10
|
+
def initialize(options)
|
11
|
+
@libdir = File.dirname(__FILE__)
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
class << self
|
16
|
+
attr_accessor :_file
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.inherited( k )
|
20
|
+
k._file = caller_locations.first.absolute_path
|
21
|
+
end
|
22
|
+
|
23
|
+
def default_fonts(options)
|
24
|
+
{
|
25
|
+
bodyfont: (options[:script] == "Hans" ? '"SimSun",serif' : configuration.word_bodyfont || '"Arial",sans-serif'),
|
26
|
+
headerfont: (options[:script] == "Hans" ? '"SimHei",sans-serif' : configuration.word_headerfont || '"Arial",sans-serif'),
|
27
|
+
monospacefont: configuration.word_monospacefont || '"Courier New",monospace'
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def default_file_locations(options)
|
32
|
+
{
|
33
|
+
wordstylesheet: baselocation(configuration.wordstylesheet) ||
|
34
|
+
html_doc_path("wordstyle.scss"),
|
35
|
+
standardstylesheet: baselocation(configuration.standardstylesheet) ||
|
36
|
+
html_doc_path("generic.scss"),
|
37
|
+
header: baselocation(configuration.header) ||
|
38
|
+
html_doc_path("header.html"),
|
39
|
+
wordcoverpage: baselocation(configuration.wordcoverpage) ||
|
40
|
+
html_doc_path("word_generic_titlepage.html"),
|
41
|
+
wordintropage: baselocation(configuration.wordintropage) ||
|
42
|
+
html_doc_path("word_generic_intro.html"),
|
43
|
+
i18nyaml: baselocation(configuration.i18nyaml),
|
44
|
+
ulstyle: "l3",
|
45
|
+
olstyle: "l2",
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
def configuration
|
50
|
+
Metanorma::Generic.configuration
|
51
|
+
end
|
52
|
+
|
53
|
+
include BaseConvert
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require "metanorma/generic/processor"
|
2
|
+
require "metanorma/generic/version"
|
3
|
+
require 'forwardable'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
module Metanorma
|
7
|
+
module Generic
|
8
|
+
ORGANIZATION_NAME_SHORT = "Acme"
|
9
|
+
ORGANIZATION_NAME_LONG = "Acme Corp."
|
10
|
+
DOCUMENT_NAMESPACE = "https://metanorma.org/ns/generic"
|
11
|
+
YAML_CONFIG_FILE = 'metanorma.yml'
|
12
|
+
|
13
|
+
class Configuration
|
14
|
+
CONFIG_ATTRS = %i[
|
15
|
+
organization_name_short
|
16
|
+
organization_name_long
|
17
|
+
document_namespace
|
18
|
+
docid_template
|
19
|
+
i18nyaml
|
20
|
+
logo_path
|
21
|
+
header
|
22
|
+
htmlcoverpage
|
23
|
+
htmlintropage
|
24
|
+
htmlstylesheet
|
25
|
+
html_bodyfont
|
26
|
+
html_headerfont
|
27
|
+
html_monospacefont
|
28
|
+
published_stages
|
29
|
+
stage_abbreviations
|
30
|
+
scripts
|
31
|
+
scripts_pdf
|
32
|
+
standardstylesheet
|
33
|
+
validate_rng_file
|
34
|
+
wordcoverpage
|
35
|
+
wordintropage
|
36
|
+
wordstylesheet
|
37
|
+
word_bodyfont
|
38
|
+
word_headerfont
|
39
|
+
word_monospacefont
|
40
|
+
xml_root_tag
|
41
|
+
].freeze
|
42
|
+
|
43
|
+
attr_accessor(*CONFIG_ATTRS)
|
44
|
+
|
45
|
+
class << self
|
46
|
+
attr_accessor :_file
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.inherited( k )
|
50
|
+
k._file = caller_locations.first.absolute_path
|
51
|
+
end
|
52
|
+
|
53
|
+
def initialize(*args)
|
54
|
+
super
|
55
|
+
# Try to set config values from yaml file in current directory
|
56
|
+
@yaml = File.join(File.dirname(self.class::_file || __FILE__), "..", "..", YAML_CONFIG_FILE)
|
57
|
+
set_default_values_from_yaml_file(@yaml) if File.file?(@yaml)
|
58
|
+
self.organization_name_short ||= ORGANIZATION_NAME_SHORT
|
59
|
+
self.organization_name_long ||= ORGANIZATION_NAME_LONG
|
60
|
+
self.document_namespace ||= DOCUMENT_NAMESPACE
|
61
|
+
end
|
62
|
+
|
63
|
+
def set_default_values_from_yaml_file(config_file)
|
64
|
+
default_config_options = YAML.load(File.read(config_file))
|
65
|
+
CONFIG_ATTRS.each do |attr_name|
|
66
|
+
instance_variable_set("@#{attr_name}", default_config_options[attr_name.to_s])
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
class << self
|
72
|
+
extend Forwardable
|
73
|
+
|
74
|
+
attr_accessor :configuration
|
75
|
+
|
76
|
+
Configuration::CONFIG_ATTRS.each do |attr_name|
|
77
|
+
def_delegator :@configuration, attr_name
|
78
|
+
end
|
79
|
+
|
80
|
+
def configure
|
81
|
+
self.configuration ||= Configuration.new
|
82
|
+
yield(configuration)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
configure {}
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require "metanorma/processor"
|
2
|
+
|
3
|
+
module Metanorma
|
4
|
+
module Generic
|
5
|
+
class Processor < Metanorma::Processor
|
6
|
+
def initialize
|
7
|
+
@short = :generic
|
8
|
+
@input_format = :asciidoc
|
9
|
+
@asciidoctor_backend = :generic
|
10
|
+
end
|
11
|
+
|
12
|
+
def output_formats
|
13
|
+
super.merge(
|
14
|
+
html: "html",
|
15
|
+
doc: "doc",
|
16
|
+
pdf: "pdf"
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
def version
|
21
|
+
"Metanorma::Generic #{Metanorma::Generic::VERSION}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def input_to_isodoc(file, filename)
|
25
|
+
Metanorma::Input::Asciidoc.new.process(file, filename, @asciidoctor_backend)
|
26
|
+
end
|
27
|
+
|
28
|
+
def extract_options(file)
|
29
|
+
head = file.sub(/\n\n.*$/m, "\n")
|
30
|
+
/\n:htmlstylesheet: (?<htmlstylesheet>[^\n]+)\n/ =~ head
|
31
|
+
/\n:htmlcoverpage: (?<htmlcoverpage>[^\n]+)\n/ =~ head
|
32
|
+
/\n:htmlintropage: (?<htmlintropage>[^\n]+)\n/ =~ head
|
33
|
+
/\n:scripts: (?<scripts>[^\n]+)\n/ =~ head
|
34
|
+
/\n:wordstylesheet: (?<wordstylesheet>[^\n]+)\n/ =~ head
|
35
|
+
/\n:standardstylesheet: (?<standardstylesheet>[^\n]+)\n/ =~ head
|
36
|
+
/\n:header: (?<header>[^\n]+)\n/ =~ head
|
37
|
+
/\n:wordcoverpage: (?<wordcoverpage>[^\n]+)\n/ =~ head
|
38
|
+
/\n:wordintropage: (?<wordintropage>[^\n]+)\n/ =~ head
|
39
|
+
/\n:ulstyle: (?<ulstyle>[^\n]+)\n/ =~ head
|
40
|
+
/\n:olstyle: (?<olstyle>[^\n]+)\n/ =~ head
|
41
|
+
new_options = {
|
42
|
+
htmlstylesheet: defined?(htmlstylesheet) ? htmlstylesheet : nil,
|
43
|
+
htmlcoverpage: defined?(htmlcoverpage) ? htmlcoverpage : nil,
|
44
|
+
htmlintropage: defined?(htmlintropage) ? htmlintropage : nil,
|
45
|
+
scripts: defined?(scripts) ? scripts : nil,
|
46
|
+
wordstylesheet: defined?(wordstylesheet) ? wordstylesheet : nil,
|
47
|
+
standardstylesheet: defined?(standardstylesheet) ? standardstylesheet : nil,
|
48
|
+
header: defined?(header) ? header : nil,
|
49
|
+
wordcoverpage: defined?(wordcoverpage) ? wordcoverpage : nil,
|
50
|
+
wordintropage: defined?(wordintropage) ? wordintropage : nil,
|
51
|
+
ulstyle: defined?(ulstyle) ? ulstyle : nil,
|
52
|
+
olstyle: defined?(olstyle) ? olstyle : nil,
|
53
|
+
}.reject { |_, val| val.nil? }
|
54
|
+
super.merge(new_options)
|
55
|
+
end
|
56
|
+
|
57
|
+
def output(isodoc_node, outname, format, options={})
|
58
|
+
case format
|
59
|
+
when :html
|
60
|
+
IsoDoc::Generic::HtmlConvert.new(options).convert(outname, isodoc_node)
|
61
|
+
when :doc
|
62
|
+
IsoDoc::Generic::WordConvert.new(options).convert(outname, isodoc_node)
|
63
|
+
when :pdf
|
64
|
+
IsoDoc::Generic::PdfConvert.new(options).convert(outname, isodoc_node)
|
65
|
+
else
|
66
|
+
super
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "metanorma/generic/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "metanorma-generic"
|
7
|
+
spec.version = Metanorma::Generic::VERSION
|
8
|
+
spec.authors = ["Ribose Inc."]
|
9
|
+
spec.email = ["open.source@ribose.com"]
|
10
|
+
|
11
|
+
spec.summary = "Metanorma template gem for customisation."
|
12
|
+
spec.description = <<~DESCRIPTION
|
13
|
+
Metanorma template gem for customisation. This gem is meant to be customised for any downstream use.
|
14
|
+
|
15
|
+
Formerly known as metanorma-acme
|
16
|
+
DESCRIPTION
|
17
|
+
|
18
|
+
spec.homepage = "https://github.com/metanorma/metanorma-generic"
|
19
|
+
spec.license = "BSD-2-Clause"
|
20
|
+
|
21
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
22
|
+
f.match(%r{^(test|spec|features)/})
|
23
|
+
end
|
24
|
+
spec.bindir = "exe"
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
28
|
+
|
29
|
+
spec.add_dependency "htmlentities", "~> 4.3.4"
|
30
|
+
spec.add_dependency "ruby-jing"
|
31
|
+
spec.add_dependency "metanorma-standoc", "~> 1.3.0"
|
32
|
+
spec.add_dependency "isodoc", "~> 1.0.0"
|
33
|
+
|
34
|
+
spec.add_development_dependency "byebug", "~> 9.1"
|
35
|
+
spec.add_development_dependency "equivalent-xml", "~> 0.6"
|
36
|
+
spec.add_development_dependency "guard", "~> 2.14"
|
37
|
+
spec.add_development_dependency "guard-rspec", "~> 4.7"
|
38
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
39
|
+
spec.add_development_dependency "rspec", "~> 3.6"
|
40
|
+
spec.add_development_dependency "rubocop", "= 0.54.0"
|
41
|
+
spec.add_development_dependency "simplecov", "~> 0.15"
|
42
|
+
spec.add_development_dependency "timecop", "~> 0.9"
|
43
|
+
end
|