metanorma 1.2.8 → 1.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +2 -12
- data/.hound.yml +3 -1
- data/.rubocop.yml +3 -7
- data/Rakefile +1 -1
- data/lib/metanorma/asciidoctor_extensions/glob_include_processor.rb +4 -6
- data/lib/metanorma/collection.rb +32 -16
- data/lib/metanorma/collection_fileparse.rb +220 -0
- data/lib/metanorma/collection_fileprocess.rb +66 -222
- data/lib/metanorma/collection_manifest.rb +9 -6
- data/lib/metanorma/collection_renderer.rb +28 -9
- data/lib/metanorma/compile.rb +32 -158
- data/lib/metanorma/compile_validate.rb +51 -0
- data/lib/metanorma/config.rb +1 -1
- data/lib/metanorma/document.rb +24 -10
- data/lib/metanorma/fontist_utils.rb +108 -0
- data/lib/metanorma/input.rb +0 -1
- data/lib/metanorma/input/asciidoc.rb +38 -75
- data/lib/metanorma/output.rb +0 -2
- data/lib/metanorma/output/utils.rb +2 -1
- data/lib/metanorma/util.rb +4 -0
- data/lib/metanorma/version.rb +1 -1
- data/metanorma.gemspec +21 -22
- metadata +47 -44
data/lib/metanorma/config.rb
CHANGED
data/lib/metanorma/document.rb
CHANGED
@@ -1,20 +1,25 @@
|
|
1
1
|
module Metanorma
|
2
2
|
class Document
|
3
3
|
# @return [Strin]
|
4
|
-
attr_reader :file
|
4
|
+
attr_reader :file, :attachment, :bibitem
|
5
5
|
|
6
6
|
# @param bibitem [RelatonBib::BibliographicItem]
|
7
7
|
def initialize(bibitem, file, options = {})
|
8
8
|
@bibitem = bibitem
|
9
9
|
@file = file
|
10
|
+
@attachment = options[:attachment]
|
10
11
|
@raw = options[:raw]
|
11
12
|
end
|
12
13
|
|
13
14
|
class << self
|
14
15
|
# @param file [String] file path
|
16
|
+
# @param attachment [Bool] is an attachment
|
17
|
+
# @param identifier [String] is the identifier assigned the file
|
18
|
+
# in the collection file
|
15
19
|
# @return [Metanorma::Document]
|
16
|
-
def parse_file(file)
|
17
|
-
new
|
20
|
+
def parse_file(file, attachment, identifier = nil)
|
21
|
+
new(bibitem(file, attachment, identifier), file,
|
22
|
+
{ attachment: attachment })
|
18
23
|
end
|
19
24
|
|
20
25
|
# #param xml [Nokogiri::XML::Document, Nokogiri::XML::Element]
|
@@ -29,6 +34,12 @@ module Metanorma
|
|
29
34
|
new(doc, filename, raw: true)
|
30
35
|
end
|
31
36
|
|
37
|
+
def attachment_bibitem(identifier)
|
38
|
+
Nokogiri::XML(
|
39
|
+
"<bibdata><docidentifier>#{identifier}</docidentifier></bibdata>",
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
32
43
|
private
|
33
44
|
|
34
45
|
# #param xml [Nokogiri::XML::Document, Nokogiri::XML::Element]
|
@@ -49,13 +60,16 @@ module Metanorma
|
|
49
60
|
# @param file [String]
|
50
61
|
# @return [RelatonBib::BibliographicItem,
|
51
62
|
# RelatonIso::IsoBibliographicItem]
|
52
|
-
def bibitem(file)
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
63
|
+
def bibitem(file, attachment, identifier)
|
64
|
+
if attachment then attachment_bibitem(identifier)
|
65
|
+
else
|
66
|
+
case format(file)
|
67
|
+
when :xml
|
68
|
+
from_xml Nokogiri::XML(File.read(file, encoding: "UTF-8"))
|
69
|
+
when :yaml
|
70
|
+
yaml = File.read(file, encoding: "UTF-8")
|
71
|
+
Relaton::Cli::YAMLConvertor.convert_single_file(yaml)
|
72
|
+
end
|
59
73
|
end
|
60
74
|
end
|
61
75
|
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
module Metanorma
|
2
|
+
class FontistUtils
|
3
|
+
class << self
|
4
|
+
private
|
5
|
+
|
6
|
+
def validate_options(options)
|
7
|
+
agree_to_terms = options[:agree_to_terms] || false
|
8
|
+
continue_without_fonts = options[:continue_without_fonts] || false
|
9
|
+
no_progress = options[:no_progress] || false
|
10
|
+
|
11
|
+
[agree_to_terms, continue_without_fonts, no_progress]
|
12
|
+
end
|
13
|
+
|
14
|
+
def validate_install_fonts(processor, options)
|
15
|
+
if options[:no_install_fonts]
|
16
|
+
Util.log("[fontist] Skip font installation because" \
|
17
|
+
" --no-install-fonts argument passed", :debug)
|
18
|
+
return false
|
19
|
+
elsif missing_fontist_manifest?(processor)
|
20
|
+
Util.log("[fontist] Skip font installation because "\
|
21
|
+
"font_manifest is missing", :debug)
|
22
|
+
return false
|
23
|
+
end
|
24
|
+
true
|
25
|
+
end
|
26
|
+
|
27
|
+
def install_fonts_safe(manifest, agree, continue, no_progress)
|
28
|
+
fontist_install(manifest, agree, no_progress)
|
29
|
+
rescue Fontist::Errors::LicensingError
|
30
|
+
if continue
|
31
|
+
Util.log(
|
32
|
+
"[fontist] Processing will continue without fonts installed",
|
33
|
+
:debug
|
34
|
+
)
|
35
|
+
else
|
36
|
+
Util.log("[fontist] Aborting without proper fonts installed," \
|
37
|
+
" make sure that you have set option --agree-to-terms",
|
38
|
+
:fatal)
|
39
|
+
end
|
40
|
+
rescue Fontist::Errors::FontError => e
|
41
|
+
log_level = continue ? :warning : :fatal
|
42
|
+
Util.log("[fontist] '#{e.font}' font is not supported. " \
|
43
|
+
"Please report this issue at github.com/metanorma/metanorma" \
|
44
|
+
"/issues to report this issue.", log_level)
|
45
|
+
rescue Fontist::Errors::FormulaIndexNotFoundError
|
46
|
+
if @@updated_formulas_repo
|
47
|
+
Util.log(
|
48
|
+
"[fontist] Bug: formula index not found after 'fontist update'",
|
49
|
+
:fatal
|
50
|
+
)
|
51
|
+
end
|
52
|
+
Util.log("[fontist] Missing formula index. Fetching it...", :debug)
|
53
|
+
Fontist::Formula.update_formulas_repo
|
54
|
+
@@updated_formulas_repo = true
|
55
|
+
install_fonts_safe(manifest, agree, continue, no_progress)
|
56
|
+
end
|
57
|
+
|
58
|
+
def fontist_install(manifest, agree, no_progress)
|
59
|
+
Fontist::Manifest::Install.from_hash(
|
60
|
+
manifest,
|
61
|
+
confirmation: agree ? "yes" : "no",
|
62
|
+
no_progress: no_progress
|
63
|
+
)
|
64
|
+
end
|
65
|
+
|
66
|
+
def dump_fontist_manifest_locations(manifest)
|
67
|
+
location_manifest = Fontist::Manifest::Locations.from_hash(
|
68
|
+
manifest
|
69
|
+
)
|
70
|
+
location_manifest_file = Tempfile.new(["fontist_locations", ".yml"])
|
71
|
+
location_manifest_file.write location_manifest.to_yaml
|
72
|
+
location_manifest_file.flush
|
73
|
+
location_manifest_file
|
74
|
+
end
|
75
|
+
|
76
|
+
def missing_fontist_manifest?(processor)
|
77
|
+
!processor.respond_to?(:fonts_manifest) || processor.fonts_manifest.nil?
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.install_fonts(processor, options)
|
82
|
+
return unless validate_install_fonts(processor, options)
|
83
|
+
|
84
|
+
@@updated_formulas_repo = false
|
85
|
+
manifest = processor.fonts_manifest
|
86
|
+
agree_to_terms, can_without_fonts, no_progress = validate_options(options)
|
87
|
+
|
88
|
+
install_fonts_safe(
|
89
|
+
manifest,
|
90
|
+
agree_to_terms,
|
91
|
+
can_without_fonts,
|
92
|
+
no_progress
|
93
|
+
)
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.fontist_font_locations(processor, options)
|
97
|
+
if missing_fontist_manifest?(processor) || options[:no_install_fonts]
|
98
|
+
return nil
|
99
|
+
end
|
100
|
+
|
101
|
+
dump_fontist_manifest_locations(processor.fonts_manifest)
|
102
|
+
rescue Fontist::Errors::FormulaIndexNotFoundError
|
103
|
+
raise unless options[:continue_without_fonts]
|
104
|
+
|
105
|
+
nil
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
data/lib/metanorma/input.rb
CHANGED
@@ -2,20 +2,14 @@ require "nokogiri"
|
|
2
2
|
|
3
3
|
module Metanorma
|
4
4
|
module Input
|
5
|
-
|
6
5
|
class Asciidoc < Base
|
7
|
-
|
8
6
|
def process(file, filename, type, options = {})
|
9
7
|
require "asciidoctor"
|
10
8
|
out_opts = {
|
11
|
-
to_file: false,
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
attributes: [
|
16
|
-
"nodoc", "stem", "xrefstyle=short", "docfile=#{filename}",
|
17
|
-
"output_dir=#{options[:output_dir]}"
|
18
|
-
]
|
9
|
+
to_file: false, safe: :safe, backend: type, header_footer: true,
|
10
|
+
attributes: ["nodoc", "stem", "xrefstyle=short",
|
11
|
+
"docfile=#{filename}",
|
12
|
+
"output_dir=#{options[:output_dir]}"]
|
19
13
|
}
|
20
14
|
unless asciidoctor_validate(file, filename, out_opts)
|
21
15
|
warn "Cannot continue compiling Asciidoctor document"
|
@@ -27,11 +21,12 @@ module Metanorma
|
|
27
21
|
def asciidoctor_validate(file, filename, options)
|
28
22
|
err = nil
|
29
23
|
begin
|
30
|
-
previous_stderr
|
24
|
+
previous_stderr = $stderr
|
25
|
+
$stderr = StringIO.new
|
31
26
|
::Asciidoctor.load(file, options)
|
32
|
-
%r{(\n|^)asciidoctor: ERROR: ['"]?#{Regexp.escape(filename ||
|
33
|
-
"<empty>")}['"]?: line \d+: include file not found: }
|
34
|
-
|
27
|
+
%r{(\n|^)asciidoctor: ERROR: ['"]?#{Regexp.escape(filename ||
|
28
|
+
"<empty>")}['"]?: line \d+: include file not found: }
|
29
|
+
.match($stderr.string) and err = $stderr.string
|
35
30
|
ensure
|
36
31
|
$stderr = previous_stderr
|
37
32
|
end
|
@@ -45,8 +40,9 @@ module Metanorma
|
|
45
40
|
/\n:mn-output-extensions: (?<extensions>[^\n]+)\n/ =~ headerextract
|
46
41
|
/\n:mn-relaton-output-file: (?<relaton>[^\n]+)\n/ =~ headerextract
|
47
42
|
/\n(?<asciimath>:mn-keep-asciimath:[^\n]*)\n/ =~ headerextract
|
48
|
-
asciimath = defined?(asciimath)
|
49
|
-
|
43
|
+
asciimath = if defined?(asciimath)
|
44
|
+
(!asciimath.nil? && asciimath != ":mn-keep-asciimath: false")
|
45
|
+
end
|
50
46
|
asciimath = nil if asciimath == false
|
51
47
|
{
|
52
48
|
type: defined?(type) ? type : nil,
|
@@ -60,72 +56,39 @@ module Metanorma
|
|
60
56
|
attr&.sub(/^#{name}:\s*$/, "#{name}: true")&.sub(/^#{name}:\s+/, "")
|
61
57
|
end
|
62
58
|
|
63
|
-
|
64
|
-
|
59
|
+
ADOC_OPTIONS = %w(htmlstylesheet htmlcoverpage htmlintropage scripts
|
60
|
+
scripts-override scripts-pdf wordstylesheet bare i18nyaml
|
61
|
+
standardstylesheet header wordcoverpage wordintropage
|
62
|
+
ulstyle olstyle htmlstylesheet-override
|
63
|
+
htmltoclevels doctoclevels sectionsplit
|
64
|
+
body-font header-font monospace-font title-font
|
65
|
+
wordstylesheet-override).freeze
|
65
66
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
/\n:
|
74
|
-
/\n:
|
75
|
-
/\n:
|
76
|
-
/\n:
|
77
|
-
/\n:scripts-pdf: (?<scripts_pdf>[^\n]+)\n/ =~ headerextract
|
78
|
-
/\n:wordstylesheet: (?<wordstylesheet>[^\n]+)\n/ =~ headerextract
|
79
|
-
/\n:wordstylesheet-override: (?<wordstylesheet_override>[^\n]+)\n/ =~ headerextract
|
80
|
-
/\n:standardstylesheet: (?<standardstylesheet>[^\n]+)\n/ =~ headerextract
|
81
|
-
/\n:header: (?<header>[^\n]+)\n/ =~ headerextract
|
82
|
-
/\n:wordcoverpage: (?<wordcoverpage>[^\n]+)\n/ =~ headerextract
|
83
|
-
/\n:wordintropage: (?<wordintropage>[^\n]+)\n/ =~ headerextract
|
84
|
-
/\n:ulstyle: (?<ulstyle>[^\n]+)\n/ =~ headerextract
|
85
|
-
/\n:olstyle: (?<olstyle>[^\n]+)\n/ =~ headerextract
|
86
|
-
/\n:data-uri-image: (?<datauriimage>[^\n]+)\n/ =~ headerextract
|
87
|
-
/\n:htmltoclevels: (?<htmltoclevels>[^\n]+)\n/ =~ headerextract
|
88
|
-
/\n:doctoclevels: (?<doctoclevels>[^\n]+)\n/ =~ headerextract
|
89
|
-
/\n:(?<hierarchical_assets>hierarchical-assets:[^\n]*)\n/ =~ headerextract
|
90
|
-
/\n:(?<use_xinclude>use-xinclude:[^\n]*)\n/ =~ headerextract
|
91
|
-
/\n:(?<break_up_urls_in_tables>break-up-urls-in-tables:[^\n]*)\n/ =~ headerextract
|
67
|
+
def extract_options(file)
|
68
|
+
header = file.sub(/\n\n.*$/m, "\n")
|
69
|
+
ret = ADOC_OPTIONS.each_with_object({}) do |w, acc|
|
70
|
+
m = /\n:#{w}: ([^\n]+)\n/.match(header) or next
|
71
|
+
acc[w.gsub(/-/, "").sub(/override$/, "_override")
|
72
|
+
.sub(/pdf$/, "_pdf").to_sym] = m[1]
|
73
|
+
end
|
74
|
+
/\n:data-uri-image: (?<datauriimage>[^\n]+)\n/ =~ header
|
75
|
+
/\n:(?<hier_assets>hierarchical-assets:[^\n]*)\n/ =~ header
|
76
|
+
/\n:(?<use_xinclude>use-xinclude:[^\n]*)\n/ =~ header
|
77
|
+
/\n:(?<break_up>break-up-urls-in-tables:[^\n]*)\n/ =~ header
|
92
78
|
|
93
|
-
defined?(
|
94
|
-
|
79
|
+
defined?(hier_assets) and
|
80
|
+
hier_assets = empty_attr(hier_assets, "hierarchical-assets")
|
95
81
|
defined?(use_xinclude) and
|
96
82
|
use_xinclude = empty_attr(use_xinclude, "use-xinclude")
|
97
|
-
defined?(
|
98
|
-
|
99
|
-
|
100
|
-
script: defined?(script) ? script : nil,
|
101
|
-
bodyfont: defined?(bodyfont) ? bodyfont : nil,
|
102
|
-
headerfont: defined?(headerfont) ? headerfont : nil,
|
103
|
-
monospacefont: defined?(monospacefont) ? monospacefont : nil,
|
104
|
-
titlefont: defined?(titlefont) ? titlefont : nil,
|
105
|
-
i18nyaml: defined?(i18nyaml) ? i18nyaml : nil,
|
106
|
-
htmlstylesheet: defined?(htmlstylesheet) ? htmlstylesheet : nil,
|
107
|
-
htmlstylesheet_override: defined?(htmlstylesheet_override) ? htmlstylesheet_override : nil,
|
108
|
-
htmlcoverpage: defined?(htmlcoverpage) ? htmlcoverpage : nil,
|
109
|
-
htmlintropage: defined?(htmlintropage) ? htmlintropage : nil,
|
110
|
-
scripts: defined?(scripts) ? scripts : nil,
|
111
|
-
scripts_pdf: defined?(scripts_pdf) ? scripts_pdf : nil,
|
112
|
-
wordstylesheet: defined?(wordstylesheet) ? wordstylesheet : nil,
|
113
|
-
wordstylesheet_override: defined?(wordstylesheet_override) ? wordstylesheet_override : nil,
|
114
|
-
standardstylesheet: defined?(standardstylesheet) ? standardstylesheet : nil,
|
115
|
-
header: defined?(header) ? header : nil,
|
116
|
-
wordcoverpage: defined?(wordcoverpage) ? wordcoverpage : nil,
|
117
|
-
wordintropage: defined?(wordintropage) ? wordintropage : nil,
|
118
|
-
ulstyle: defined?(ulstyle) ? ulstyle : nil,
|
119
|
-
olstyle: defined?(olstyle) ? olstyle : nil,
|
83
|
+
defined?(break_up) and
|
84
|
+
break_up = empty_attr(break_up, "break-up-urls-in-tables")
|
85
|
+
ret.merge(
|
120
86
|
datauriimage: defined?(datauriimage) ? datauriimage != "false" : nil,
|
121
|
-
|
122
|
-
doctoclevels: defined?(doctoclevels) ? doctoclevels : nil,
|
123
|
-
hierarchical_assets: defined?(hierarchical_assets) ? hierarchical_assets : nil,
|
87
|
+
hierarchical_assets: defined?(hier_assets) ? hier_assets : nil,
|
124
88
|
use_xinclude: defined?(use_xinclude) ? use_xinclude : nil,
|
125
|
-
break_up_urls_in_tables: defined?(
|
126
|
-
|
89
|
+
break_up_urls_in_tables: defined?(break_up) ? break_up : nil,
|
90
|
+
).reject { |_, val| val.nil? }
|
127
91
|
end
|
128
|
-
|
129
92
|
end
|
130
93
|
end
|
131
94
|
end
|
data/lib/metanorma/output.rb
CHANGED
@@ -7,7 +7,8 @@ module Metanorma
|
|
7
7
|
def file_path(url_path)
|
8
8
|
file_url = url_path
|
9
9
|
file_url = "file://#{url_path}" if Pathname.new(file_url).absolute?
|
10
|
-
|
10
|
+
%r{^file://}.match?(file_url) or
|
11
|
+
file_url = "file://#{Dir.pwd}/#{url_path}"
|
11
12
|
file_url
|
12
13
|
end
|
13
14
|
end
|
data/lib/metanorma/util.rb
CHANGED
data/lib/metanorma/version.rb
CHANGED
data/metanorma.gemspec
CHANGED
@@ -1,16 +1,15 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path("../lib", __FILE__)
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require "metanorma/version"
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
6
|
spec.name = "metanorma"
|
8
7
|
spec.version = Metanorma::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
8
|
+
spec.authors = ["Ribose Inc."]
|
9
|
+
spec.email = ["open.source@ribose.com"]
|
11
10
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
11
|
+
spec.summary = "Metanorma is the standard of standards; the metanorma gem allows you to create any standard document type supported by Metanorma."
|
12
|
+
spec.description = "Library to process any Metanorma standard."
|
14
13
|
spec.homepage = "https://github.com/metanorma/metanorma"
|
15
14
|
spec.license = "BSD-2-Clause"
|
16
15
|
|
@@ -19,28 +18,28 @@ Gem::Specification.new do |spec|
|
|
19
18
|
end
|
20
19
|
spec.extra_rdoc_files = %w[README.adoc CHANGELOG.adoc LICENSE.txt]
|
21
20
|
spec.bindir = "bin"
|
22
|
-
#spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
# spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
22
|
spec.require_paths = ["lib"]
|
24
|
-
spec.required_ruby_version =
|
23
|
+
spec.required_ruby_version = ">= 2.4.0"
|
25
24
|
|
26
|
-
spec.add_runtime_dependency
|
27
|
-
spec.add_runtime_dependency
|
28
|
-
spec.add_runtime_dependency
|
29
|
-
spec.add_runtime_dependency
|
30
|
-
spec.add_runtime_dependency
|
31
|
-
spec.add_runtime_dependency
|
32
|
-
spec.add_runtime_dependency
|
25
|
+
spec.add_runtime_dependency "asciidoctor"
|
26
|
+
spec.add_runtime_dependency "fontist", "~> 1.8"
|
27
|
+
spec.add_runtime_dependency "htmlentities"
|
28
|
+
spec.add_runtime_dependency "metanorma-utils", "~> 1.2.0"
|
29
|
+
spec.add_runtime_dependency "mn2pdf", "~> 1"
|
30
|
+
spec.add_runtime_dependency "nokogiri"
|
31
|
+
spec.add_runtime_dependency "pry"
|
33
32
|
|
34
|
-
# get relaton-cli to avoid circular reference with metanorma-standoc
|
35
|
-
#spec.add_dependency "relaton-cli"
|
36
|
-
#spec.add_dependency "metanorma-standoc"
|
33
|
+
# get relaton-cli to avoid circular reference with metanorma-standoc
|
34
|
+
# spec.add_dependency "relaton-cli"
|
35
|
+
# spec.add_dependency "metanorma-standoc"
|
37
36
|
|
37
|
+
spec.add_development_dependency "byebug", "~> 10.0"
|
38
|
+
spec.add_development_dependency "equivalent-xml", "~> 0.6"
|
39
|
+
spec.add_development_dependency "metanorma-iso", "~> 1.8.0"
|
38
40
|
spec.add_development_dependency "rake", "~> 13.0"
|
39
41
|
spec.add_development_dependency "rspec", "~> 3.0"
|
40
|
-
spec.add_development_dependency "byebug", "~> 10.0"
|
41
42
|
spec.add_development_dependency "rspec-command", "~> 1.0"
|
42
|
-
spec.add_development_dependency "equivalent-xml", "~> 0.6"
|
43
|
-
spec.add_development_dependency "metanorma-iso", "~> 1.7.0"
|
44
|
-
spec.add_development_dependency "sassc", "~> 2.4.0"
|
45
43
|
spec.add_development_dependency "rubocop", "~> 1.5.2"
|
44
|
+
spec.add_development_dependency "sassc", "~> 2.4.0"
|
46
45
|
end
|