metanorma 1.0.3 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 17965bd6b4a4f5f6bc620947633b3286e938812e0fab3a8e71b92eb8651120a8
4
- data.tar.gz: ea9f2b8b5db24dff0c95351747daf35d3de9c7dbe010657e2bc5eae655fc1c78
3
+ metadata.gz: 11c17884b5c38b4bc7b7ada32496534008bc38e6748d5b96cf67c70048054f9d
4
+ data.tar.gz: 0a9339c045590799855c9e0b50729c486901ac562300fdba69b1f9285fc8b6f0
5
5
  SHA512:
6
- metadata.gz: 9afa1bd9a2b75a8d7fc409899220b7a3460fabfebd739aa0263f557d55d93f27deb8dc1bd96fa4d6f57b23a9200510e239f2c33b79678d48e5b9eab41e783f7c
7
- data.tar.gz: 7e787898c91da56beb6da5fa575c1e0b2c988265e88d42f835a5b281f0894f3dfa83f42c0c5011a6436b6bc0b9ef169ef9906bfdb88896da3426ebd2b3cc5c54
6
+ metadata.gz: 50a11067a41ac75ebabdb6914383ec36820332f0a74ec6fe54b4075da613949aab3a4ad041c07ae210987aa03207dfdb4b253af6e00ff5c30fed9e82682ae621
7
+ data.tar.gz: 0b2eaf2a627b6fc3b359a51043ebee36784eae974e8b1a6bf75dc2fbdacb5229975131c37bb579dcf8efdb962605a4d73aa6f4e36dec4e2a6595425867e5ebc8
@@ -6,33 +6,33 @@ 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
21
29
  uses: actions/setup-ruby@v1
22
30
  with:
23
31
  ruby-version: ${{ matrix.ruby }}
24
- architecture: 'x64'
25
32
  - name: Update gems
26
33
  run: |
27
34
  sudo gem install bundler --force
28
35
  bundle install --jobs 4 --retry 3
29
- - name: Use Node
30
- uses: actions/setup-node@v1
31
- with:
32
- node-version: '12'
33
- - name: Install Puppeteer
34
- run: |
35
- npm install -g puppeteer@3.0.0
36
36
  - name: Run specs
37
37
  run: |
38
38
  bundle exec rake
@@ -5,46 +5,52 @@ name: ubuntu
5
5
  on:
6
6
  push:
7
7
  branches: [ master ]
8
+ tags:
9
+ - '*'
8
10
  pull_request:
11
+ paths-ignore:
12
+ - .github/workflows/macos.yml
13
+ - .github/workflows/windows.yml
9
14
 
10
15
  jobs:
11
16
  test-linux:
12
17
  name: Test on Ruby ${{ matrix.ruby }} Ubuntu
13
18
  runs-on: ubuntu-latest
19
+ continue-on-error: ${{ matrix.experimental }}
14
20
  strategy:
15
21
  fail-fast: false
16
22
  matrix:
17
23
  ruby: [ '2.6', '2.5', '2.4' ]
24
+ experimental: [false]
25
+ include:
26
+ - ruby: '2.7'
27
+ experimental: true
18
28
  steps:
19
29
  - uses: actions/checkout@master
20
30
  - name: Use Ruby
21
31
  uses: actions/setup-ruby@v1
22
32
  with:
23
33
  ruby-version: ${{ matrix.ruby }}
24
- architecture: 'x64'
25
34
  - name: Update gems
26
35
  run: |
27
36
  gem install bundler
28
37
  bundle install --jobs 4 --retry 3
29
- - name: Use Node
30
- uses: actions/setup-node@v1
31
- with:
32
- node-version: '12'
33
- - name: Install Puppeteer
34
- run: |
35
- npm install -g puppeteer@3.0.0
36
38
  - name: Run specs
37
39
  run: |
38
40
  bundle exec rake
39
- - name: Trigger dependent repositories
40
- if: github.ref == 'refs/heads/master'
41
+ - name: Trigger repositories
42
+ if: matrix.ruby == '2.6'
41
43
  env:
