metanorma 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/macos.yml +10 -2
- data/.github/workflows/ubuntu.yml +13 -3
- data/.github/workflows/windows.yml +10 -2
- data/.gitignore +3 -0
- data/lib/metanorma/compile.rb +57 -18
- data/lib/metanorma/input/asciidoc.rb +15 -2
- data/lib/metanorma/output.rb +1 -0
- data/lib/metanorma/output/pdf.rb +2 -3
- data/lib/metanorma/output/utils.rb +16 -0
- data/lib/metanorma/output/xslfo.rb +15 -0
- data/lib/metanorma/processor.rb +10 -1
- data/lib/metanorma/registry.rb +1 -1
- data/lib/metanorma/version.rb +1 -1
- data/metanorma.gemspec +2 -1
- metadata +24 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 315077d28cfe3e052808e9890d2f3c3f571b7350788e6d6423be1746e5559ef4
|
4
|
+
data.tar.gz: f8a9c7d3055af8a687fe8df52b725b1fadbceb8920bef8ea449af5cde0aafb6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab023b366ca20c7d4fe3785e00698d2ccd868c0d119b0df74a5ba52e11f4bd69b884b18fea2b820838708c3bae5516be911c9e82de8302b6ade8cf52c99c36b4
|
7
|
+
data.tar.gz: 3f3520b67f58296be755b0e8b2b9cfb0e98611e214f73e131e1eccde7b74dfd611db1f476cee84d5071f6ef0c1b7b801ed9874e7261697b52fb7bf288282c57d
|
data/.github/workflows/macos.yml
CHANGED
@@ -6,15 +6,23 @@ on:
|
|
6
6
|
push:
|
7
7
|
branches: [ master ]
|
8
8
|
pull_request:
|
9
|
+
paths-ignore:
|
10
|
+
- .github/workflows/ubuntu.yml
|
11
|
+
- .github/workflows/windows.yml
|
9
12
|
|
10
13
|
jobs:
|
11
14
|
test-macos:
|
12
15
|
name: Test on Ruby ${{ matrix.ruby }} macOS
|
13
16
|
runs-on: macos-latest
|
17
|
+
continue-on-error: ${{ matrix.experimental }}
|
14
18
|
strategy:
|
15
19
|
fail-fast: false
|
16
20
|
matrix:
|
17
21
|
ruby: [ '2.6', '2.5', '2.4' ]
|
22
|
+
experimental: [false]
|
23
|
+
include:
|
24
|
+
- ruby: '2.7'
|
25
|
+
experimental: true
|
18
26
|
steps:
|
19
27
|
- uses: actions/checkout@master
|
20
28
|
- name: Use Ruby
|
@@ -29,10 +37,10 @@ jobs:
|
|
29
37
|
- name: Use Node
|
30
38
|
uses: actions/setup-node@v1
|
31
39
|
with:
|
32
|
-
node-version: '
|
40
|
+
node-version: '12'
|
33
41
|
- name: Install Puppeteer
|
34
42
|
run: |
|
35
|
-
npm install -g puppeteer
|
43
|
+
npm install -g puppeteer@3.0.1
|
36
44
|
- name: Run specs
|
37
45
|
run: |
|
38
46
|
bundle exec rake
|
@@ -6,15 +6,23 @@ on:
|
|
6
6
|
push:
|
7
7
|
branches: [ master ]
|
8
8
|
pull_request:
|
9
|
+
paths-ignore:
|
10
|
+
- .github/workflows/macos.yml
|
11
|
+
- .github/workflows/windows.yml
|
9
12
|
|
10
13
|
jobs:
|
11
14
|
test-linux:
|
12
15
|
name: Test on Ruby ${{ matrix.ruby }} Ubuntu
|
13
16
|
runs-on: ubuntu-latest
|
17
|
+
continue-on-error: ${{ matrix.experimental }}
|
14
18
|
strategy:
|
15
19
|
fail-fast: false
|
16
20
|
matrix:
|
17
21
|
ruby: [ '2.6', '2.5', '2.4' ]
|
22
|
+
experimental: [false]
|
23
|
+
include:
|
24
|
+
- ruby: '2.7'
|
25
|
+
experimental: true
|
18
26
|
steps:
|
19
27
|
- uses: actions/checkout@master
|
20
28
|
- name: Use Ruby
|
@@ -29,15 +37,17 @@ jobs:
|
|
29
37
|
- name: Use Node
|
30
38
|
uses: actions/setup-node@v1
|
31
39
|
with:
|
32
|
-
node-version: '
|
40
|
+
node-version: '12'
|
33
41
|
- name: Install Puppeteer
|
34
42
|
run: |
|
35
|
-
|
43
|
+
sudo apt-get update
|
44
|
+
sudo apt-get install libgbm1
|
45
|
+
npm install -g puppeteer@3.0.1
|
36
46
|
- name: Run specs
|
37
47
|
run: |
|
38
48
|
bundle exec rake
|
39
49
|
- name: Trigger dependent repositories
|
40
|
-
if: github.ref == 'refs/heads/master'
|
50
|
+
if: github.ref == 'refs/heads/master' && matrix.ruby == '2.6'
|
41
51
|
env:
|
42
52
|
GH_USERNAME: ${{ secrets.PAT_USERNAME }}
|
43
53
|
GH_ACCESS_TOKEN: ${{ secrets.PAT_TOKEN }}
|
@@ -6,15 +6,23 @@ on:
|
|
6
6
|
push:
|
7
7
|
branches: [ master ]
|
8
8
|
pull_request:
|
9
|
+
paths-ignore:
|
10
|
+
- .github/workflows/macos.yml
|
11
|
+
- .github/workflows/ubuntu.yml
|
9
12
|
|
10
13
|
jobs:
|
11
14
|
test-windows:
|
12
15
|
name: Test on Ruby ${{ matrix.ruby }} Windows
|
13
16
|
runs-on: windows-latest
|
17
|
+
continue-on-error: ${{ matrix.experimental }}
|
14
18
|
strategy:
|
15
19
|
fail-fast: false
|
16
20
|
matrix:
|
17
21
|
ruby: [ '2.6', '2.5', '2.4' ]
|
22
|
+
experimental: [false]
|
23
|
+
include:
|
24
|
+
- ruby: '2.7'
|
25
|
+
experimental: true
|
18
26
|
steps:
|
19
27
|
- uses: actions/checkout@master
|
20
28
|
- name: Use Ruby
|
@@ -31,10 +39,10 @@ jobs:
|
|
31
39
|
- name: Use Node
|
32
40
|
uses: actions/setup-node@v1
|
33
41
|
with:
|
34
|
-
node-version: '
|
42
|
+
node-version: '12'
|
35
43
|
- name: Install Puppeteer
|
36
44
|
run: |
|
37
|
-
npm install -g puppeteer
|
45
|
+
npm install -g puppeteer@3.0.1
|
38
46
|
- name: Run specs
|
39
47
|
run: |
|
40
48
|
bundle exec rake
|
data/.gitignore
CHANGED
data/lib/metanorma/compile.rb
CHANGED
@@ -4,14 +4,18 @@ require "htmlentities"
|
|
4
4
|
|
5
5
|
module Metanorma
|
6
6
|
class Compile
|
7
|
+
# @return [Array<String>]
|
8
|
+
attr_reader :errors
|
9
|
+
|
7
10
|
def initialize
|
8
11
|
@registry = Metanorma::Registry.instance
|
12
|
+
@errors = []
|
9
13
|
end
|
10
14
|
|
11
15
|
def compile(filename, options = {})
|
16
|
+
require_libraries(options)
|
12
17
|
options = options_extract(filename, options)
|
13
18
|
validate(options) or return nil
|
14
|
-
require_libraries(options)
|
15
19
|
@processor = @registry.find_processor(options[:type].to_sym)
|
16
20
|
extensions = get_extensions(options) or return nil
|
17
21
|
(file, isodoc = process_input(filename, options)) or return nil
|
@@ -89,21 +93,29 @@ module Metanorma
|
|
89
93
|
end
|
90
94
|
|
91
95
|
def get_extensions(options)
|
92
|
-
options[:extension_keys] ||= @processor.output_formats.
|
93
|
-
memo << k
|
96
|
+
options[:extension_keys] ||= @processor.output_formats.reduce([]) do |memo, (k, _)|
|
97
|
+
memo << k
|
94
98
|
end
|
95
|
-
extensions = options[:extension_keys].
|
96
|
-
@processor.output_formats[e]
|
97
|
-
|
98
|
-
|
99
|
+
extensions = options[:extension_keys].reduce([]) do |memo, e|
|
100
|
+
if @processor.output_formats[e]
|
101
|
+
memo << e
|
102
|
+
else
|
103
|
+
message = "[metanorma] Error: #{e} format is not supported for this standard."
|
104
|
+
@errors << message
|
105
|
+
Util.log(message, :error)
|
106
|
+
memo
|
107
|
+
end
|
99
108
|
end
|
109
|
+
if !extensions.include?(:presentation) and extensions.any? { |e| @processor.use_presentation_xml(e) }
|
110
|
+
extensions << :presentation
|
111
|
+
end
|
100
112
|
extensions
|
101
113
|
end
|
102
114
|
|
103
115
|
def process_input(filename, options)
|
104
116
|
case extname = File.extname(filename)
|
105
117
|
when ".adoc"
|
106
|
-
Util.log("[metanorma] Processing:
|
118
|
+
Util.log("[metanorma] Processing: AsciiDoc input.", :info)
|
107
119
|
file = read_file(filename)
|
108
120
|
options[:asciimath] and
|
109
121
|
file.sub!(/^(=[^\n]+\n)/, "\\1:mn-keep-asciimath:\n")
|
@@ -195,24 +207,51 @@ module Metanorma
|
|
195
207
|
end
|
196
208
|
end
|
197
209
|
|
210
|
+
# dependency ordering
|
211
|
+
def sort_extensions_execution(ext)
|
212
|
+
case ext
|
213
|
+
when :xml then 0
|
214
|
+
when :rxl then 1
|
215
|
+
when :presentation then 2
|
216
|
+
else
|
217
|
+
99
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
def wrap_html(options, file_extension, outfilename)
|
222
|
+
if options[:wrapper] and /html$/.match file_extension
|
223
|
+
outfilename = outfilename.sub(/\.html$/, "")
|
224
|
+
FileUtils.mkdir_p outfilename
|
225
|
+
FileUtils.mv "#{outfilename}.html", outfilename
|
226
|
+
FileUtils.mv "#{outfilename}_images", outfilename, force: true
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
# isodoc is Raw Metanorma XML
|
198
231
|
def process_extensions(extensions, file, isodoc, options)
|
199
|
-
|
200
|
-
|
201
|
-
|
232
|
+
xml_name = options[:filename].sub(/\.[^.]+$/, ".xml")
|
233
|
+
presentationxml_name = options[:filename].sub(/\.[^.]+$/, ".presentation.xml")
|
234
|
+
isodoc_options = @processor.extract_options(file)
|
235
|
+
isodoc_options[:datauriimage] = true if options[:datauriimage]
|
236
|
+
extensions.sort do |a, b|
|
237
|
+
sort_extensions_execution(a) <=> sort_extensions_execution(b)
|
238
|
+
end.each do |ext|
|
202
239
|
file_extension = @processor.output_formats[ext]
|
203
240
|
outfilename = options[:filename].sub(/\.[^.]+$/, ".#{file_extension}")
|
204
241
|
if ext == :rxl
|
205
242
|
options[:relaton] = outfilename
|
206
243
|
relaton_export(isodoc, options)
|
207
244
|
else
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
245
|
+
begin
|
246
|
+
#require "byebug"; byebug
|
247
|
+
@processor.use_presentation_xml(ext) ?
|
248
|
+
@processor.output(nil, presentationxml_name, outfilename, ext, isodoc_options) :
|
249
|
+
@processor.output(isodoc, xml_name, outfilename, ext, isodoc_options)
|
250
|
+
rescue StandardError => e
|
251
|
+
puts e.message
|
252
|
+
end
|
215
253
|
end
|
254
|
+
wrap_html(options, file_extension, outfilename)
|
216
255
|
end
|
217
256
|
end
|
218
257
|
end
|
@@ -34,6 +34,10 @@ module Metanorma
|
|
34
34
|
}.reject { |_, val| val.nil? }
|
35
35
|
end
|
36
36
|
|
37
|
+
def empty_attr(attr, name)
|
38
|
+
attr&.sub(/^#{name}:\s*$/, "#{name}: true")&.sub(/^#{name}:\s+/, "")
|
39
|
+
end
|
40
|
+
|
37
41
|
def extract_options(file)
|
38
42
|
headerextract = file.sub(/\n\n.*$/m, "\n")
|
39
43
|
|
@@ -58,8 +62,16 @@ module Metanorma
|
|
58
62
|
/\n:data-uri-image: (?<datauriimage>[^\n]+)\n/ =~ headerextract
|
59
63
|
/\n:htmltoclevels: (?<htmltoclevels>[^\n]+)\n/ =~ headerextract
|
60
64
|
/\n:doctoclevels: (?<doctoclevels>[^\n]+)\n/ =~ headerextract
|
61
|
-
/\n:hierarchical-assets:
|
62
|
-
/\n:use-xinclude:
|
65
|
+
/\n:(?<hierarchical_assets>hierarchical-assets:[^\n]*)\n/ =~ headerextract
|
66
|
+
/\n:(?<use_xinclude>use-xinclude:[^\n]*)\n/ =~ headerextract
|
67
|
+
/\n:(?<break_up_urls_in_tables>break-up-urls-in-tables:[^\n]*)\n/ =~ headerextract
|
68
|
+
|
69
|
+
defined?(hierarchical_assets) and
|
70
|
+
hierarchical_assets = empty_attr(hierarchical_assets, "hierarchical-assets")
|
71
|
+
defined?(use_xinclude) and
|
72
|
+
use_xinclude = empty_attr(use_xinclude, "use-xinclude")
|
73
|
+
defined?(break_up_urls_in_tables) and
|
74
|
+
break_up_urls_in_tables = empty_attr(break_up_urls_in_tables, "break-up-urls-in-tables")
|
63
75
|
{
|
64
76
|
script: defined?(script) ? script : nil,
|
65
77
|
bodyfont: defined?(bodyfont) ? bodyfont : nil,
|
@@ -84,6 +96,7 @@ module Metanorma
|
|
84
96
|
doctoclevels: defined?(doctoclevels) ? doctoclevels : nil,
|
85
97
|
hierarchical_assets: defined?(hierarchical_assets) ? hierarchical_assets : nil,
|
86
98
|
use_xinclude: defined?(use_xinclude) ? use_xinclude : nil,
|
99
|
+
break_up_urls_in_tables: defined?(break_up_urls_in_tables) ? break_up_urls_in_tables : nil,
|
87
100
|
}.reject { |_, val| val.nil? }
|
88
101
|
end
|
89
102
|
|
data/lib/metanorma/output.rb
CHANGED
data/lib/metanorma/output/pdf.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "open3"
|
2
|
+
require_relative "./utils.rb"
|
2
3
|
require "pathname"
|
3
4
|
require "shellwords"
|
4
5
|
|
@@ -7,9 +8,7 @@ module Metanorma
|
|
7
8
|
class Pdf < Base
|
8
9
|
|
9
10
|
def convert(url_path, output_path)
|
10
|
-
file_url = url_path
|
11
|
-
file_url = "file://#{url_path}" if Pathname.new(file_url).absolute?
|
12
|
-
file_url = "file://#{Dir.pwd}/#{url_path}" unless %r{^file://} =~ file_url
|
11
|
+
file_url = Utils::file_path(url_path)
|
13
12
|
pdfjs = File.join(File.dirname(__FILE__), "../../../bin/metanorma-pdf.js")
|
14
13
|
|
15
14
|
node_path = ENV["NODE_PATH"] || `npm root --quiet -g`.strip
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
3
|
+
module Metanorma
|
4
|
+
module Output
|
5
|
+
module Utils
|
6
|
+
class << self
|
7
|
+
def file_path(url_path)
|
8
|
+
file_url = url_path
|
9
|
+
file_url = "file://#{url_path}" if Pathname.new(file_url).absolute?
|
10
|
+
file_url = "file://#{Dir.pwd}/#{url_path}" unless %r{^file://} =~ file_url
|
11
|
+
file_url
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'mn2pdf'
|
2
|
+
require_relative "./utils.rb"
|
3
|
+
|
4
|
+
module Metanorma
|
5
|
+
module Output
|
6
|
+
class XslfoPdf < Base
|
7
|
+
def convert(url_path, output_path, xsl_stylesheet)
|
8
|
+
return if url_path.nil? || output_path.nil? || xsl_stylesheet.nil?
|
9
|
+
|
10
|
+
Mn2pdf.convert(url_path, output_path, xsl_stylesheet)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
data/lib/metanorma/processor.rb
CHANGED
@@ -15,6 +15,7 @@ module Metanorma
|
|
15
15
|
def output_formats
|
16
16
|
{
|
17
17
|
xml: "xml",
|
18
|
+
presentation: "presentation.xml",
|
18
19
|
rxl: "rxl"
|
19
20
|
}
|
20
21
|
end
|
@@ -23,7 +24,15 @@ module Metanorma
|
|
23
24
|
raise "This is an abstract class!"
|
24
25
|
end
|
25
26
|
|
26
|
-
def
|
27
|
+
def use_presentation_xml(ext)
|
28
|
+
case ext
|
29
|
+
when :html, :doc, :pdf then true
|
30
|
+
else
|
31
|
+
false
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def output(isodoc_node, inname, outname, format, options={})
|
27
36
|
File.open(outname, "w:UTF-8") { |f| f.write(isodoc_node) }
|
28
37
|
end
|
29
38
|
|
data/lib/metanorma/registry.rb
CHANGED
data/lib/metanorma/version.rb
CHANGED
data/metanorma.gemspec
CHANGED
@@ -26,11 +26,12 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_runtime_dependency 'asciidoctor'
|
27
27
|
spec.add_runtime_dependency 'htmlentities'
|
28
28
|
spec.add_runtime_dependency 'nokogiri'
|
29
|
+
spec.add_runtime_dependency 'mn2pdf', "~> 1"
|
29
30
|
|
30
31
|
spec.add_development_dependency "rake", "~> 12.0"
|
31
32
|
spec.add_development_dependency "rspec", "~> 3.0"
|
32
33
|
spec.add_development_dependency "byebug", "~> 10.0"
|
33
34
|
spec.add_development_dependency "rspec-command", "~> 1.0"
|
34
35
|
spec.add_development_dependency "equivalent-xml", "~> 0.6"
|
35
|
-
spec.add_development_dependency "metanorma-iso", "~> 1.
|
36
|
+
spec.add_development_dependency "metanorma-iso", "~> 1.4"
|
36
37
|
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.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mn2pdf
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rake
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,14 +142,14 @@ dependencies:
|
|
128
142
|
requirements:
|
129
143
|
- - "~>"
|
130
144
|
- !ruby/object:Gem::Version
|
131
|
-
version: '1.
|
145
|
+
version: '1.4'
|
132
146
|
type: :development
|
133
147
|
prerelease: false
|
134
148
|
version_requirements: !ruby/object:Gem::Requirement
|
135
149
|
requirements:
|
136
150
|
- - "~>"
|
137
151
|
- !ruby/object:Gem::Version
|
138
|
-
version: '1.
|
152
|
+
version: '1.4'
|
139
153
|
description: Library to process any Metanorma standard.
|
140
154
|
email:
|
141
155
|
- open.source@ribose.com
|
@@ -177,6 +191,8 @@ files:
|
|
177
191
|
- lib/metanorma/output.rb
|
178
192
|
- lib/metanorma/output/base.rb
|
179
193
|
- lib/metanorma/output/pdf.rb
|
194
|
+
- lib/metanorma/output/utils.rb
|
195
|
+
- lib/metanorma/output/xslfo.rb
|
180
196
|
- lib/metanorma/processor.rb
|
181
197
|
- lib/metanorma/registry.rb
|
182
198
|
- lib/metanorma/util.rb
|
@@ -186,7 +202,7 @@ homepage: https://github.com/metanorma/metanorma
|
|
186
202
|
licenses:
|
187
203
|
- BSD-2-Clause
|
188
204
|
metadata: {}
|
189
|
-
post_install_message:
|
205
|
+
post_install_message:
|
190
206
|
rdoc_options: []
|
191
207
|
require_paths:
|
192
208
|
- lib
|
@@ -201,9 +217,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
201
217
|
- !ruby/object:Gem::Version
|
202
218
|
version: '0'
|
203
219
|
requirements: []
|
204
|
-
|
205
|
-
|
206
|
-
signing_key:
|
220
|
+
rubygems_version: 3.0.3
|
221
|
+
signing_key:
|
207
222
|
specification_version: 4
|
208
223
|
summary: Metanorma is the standard of standards; the metanorma gem allows you to create
|
209
224
|
any standard document type supported by Metanorma.
|