metanorma 1.7.3 → 1.7.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.devel +2 -0
- data/lib/metanorma/collection.rb +13 -9
- data/lib/metanorma/collection_fileparse.rb +4 -2
- data/lib/metanorma/collection_fileprocess.rb +2 -1
- data/lib/metanorma/collection_manifest.rb +3 -8
- data/lib/metanorma/collection_render_utils.rb +7 -6
- data/lib/metanorma/collection_render_word.rb +131 -0
- data/lib/metanorma/collection_renderer.rb +31 -18
- data/lib/metanorma/compile_validate.rb +13 -7
- data/lib/metanorma/document.rb +1 -0
- data/lib/metanorma/files_lookup.rb +1 -1
- data/lib/metanorma/files_lookup_sectionsplit.rb +1 -0
- data/lib/metanorma/sectionsplit.rb +2 -1
- data/lib/metanorma/util.rb +24 -1
- data/lib/metanorma/version.rb +1 -1
- data/metanorma.gemspec +1 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a0536c88a7c8537b315bda6cfd570203898587b523a2b627db62474a7f53f37
|
4
|
+
data.tar.gz: fec598a14f605c2e9af31195e30d7c725a74477efaad572592c149dd5579c69e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e2978dcd6a5b2269465f8a710eeaf04acc6b261ba5d7848aa46be5b1b44479420e7249d22b75df423e9cee91a5be55f423e6910856d0259bbdd2000f0c5d478
|
7
|
+
data.tar.gz: e63eb96bea888b9e383f0f9f1131ea1a419f87b3c39b31c07dfdbbf91fafe7f061a3b73da8a9532c910869de1a9a0b4174828f6dcba8997c5be1129f0bbf4e95
|
data/Gemfile.devel
ADDED
data/lib/metanorma/collection.rb
CHANGED
@@ -13,10 +13,11 @@ module Metanorma
|
|
13
13
|
|
14
14
|
# @return [Array<String>] documents-inline to inject the XML into
|
15
15
|
# the collection manifest; documents-external to keeps them outside
|
16
|
-
attr_accessor :directives, :documents, :bibdatas, :coverpage
|
16
|
+
attr_accessor :directives, :documents, :bibdatas, :coverpage, :dirname
|
17
17
|
attr_accessor :disambig, :manifest
|
18
18
|
|
19
19
|
# @param file [String] path to source file
|
20
|
+
# @param dirname [String] directory of source file
|
20
21
|
# @param directives [Array<String>] documents-inline to inject the XML into
|
21
22
|
# the collection manifest; documents-external to keeps them outside
|
22
23
|
# @param bibdata [RelatonBib::BibliographicItem]
|
@@ -28,30 +29,33 @@ module Metanorma
|
|
28
29
|
# rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
29
30
|
def initialize(**args)
|
30
31
|
@file = args[:file]
|
32
|
+
@dirname = File.dirname(@file)
|
31
33
|
@directives = args[:directives] || []
|
32
34
|
@bibdata = args[:bibdata]
|
33
35
|
@manifest = args[:manifest]
|
34
36
|
@manifest.collection = self
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
c and @coverpage_style = c["coverpage-style"]
|
37
|
+
@coverpage = Util::hash_key_detect(@directives, "coverpage", @coverpage)
|
38
|
+
@coverpage_style = Util::hash_key_detect(@directives, "coverpage-style",
|
39
|
+
@coverpage_style)
|
39
40
|
@documents = args[:documents] || {}
|
40
41
|
@bibdatas = args[:documents] || {}
|
41
42
|
if @documents.any? && !@directives.include?("documents-inline")
|
42
43
|
@directives << "documents-inline"
|
43
44
|
end
|
44
|
-
@documents.merge! @manifest.documents(
|
45
|
-
@bibdatas.merge! @manifest.documents(
|
45
|
+
@documents.merge! @manifest.documents(@dirname)
|
46
|
+
@bibdatas.merge! @manifest.documents(@dirname)
|
47
|
+
@documents.transform_keys { |k| Util::key(k) }
|
48
|
+
@bibdatas.transform_keys { |k| Util::key(k) }
|
46
49
|
@prefatory = args[:prefatory]
|
47
50
|
@final = args[:final]
|
51
|
+
@compile = Metanorma::Compile.new
|
48
52
|
@log = Metanorma::Utils::Log.new
|
49
53
|
@disambig = Util::DisambigFiles.new
|
50
54
|
end
|
51
55
|
|
52
56
|
# rubocop:enable Metrics/AbcSize,Metrics/MethodLength
|
53
57
|
def clean_exit
|
54
|
-
@log.write(File.join(
|
58
|
+
@log.write(File.join(@dirname,
|
55
59
|
"#{File.basename(@file, '.*')}.err.html"))
|
56
60
|
end
|
57
61
|
|
@@ -195,7 +199,7 @@ module Metanorma
|
|
195
199
|
def content_to_xml(elm, builder)
|
196
200
|
return unless (cnt = send(elm))
|
197
201
|
|
198
|
-
|
202
|
+
@compile.load_flavor(doctype)
|
199
203
|
out = sections(dummy_header + cnt.strip)
|
200
204
|
builder.send("#{elm}-content") { |b| b << out }
|
201
205
|
end
|
@@ -8,6 +8,7 @@ module Metanorma
|
|
8
8
|
.targetfile_id(docid, relative: true, read: false,
|
9
9
|
doc: !@files.get(docid, :attachment))
|
10
10
|
dest = newbib.at("./docidentifier") || newbib.at(ns("./docidentifier"))
|
11
|
+
dest or dest = newbib.elements[-1]
|
11
12
|
dest.previous = "<uri type='citation'>#{url}</uri>"
|
12
13
|
bib.replace(newbib)
|
13
14
|
end
|
@@ -178,8 +179,9 @@ module Metanorma
|
|
178
179
|
def indirect_ref_key(schema, id, docxml)
|
179
180
|
/^#{schema}_/.match?(id) and return id
|
180
181
|
ret = "#{schema}_#{id}"
|
181
|
-
|
182
|
-
|
182
|
+
suffix = docxml.root['document_suffix']
|
183
|
+
(k = docxml.root["type"]) && k != schema && suffix and
|
184
|
+
ret = "#{ret}_#{suffix}"
|
183
185
|
ret
|
184
186
|
end
|
185
187
|
|
@@ -56,7 +56,7 @@ module Metanorma
|
|
56
56
|
# process each file in the collection
|
57
57
|
# files are held in memory, and altered as postprocessing
|
58
58
|
def files # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
59
|
-
warn "\n\n\n\n\
|
59
|
+
warn "\n\n\n\n\nRender Files: #{DateTime.now.strftime('%H:%M:%S')}"
|
60
60
|
internal_refs = locate_internal_refs
|
61
61
|
@files.keys.each_with_index do |ident, i|
|
62
62
|
i.positive? && Array(@directives).include?("bare-after-first") and
|
@@ -121,6 +121,7 @@ module Metanorma
|
|
121
121
|
|
122
122
|
# resolve file location for the target of each internal reference
|
123
123
|
def locate_internal_refs
|
124
|
+
warn "\n\n\n\n\nInternal Refs: #{DateTime.now.strftime('%H:%M:%S')}"
|
124
125
|
refs = populate_internal_refs(gather_internal_refs)
|
125
126
|
refs.each do |schema, ids|
|
126
127
|
ids.each do |id, key|
|
@@ -67,8 +67,8 @@ module Metanorma
|
|
67
67
|
def documents(dir = "")
|
68
68
|
docs = @docref.each_with_object({}) do |dr, m|
|
69
69
|
dr["fileref"] or next m
|
70
|
-
m[dr["identifier"]] = Document.parse_file(
|
71
|
-
rel_path_resolve(dir, dr["fileref"]),
|
70
|
+
m[Util::key dr["identifier"]] = Document.parse_file(
|
71
|
+
Util::rel_path_resolve(dir, dr["fileref"]),
|
72
72
|
dr["attachment"], dr["identifier"], dr["index"]
|
73
73
|
)
|
74
74
|
m
|
@@ -76,11 +76,6 @@ module Metanorma
|
|
76
76
|
@manifest.reduce(docs) { |mem, mnf| mem.merge mnf.documents(dir) }
|
77
77
|
end
|
78
78
|
|
79
|
-
def rel_path_resolve(dir, path)
|
80
|
-
p = Pathname.new(path)
|
81
|
-
p.absolute? ? path : File.join(dir, path)
|
82
|
-
end
|
83
|
-
|
84
79
|
# @param builder [Nokogiri::XML::Builder]
|
85
80
|
def to_xml(builder)
|
86
81
|
builder.manifest do |b|
|
@@ -114,7 +109,7 @@ module Metanorma
|
|
114
109
|
drf = builder.docref do |b|
|
115
110
|
b.identifier { |i| i << dr["identifier"] }
|
116
111
|
!dr["attachment"] && !dr["sectionsplit"] &&
|
117
|
-
d = @collection.bibdatas[dr["identifier"]] and
|
112
|
+
d = @collection.bibdatas[Util::key dr["identifier"]] and
|
118
113
|
b.parent.add_child(d.bibitem.to_xml(bibdata: true))
|
119
114
|
end
|
120
115
|
docref_to_xml_attrs(drf, dr)
|
@@ -20,8 +20,9 @@ module Metanorma
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def get_bibitem_docid(bib, identifier)
|
23
|
-
|
24
|
-
|
23
|
+
docid =
|
24
|
+
bib.at(ns("./docidentifier[@type = 'metanorma-collection']")) ||
|
25
|
+
bib.at(ns("./docidentifier[not(@type)]")) ||
|
25
26
|
bib.at(ns("./docidentifier"))
|
26
27
|
docid &&= docid_prefix(docid)
|
27
28
|
if @files.get(docid) then docid
|
@@ -147,10 +148,10 @@ module Metanorma
|
|
147
148
|
"final-content": isodoc_builder(@xml.at(ns("//final-content"))),
|
148
149
|
doctitle: m.at(ns("../bibdata/title"))&.text,
|
149
150
|
docnumber: m.at(ns("../bibdata/docidentifier"))&.text }.each do |k, v|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
151
|
+
v and @isodoc.meta.set(
|
152
|
+
k, v
|
153
|
+
)
|
154
|
+
end
|
154
155
|
end
|
155
156
|
|
156
157
|
def isodoc_builder(node)
|
@@ -0,0 +1,131 @@
|
|
1
|
+
module Metanorma
|
2
|
+
class CollectionRenderer
|
3
|
+
def docconv
|
4
|
+
@tempfile_cache ||= []
|
5
|
+
doctype = @doctype.to_sym
|
6
|
+
x = Asciidoctor.load nil, backend: doctype
|
7
|
+
x.converter.doc_converter(DocOptionsNode.new(@directives, @dirname))
|
8
|
+
end
|
9
|
+
|
10
|
+
def concat_extract_files(filename)
|
11
|
+
xml = Nokogiri::XML(File.read(filename, encoding: "UTF-8"), &:huge)
|
12
|
+
docs = xml.xpath(ns("//doc-container")).each_with_object([]) do |x, m|
|
13
|
+
n = Nokogiri::XML::Document.new
|
14
|
+
n.add_child(x.elements.first.remove)
|
15
|
+
m << n
|
16
|
+
end
|
17
|
+
[wrapping_doc(docs.first.dup, xml), docs]
|
18
|
+
end
|
19
|
+
|
20
|
+
def wrapping_doc(doc, xml)
|
21
|
+
doc.at(ns("//bibdata")).replace(xml.at(ns("//bibdata")).to_xml)
|
22
|
+
sections = wrapping_doc_body(doc)
|
23
|
+
wrapping_doc_intro_outro(xml, sections)
|
24
|
+
set_displayorder_wrapping_doc(doc)
|
25
|
+
end
|
26
|
+
|
27
|
+
def wrapping_doc_intro_outro(xml, sections)
|
28
|
+
p = xml.at(ns("//prefatory-content")) and
|
29
|
+
sections.previous = "<preface>#{p.children.to_xml}</preface>"
|
30
|
+
p = xml.at(ns("//final-content")) and
|
31
|
+
sections.next = "<annex>#{p.children.to_xml}</annex>"
|
32
|
+
end
|
33
|
+
|
34
|
+
def wrapping_doc_body(doc)
|
35
|
+
doc.xpath(ns("//annex | //preface | //bibliography")).each(&:remove)
|
36
|
+
s = doc.at(ns("//sections"))
|
37
|
+
repl = <<~BODY
|
38
|
+
<sections><clause id='_collection_placeholder'><p>PLACEHOLDER</p></clause></sections>
|
39
|
+
BODY
|
40
|
+
s.replace(repl)
|
41
|
+
doc.at(ns("//sections"))
|
42
|
+
end
|
43
|
+
|
44
|
+
def set_displayorder_wrapping_doc(doc)
|
45
|
+
doc.xpath(ns("//preface/* | //sections/* | //annex"))
|
46
|
+
.each_with_index do |x, i|
|
47
|
+
x["displayorder"] = i + 1
|
48
|
+
end
|
49
|
+
doc
|
50
|
+
end
|
51
|
+
|
52
|
+
SECTION_BREAK = '<p class="MsoNormal"><br clear="all" class="section"/></p>'
|
53
|
+
.freeze
|
54
|
+
DIV1 = '<div class="WordSection1"> </div>'.freeze
|
55
|
+
DIV2 = '<div class="WordSection2"> </div>'.freeze
|
56
|
+
|
57
|
+
def docconv_convert1(docs)
|
58
|
+
docs.each_with_index.with_object([]) do |(d, i), m|
|
59
|
+
conv = docconv
|
60
|
+
conv.convert_init(d.to_xml(encoding: "UTF-8"), "xxxx", false)
|
61
|
+
html = conv.postprocess_cleanup(conv.convert1(d, "xxx", "."))
|
62
|
+
@tempfile_cache += conv.tempfile_cache # hold on to the temp img files
|
63
|
+
b = Nokogiri::XML(html).at("//body")
|
64
|
+
i == docs.size - 1 or
|
65
|
+
b << '<p class="MsoNormal"><br clear="all" class="section"/></p>'
|
66
|
+
m << b.children
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def collection_coverpages(conv, docs)
|
71
|
+
conv.wordintropage and [DIV2, SECTION_BREAK].reverse.each do |s|
|
72
|
+
docs.unshift(Nokogiri::XML(s).root)
|
73
|
+
end
|
74
|
+
conv.wordcoverpage and [DIV1, SECTION_BREAK].reverse.each do |s|
|
75
|
+
docs.unshift(Nokogiri::XML(s).root)
|
76
|
+
end
|
77
|
+
docs
|
78
|
+
end
|
79
|
+
|
80
|
+
def docconv_convert(filename)
|
81
|
+
pref_file, docs = concat_extract_files(filename)
|
82
|
+
body = docconv_convert1(docs)
|
83
|
+
collection_conv = overall_docconv_converter(body)
|
84
|
+
collection_coverpages(collection_conv, body)
|
85
|
+
collection_conv.convert(filename, pref_file.to_xml, false)
|
86
|
+
end
|
87
|
+
|
88
|
+
def overall_docconv_cover(collection_conv)
|
89
|
+
p = Util::hash_key_detect(@directives, "collection-word-coverpage", nil)
|
90
|
+
collection_conv.wordcoverpage =
|
91
|
+
Util::rel_path_resolve(@dirname, p)
|
92
|
+
p = Util::hash_key_detect(@directives, "collection-word-intropage", nil)
|
93
|
+
collection_conv.wordintropage =
|
94
|
+
Util::rel_path_resolve(@dirname, p)
|
95
|
+
end
|
96
|
+
|
97
|
+
def overall_docconv_converter(body)
|
98
|
+
collection_conv = docconv
|
99
|
+
collection_conv.options[:collection_doc] = body.map(&:to_xml).join
|
100
|
+
overall_docconv_cover(collection_conv)
|
101
|
+
|
102
|
+
def collection_conv.postprocess_cleanup(result)
|
103
|
+
ret = to_xhtml(super)
|
104
|
+
b = ret.at("//div[@id = '_collection_placeholder']")
|
105
|
+
b.replace(@options[:collection_doc])
|
106
|
+
from_xhtml(ret)
|
107
|
+
end
|
108
|
+
|
109
|
+
collection_conv
|
110
|
+
end
|
111
|
+
|
112
|
+
class DocOptionsNode
|
113
|
+
def initialize(directives, dir)
|
114
|
+
@dir = dir
|
115
|
+
@wordcoverpage =
|
116
|
+
Util::hash_key_detect(directives, "document-word-coverpage",
|
117
|
+
@wordcoverpage)
|
118
|
+
@wordintropage =
|
119
|
+
Util::hash_key_detect(directives, "document-word-intropage",
|
120
|
+
@wordintropage)
|
121
|
+
end
|
122
|
+
|
123
|
+
def attr(key)
|
124
|
+
case key
|
125
|
+
when "wordcoverpage" then Util::rel_path_resolve(@dir, @wordcoverpage)
|
126
|
+
when "wordintropage" then Util::rel_path_resolve(@dir, @wordintropage)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -5,6 +5,7 @@ require_relative "fontist_utils"
|
|
5
5
|
require_relative "util"
|
6
6
|
require_relative "files_lookup"
|
7
7
|
require_relative "collection_render_utils"
|
8
|
+
require_relative "collection_render_word"
|
8
9
|
|
9
10
|
module Metanorma
|
10
11
|
# XML collection renderer
|
@@ -33,7 +34,8 @@ module Metanorma
|
|
33
34
|
@script = @xml.at("//xmlns:bibdata/xmlns:script")&.text || "Latn"
|
34
35
|
@locale = @xml.at("//xmlns:bibdata/xmlns:locale")&.text
|
35
36
|
@doctype = doctype
|
36
|
-
|
37
|
+
@compile = Compile.new
|
38
|
+
@compile.load_flavor(@doctype)
|
37
39
|
|
38
40
|
@isodoc = isodoc_create # output processor for flavour
|
39
41
|
@outdir = dir_name_cleanse(options[:output_folder])
|
@@ -45,8 +47,8 @@ module Metanorma
|
|
45
47
|
@documents = collection.documents
|
46
48
|
@bibdata = collection.documents
|
47
49
|
@directives = collection.directives
|
50
|
+
@dirname = collection.dirname
|
48
51
|
@disambig = Util::DisambigFiles.new
|
49
|
-
@compile = Compile.new
|
50
52
|
@c = HTMLEntities.new
|
51
53
|
@files_to_delete = []
|
52
54
|
@nested = options[:nested] # if false, this is the root instance of Renderer
|
@@ -61,6 +63,7 @@ module Metanorma
|
|
61
63
|
end
|
62
64
|
|
63
65
|
def flush_files
|
66
|
+
warn "\n\n\n\n\nDone: #{DateTime.now.strftime('%H:%M:%S')}"
|
64
67
|
warn @files.files_to_delete
|
65
68
|
@files.files_to_delete.each { |f| FileUtils.rm_f(f) }
|
66
69
|
@files_to_delete.each { |f| FileUtils.rm_f(f) }
|
@@ -72,31 +75,37 @@ module Metanorma
|
|
72
75
|
# @option options [Array<Symbol>] :format list of formats
|
73
76
|
# @option options [Strong] :ourput_folder output directory
|
74
77
|
def self.render(col, options = {})
|
75
|
-
folder = File.dirname col.file
|
76
78
|
warn "\n\n\n\n\nRender Init: #{DateTime.now.strftime('%H:%M:%S')}"
|
77
|
-
cr = new(col,
|
78
|
-
warn "\n\n\n\n\nRender Files: #{DateTime.now.strftime('%H:%M:%S')}"
|
79
|
+
cr = new(col, File.dirname(col.file), options)
|
79
80
|
cr.files
|
80
|
-
warn "\n\n\n\n\nConcatenate: #{DateTime.now.strftime('%H:%M:%S')}"
|
81
81
|
cr.concatenate(col, options)
|
82
|
-
|
83
|
-
cr.coverpage if options[:format]&.include?(:html)
|
84
|
-
warn "\n\n\n\n\nDone: #{DateTime.now.strftime('%H:%M:%S')}"
|
82
|
+
options[:format]&.include?(:html) and cr.coverpage
|
85
83
|
cr.flush_files
|
86
84
|
cr
|
87
85
|
end
|
88
86
|
|
89
87
|
def concatenate(col, options)
|
90
|
-
|
91
|
-
options[:format].
|
92
|
-
|
88
|
+
warn "\n\n\n\n\nConcatenate: #{DateTime.now.strftime('%H:%M:%S')}"
|
89
|
+
(options[:format] & %i(pdf doc)).empty? or
|
90
|
+
options[:format] << :presentation
|
91
|
+
concatenate_prep(col, options)
|
92
|
+
concatenate_outputs(options)
|
93
|
+
end
|
94
|
+
|
95
|
+
def concatenate_prep(col, options)
|
96
|
+
%i(xml presentation).each do |e|
|
97
|
+
options[:format].include?(e) or next
|
93
98
|
ext = e == :presentation ? "presentation.xml" : e.to_s
|
94
99
|
File.open(File.join(@outdir, "collection.#{ext}"), "w:UTF-8") do |f|
|
95
100
|
f.write(concatenate1(col.clone, e).to_xml)
|
96
101
|
end
|
97
102
|
end
|
98
|
-
|
99
|
-
|
103
|
+
end
|
104
|
+
|
105
|
+
def concatenate_outputs(options)
|
106
|
+
pres = File.join(@outdir, "collection.presentation.xml")
|
107
|
+
options[:format].include?(:pdf) and pdfconv.convert(pres)
|
108
|
+
options[:format].include?(:doc) and docconv_convert(pres)
|
100
109
|
end
|
101
110
|
|
102
111
|
def concatenate1(out, ext)
|
@@ -104,8 +113,7 @@ module Metanorma
|
|
104
113
|
out.bibdatas.each_key do |ident|
|
105
114
|
id = @isodoc.docid_prefix(nil, ident.dup)
|
106
115
|
@files.get(id, :attachment) || @files.get(id, :outputs).nil? and next
|
107
|
-
|
108
|
-
out.documents[id] =
|
116
|
+
out.documents[Util::key id] =
|
109
117
|
Metanorma::Document.raw_file(@files.get(id, :outputs)[ext])
|
110
118
|
end
|
111
119
|
out
|
@@ -127,6 +135,7 @@ module Metanorma
|
|
127
135
|
# collection manifest
|
128
136
|
def coverpage
|
129
137
|
@coverpage or return
|
138
|
+
warn "\n\n\n\n\nCoverpage: #{DateTime.now.strftime('%H:%M:%S')}"
|
130
139
|
File.open(File.join(@outdir, "index.html"), "w:UTF-8") do |f|
|
131
140
|
f.write @isodoc.populate_template(File.read(@coverpage))
|
132
141
|
end
|
@@ -153,8 +162,7 @@ module Metanorma
|
|
153
162
|
# @param builder [Nokogiri::XML::Builder]
|
154
163
|
def docrefs(elm, builder)
|
155
164
|
elm.xpath(ns("./docref[@index = 'true']")).each do |d|
|
156
|
-
ident = d
|
157
|
-
ident = @c.decode(@isodoc.docid_prefix(nil, ident))
|
165
|
+
ident = docref_ident(d)
|
158
166
|
builder.li do |li|
|
159
167
|
li.a href: index_link(d, ident) do |a|
|
160
168
|
a << ident.split(/([<>&])/).map do |x|
|
@@ -165,6 +173,11 @@ module Metanorma
|
|
165
173
|
end
|
166
174
|
end
|
167
175
|
|
176
|
+
def docref_ident(docref)
|
177
|
+
ident = docref.at(ns("./identifier")).children.to_xml
|
178
|
+
@c.decode(@isodoc.docid_prefix(nil, ident))
|
179
|
+
end
|
180
|
+
|
168
181
|
def index_link(docref, ident)
|
169
182
|
if docref["fileref"]
|
170
183
|
@files.get(ident, :out_path).sub(/\.xml$/, ".html")
|
@@ -21,19 +21,25 @@ module Metanorma
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
private
|
25
|
-
|
26
24
|
def load_flavor(stdtype)
|
27
|
-
|
28
|
-
|
25
|
+
stdtype = stdtype.to_sym
|
26
|
+
flavor = stdtype2flavor(stdtype)
|
27
|
+
@registry.supported_backends.include? stdtype or
|
29
28
|
Util.log("[metanorma] Info: Loading `#{flavor}` gem "\
|
30
29
|
"for standard type `#{stdtype}`.", :info)
|
31
|
-
end
|
32
30
|
require_flavor(flavor)
|
33
|
-
|
31
|
+
@registry.supported_backends.include? stdtype or
|
34
32
|
Util.log("[metanorma] Error: The `#{flavor}` gem does not "\
|
35
33
|
"support the standard type #{stdtype}. Exiting.", :fatal)
|
36
|
-
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
STDTYPE2FLAVOR = { plateau: "jis" }.freeze
|
39
|
+
|
40
|
+
def stdtype2flavor(stdtype)
|
41
|
+
flavor = STDTYPE2FLAVOR[stdtype] || stdtype
|
42
|
+
"metanorma-#{flavor}"
|
37
43
|
end
|
38
44
|
|
39
45
|
def require_flavor(flavor)
|
data/lib/metanorma/document.rb
CHANGED
@@ -33,6 +33,7 @@ module Metanorma
|
|
33
33
|
|
34
34
|
# raw XML file, can be used to put in entire file instead of just bibitem
|
35
35
|
def raw_file(filename)
|
36
|
+
require "debug"; binding.b if filename.nil?
|
36
37
|
doc = Nokogiri::XML(File.read(filename, encoding: "UTF-8")) do |config|
|
37
38
|
config.huge
|
38
39
|
end
|
@@ -67,7 +67,7 @@ module Metanorma
|
|
67
67
|
out = ref["attachment"] ? ref["fileref"] : File.basename(ref["fileref"])
|
68
68
|
out1 = @disambig.source2dest_filename(out)
|
69
69
|
ret = if ref["fileref"]
|
70
|
-
{ type: "fileref", ref: @documents[identifier].file,
|
70
|
+
{ type: "fileref", ref: @documents[Util::key identifier].file,
|
71
71
|
rel_path: ref["fileref"],
|
72
72
|
out_path: out1 } # @disambig.source2dest_filename(out) }
|
73
73
|
else { type: "id", ref: ref["id"] }
|
@@ -206,7 +206,8 @@ module Metanorma
|
|
206
206
|
output_folder: "#{ident}_collection",
|
207
207
|
format: %i(html),
|
208
208
|
coverpage: File.join(dir, "cover.html")).coverpage
|
209
|
-
filename = one_doc_coll ? "#{ident}_index.html" : "index.html"
|
209
|
+
#filename = one_doc_coll ? "#{ident}_index.html" : "index.html"
|
210
|
+
filename = "#{ident}_index.html"
|
210
211
|
FileUtils.mv "#{ident}_collection/index.html", File.join(dir, filename)
|
211
212
|
FileUtils.rm_rf "#{ident}_collection"
|
212
213
|
filename
|
data/lib/metanorma/util.rb
CHANGED
@@ -40,7 +40,12 @@ module Metanorma
|
|
40
40
|
|
41
41
|
def self.gather_bibitems(xml)
|
42
42
|
xml.xpath("//xmlns:bibitem[@id]").each_with_object({}) do |b, m|
|
43
|
-
m[b["id"]]
|
43
|
+
if m[b["id"]]
|
44
|
+
b.remove
|
45
|
+
next # we can't update duplicate bibitem, processing updates wrong one
|
46
|
+
else
|
47
|
+
m[b["id"]] = b
|
48
|
+
end
|
44
49
|
end
|
45
50
|
end
|
46
51
|
|
@@ -69,6 +74,24 @@ module Metanorma
|
|
69
74
|
end
|
70
75
|
end
|
71
76
|
|
77
|
+
def self.hash_key_detect(directives, key, variable)
|
78
|
+
c = directives.detect { |x| x.is_a?(Hash) && x.has_key?(key) } or
|
79
|
+
return variable
|
80
|
+
c[key]
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.rel_path_resolve(dir, path)
|
84
|
+
path.nil? and return path
|
85
|
+
path.empty? and return path
|
86
|
+
p = Pathname.new(path)
|
87
|
+
p.absolute? ? path : File.join(dir, path)
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.key(ident)
|
91
|
+
@c ||= HTMLEntities.new
|
92
|
+
@c.decode(ident).gsub(/(\p{Zs})+/, " ")
|
93
|
+
end
|
94
|
+
|
72
95
|
class DisambigFiles
|
73
96
|
def initialize
|
74
97
|
@seen_filenames = []
|
data/lib/metanorma/version.rb
CHANGED
data/metanorma.gemspec
CHANGED
@@ -44,4 +44,5 @@ Gem::Specification.new do |spec|
|
|
44
44
|
spec.add_development_dependency "rspec-command", "~> 1.0"
|
45
45
|
spec.add_development_dependency "rubocop", "~> 1.5.2"
|
46
46
|
spec.add_development_dependency "sassc", "~> 2.4.0"
|
47
|
+
spec.add_development_dependency "simplecov", "~> 0.15"
|
47
48
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metanorma
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.7.
|
4
|
+
version: 1.7.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|
@@ -234,6 +234,20 @@ dependencies:
|
|
234
234
|
- - "~>"
|
235
235
|
- !ruby/object:Gem::Version
|
236
236
|
version: 2.4.0
|
237
|
+
- !ruby/object:Gem::Dependency
|
238
|
+
name: simplecov
|
239
|
+
requirement: !ruby/object:Gem::Requirement
|
240
|
+
requirements:
|
241
|
+
- - "~>"
|
242
|
+
- !ruby/object:Gem::Version
|
243
|
+
version: '0.15'
|
244
|
+
type: :development
|
245
|
+
prerelease: false
|
246
|
+
version_requirements: !ruby/object:Gem::Requirement
|
247
|
+
requirements:
|
248
|
+
- - "~>"
|
249
|
+
- !ruby/object:Gem::Version
|
250
|
+
version: '0.15'
|
237
251
|
description: Library to process any Metanorma standard.
|
238
252
|
email:
|
239
253
|
- open.source@ribose.com
|
@@ -251,6 +265,7 @@ files:
|
|
251
265
|
- CHANGELOG.adoc
|
252
266
|
- CODE_OF_CONDUCT.md
|
253
267
|
- Gemfile
|
268
|
+
- Gemfile.devel
|
254
269
|
- LICENSE.txt
|
255
270
|
- README.adoc
|
256
271
|
- lib/metanorma.rb
|
@@ -261,6 +276,7 @@ files:
|
|
261
276
|
- lib/metanorma/collection_fileprocess.rb
|
262
277
|
- lib/metanorma/collection_manifest.rb
|
263
278
|
- lib/metanorma/collection_render_utils.rb
|
279
|
+
- lib/metanorma/collection_render_word.rb
|
264
280
|
- lib/metanorma/collection_renderer.rb
|
265
281
|
- lib/metanorma/compile.rb
|
266
282
|
- lib/metanorma/compile_options.rb
|