42
- GH_USERNAME: ${{ secrets.PAT_USERNAME }}
43
- GH_ACCESS_TOKEN: ${{ secrets.PAT_TOKEN }}
44
+ GH_USERNAME: metanorma-ci
45
+ GH_ACCESS_TOKEN: ${{ secrets.METANORMA_CI_PAT_TOKEN }}
44
46
  run: |
45
47
  curl -LO --retry 3 https://raw.githubusercontent.com/metanorma/metanorma-build-scripts/master/trigger-gh-actions.sh
46
48
  [[ -f ".github/workflows/dependent_repos.env" ]] && source .github/workflows/dependent_repos.env
47
- for repo in $DEPENDENT_REPOS
49
+ CLIENT_PAYLOAD=$(cat <<EOF
50
+ "{ "ref": "${GITHUB_REF}", "repo": "${GITHUB_REPOSITORY}" }"
51
+ EOF
52
+ )
53
+ for repo in $REPOS
48
54
  do
49
- sh trigger-gh-actions.sh $ORGANISATION $repo $GH_USERNAME $GH_ACCESS_TOKEN $GITHUB_REPOSITORY
55
+ sh trigger-gh-actions.sh $ORGANISATION $repo $GH_USERNAME $GH_ACCESS_TOKEN $GITHUB_REPOSITORY "$CLIENT_PAYLOAD"
50
56
  done
@@ -6,35 +6,35 @@ 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
21
29
  uses: actions/setup-ruby@v1
22
30
  with:
23
31
  ruby-version: ${{ matrix.ruby }}
24
- architecture: 'x64'
25
32
  - name: Update gems
26
33
  shell: pwsh
27
34
  run: |
28
35
  gem install bundler
29
36
  bundle config --local path vendor/bundle
30
37
  bundle install --jobs 4 --retry 3
31
- - name: Use Node
32
- uses: actions/setup-node@v1
33
- with:
34
- node-version: '12'
35
- - name: Install Puppeteer
36
- run: |
37
- npm install -g puppeteer@3.0.0
38
38
  - name: Run specs
39
39
  run: |
40
40
  bundle exec rake
data/.gitignore CHANGED
@@ -16,3 +16,6 @@
16
16
 
17
17
  # rspec failure tracking
18
18
  .rspec_status
19
+ .rubocop-https---raw-githubusercontent-com-riboseinc-oss-guides-master-ci-rubocop-yml
20
+ Gemfile.lock
21
+ relaton/
@@ -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.inject([]) do |memo, (k, _)|
93
- memo << k; memo
96
+ options[:extension_keys] ||= @processor.output_formats.reduce([]) do |memo, (k, _)|
97
+ memo << k
94
98
  end
95
- extensions = options[:extension_keys].inject([]) do |memo, e|
96
- @processor.output_formats[e] and memo << e or
97
- Util.log("[metanorma] Error: #{e} format is not supported for this standard.", :error)
98
- memo
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: Asciidoctor input.", :info)
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,50 @@ 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
- extensions.each do |ext|
200
- isodoc_options = @processor.extract_options(file)
201
- isodoc_options[:datauriimage] = true if options[:datauriimage]
232
+ xml_name = options[:filename].sub(/\.[^.]+$/, ".xml")
233
+ presentationxml_name = options[:filename].sub(/\.[^.]+$/, ".presentation.xml")
234
+ extensions.sort do |a, b|
235
+ sort_extensions_execution(a) <=> sort_extensions_execution(b)
236
+ end.each do |ext|
202
237
  file_extension = @processor.output_formats[ext]
203
238
  outfilename = options[:filename].sub(/\.[^.]+$/, ".#{file_extension}")
239
+ isodoc_options = @processor.extract_options(file)
240
+ isodoc_options[:datauriimage] = true if options[:datauriimage]
204
241
  if ext == :rxl
205
242
  options[:relaton] = outfilename
206
243
  relaton_export(isodoc, options)
207
244
  else
208
- @processor.output(isodoc, outfilename, ext, isodoc_options)
209
- end
210
- if options[:wrapper] and /html$/.match file_extension
211
- outfilename = outfilename.sub(/\.html$/, "")
212
- FileUtils.mkdir_p outfilename
213
- FileUtils.mv "#{outfilename}.html", outfilename
214
- FileUtils.mv "#{outfilename}_images", outfilename, force: true
245
+ begin
246
+ @processor.use_presentation_xml(ext) ?
247
+ @processor.output(nil, presentationxml_name, outfilename, ext, isodoc_options) :
248
+ @processor.output(isodoc, xml_name, outfilename, ext, isodoc_options)
249
+ rescue StandardError => e
250
+ puts e.message
251
+ end
215
252
  end
253
+ wrap_html(options, file_extension, outfilename)
216
254
  end
217
255
  end
218
256
  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: (?<hierarchical_assets>[^\n]+)\n/ =~ headerextract
62
- /\n:use-xinclude: (?<use_xinclude>[^\n]+)\n/ =~ headerextract
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
 
@@ -1,5 +1,4 @@
1
- require "open3"
2
- require "tempfile"
1
+ require 'mn2pdf'
3
2
  require_relative "./utils.rb"
4
3
 
5
4
  module Metanorma
@@ -7,11 +6,8 @@ module Metanorma
7
6
  class XslfoPdf < Base
8
7
  def convert(url_path, output_path, xsl_stylesheet)
9
8
  return if url_path.nil? || output_path.nil? || xsl_stylesheet.nil?
10
- pdfjar = File.join(File.dirname(__FILE__), "../../../bin/mn2pdf.jar")
11
- cmd = ["java", "-jar", pdfjar, "--xml-file", url_path, "--xsl-file",
12
- xsl_stylesheet, "--pdf-file", output_path].join(" ")
13
- _, error_str, status = Open3.capture3(cmd)
14
- raise error_str unless status.success?
9
+
10
+ Mn2pdf.convert(url_path, output_path, xsl_stylesheet)
15
11
  end
16
12
  end
17
13
  end
@@ -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 output(isodoc_node, outname, format, options={})
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
 
@@ -48,7 +48,7 @@ module Metanorma
48
48
  @processors.inject({}) do |acc, (k,v)|
49
49
  if v.asciidoctor_backend
50
50
  x = Asciidoctor.load nil, {backend: v.asciidoctor_backend}
51
- acc[k] = x.converter.class::XML_ROOT_TAG
51
+ acc[k] = x.converter.xml_root_tag
52
52
  end
53
53
  acc
54
54
  end
@@ -1,3 +1,3 @@
1
1
  module Metanorma
2
- VERSION = "1.0.3"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -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.3"
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.3
4
+ version: 1.1.1
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-04-21 00:00:00.000000000 Z
11
+ date: 2020-07-07 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.3'
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.3'
152
+ version: '1.4'
139
153
  description: Library to process any Metanorma standard.
140
154
  email:
141
155
  - open.source@ribose.com
@@ -162,7 +176,6 @@ files:
162
176
  - Rakefile
163
177
  - bin/console
164
178
  - bin/metanorma-pdf.js
165
- - bin/mn2pdf.jar
166
179
  - bin/rasterize.js
167
180
  - bin/rspec
168
181
  - bin/setup
@@ -189,7 +202,7 @@ homepage: https://github.com/metanorma/metanorma
189
202
  licenses:
190
203
  - BSD-2-Clause
191
204
  metadata: {}
192
- post_install_message:
205
+ post_install_message:
193
206
  rdoc_options: []
194
207
  require_paths:
195
208
  - lib
@@ -204,9 +217,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
204
217
  - !ruby/object:Gem::Version
205
218
  version: '0'
206
219
  requirements: []
207
- rubyforge_project:
208
- rubygems_version: 2.7.6
209
- signing_key:
220
+ rubygems_version: 3.0.3
221
+ signing_key:
210
222
  specification_version: 4
211
223
  summary: Metanorma is the standard of standards; the metanorma gem allows you to create
212
224
  any standard document type supported by Metanorma.
Binary file