mn2pdf 1.36 → 1.38.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: 4c53d81c83cc92d580af1adf8ef8c82a78fbccdb8ede91f46c07ddbb41887cfc
4
- data.tar.gz: ba2120b9b826198e6b3ef5fe2703a4e181de4b56a6d46cf0806368cc2aa3db77
3
+ metadata.gz: 3920d0ce988ca4a0c1748d9c203e26c396f2fccf7ee8f4a04c6ff9afb5572639
4
+ data.tar.gz: c3cdba0ff6c45eef7b44bd5020b98cde84fa193740c4556b04a6d9a660e66ee6
5
5
  SHA512:
6
- metadata.gz: 4d976736c47626c0177bda68ae2294fd4650d6c3cef64cb5ae015cb90f063d3000b29a7479d06be037fa2dc601347ef607d129e5b4221b24b06412643857733b
7
- data.tar.gz: 178261e02bb181c54efc60374e31446a93d286b761e78221953dbf9cda6d6d5bc7f391ed8fd6627d8e3a4abc969fd69e68cb14e272e81a6764351d208442ddc2
6
+ metadata.gz: 83a37bfd6a57cde548675913cb29ec0b12c9b0496d14435736c95e2d43d41f878bff1b605f95b570ea48a13e693f78e67452c191f2c4b8cdba7df4e9507805a8
7
+ data.tar.gz: 947dc02d3aed97e8d98ad9c24a41263f34ee12866a665785aac74bfa57ee2a200614fb7eac4a33b873fdac4536d4bc3a8b3acd4ae58a86fa87ee94013f8835b2
@@ -4,28 +4,38 @@ on:
4
4
  push:
5
5
  tags:
6
6
  - '*'
7
+ workflow_dispatch:
8
+ inputs:
9
+ next_version:
10
+ description: |
11
+ Next release version. Possible values: x.y.z, major, minor, patch or pre|rc|etc
12
+ required: true
13
+ default: 'skip'
7
14
 
8
15
  jobs:
9
16
  release:
10
17
  runs-on: ubuntu-18.04
11
18
  steps:
12
19
  - uses: actions/checkout@v1
13
- - name: Use Ruby
14
- uses: actions/setup-ruby@v1
20
+
21
+ - uses: ruby/setup-ruby@v1
15
22
  with:
16
23
  ruby-version: '2.6'
17
- architecture: 'x64'
18
- - name: Update gems
19
- run: |
20
- gem install bundler
21
- bundle install --jobs 4 --retry 3
22
- - name: Update mn2pdf.jar
23
- run: |
24
- rm -f bin/mn2pdf.jar
25
- rake bin/mn2pdf.jar
26
- - name: Run specs
27
- run: |
28
- bundle exec rake
24
+ bundler-cache: true
25
+
26
+ - run: rm -f bin/mn2pdf.jar && rake bin/mn2pdf.jar
27
+
28
+ - run: bundle exec rake
29
+
30
+ - run: gem install gem-release
31
+
32
+ - run: |
33
+ git config user.name github-actions
34
+ git config user.email github-actions@github.com
35
+
36
+ - if: github.event_name == 'workflow_dispatch' && github.event.inputs.next_version != 'skip'
37
+ run: gem bump --version ${{ github.event.inputs.next_version }} --tag --push
38
+
29
39
  - name: Publish to rubygems.org
30
40
  env:
31
41
  RUBYGEMS_API_KEY: ${{secrets.METANORMA_CI_RUBYGEMS_API_KEY}}
data/bin/mn2pdf.jar CHANGED
Binary file
@@ -1,3 +1,3 @@
1
1
  module Mn2pdf
2
- VERSION = "1.36".freeze
2
+ VERSION = "1.38.1".freeze
3
3
  end
data/lib/mn2pdf.rb CHANGED
@@ -1,12 +1,17 @@
1
1
  require "open3"
2
2
  require "rbconfig"
3
+ require "tempfile"
4
+ require "yaml"
5
+
3
6
  require "mn2pdf/version"
4
7
 
5
8
  module Mn2pdf
6
9
  MN2PDF_JAR_PATH = File.join(File.dirname(__FILE__), "../bin/mn2pdf.jar")
10
+ DEFAULT_JAVA_OPTS = ["-Xss5m", "-Xmx2048m"].freeze
11
+ FONTS_MANIFEST = :font_manifest
7
12
 
8
13
  def self.jvm_options
9
- options = []
14
+ options = DEFAULT_JAVA_OPTS.dup
10
15
 
11
16
  if RbConfig::CONFIG["host_os"].match?(/darwin|mac os/)
12
17
  options << "-Dapple.awt.UIElement=true"
@@ -18,7 +23,7 @@ module Mn2pdf
18
23
  def self.help
19
24
  cmd = ["java", *jvm_options, "-jar", MN2PDF_JAR_PATH].join(" ")
20
25
  # help message goes to STDERR (from mn2pdf v1.36)
21
- blank_message, help_message, = Open3.capture3(cmd)
26
+ _, help_message, = Open3.capture3(cmd)
22
27
  help_message
23
28
  end
24
29
 
@@ -28,22 +33,71 @@ module Mn2pdf
28
33
  message.strip
29
34
  end
30
35
 
31
- def self.convert(url_path, output_path, xsl_stylesheet, options = "")
32
- return if url_path.nil? || output_path.nil? || xsl_stylesheet.nil?
36
+ def self.convert(url_path, output_path, xsl_stylesheet, options = {})
37
+ cmd = build_cmd(url_path, output_path, xsl_stylesheet)
38
+
39
+ return unless cmd
40
+
41
+ case options
42
+ when String
43
+ cmd << options
44
+
45
+ mn2pdf(cmd)
46
+ when Hash
47
+ manifest = options.delete(FONTS_MANIFEST)
48
+
49
+ options.each do |k, v|
50
+ cmd << "#{k} #{quote(v)}"
51
+ end
52
+ if manifest
53
+ dump_fontist_manifest_locations(manifest) do |manifest_path|
54
+ cmd << "--font-manifest" << quote(manifest_path)
55
+ mn2pdf(cmd)
56
+ end
57
+ else
58
+ mn2pdf(cmd)
59
+ end
60
+ else
61
+ warn "Unsupported options type #{options.class}"
62
+ end
63
+ end
64
+
65
+ def self.build_cmd(url, output, xslt)
66
+ return if url.nil? || output.nil? || xslt.nil?
33
67
 
34
- cmd = ["java", "-Xss5m", "-Xmx2048m", *jvm_options,
35
- "-jar", MN2PDF_JAR_PATH, "--xml-file", url_path,
36
- "--xsl-file", xsl_stylesheet, "--pdf-file", output_path, options].join(" ")
68
+ ["java", *jvm_options,
69
+ "-jar", MN2PDF_JAR_PATH,
70
+ "--xml-file", quote(url),
71
+ "--xsl-file", quote(xslt),
72
+ "--pdf-file", quote(output)]
73
+ end
37
74
 
75
+ def self.mn2pdf(cmd)
76
+ cmd = cmd.join(" ")
38
77
  puts cmd
39
- stdout_str, error_str, status = Open3.capture3(cmd)
78
+ out, err, status = Open3.capture3(cmd)
40
79
 
41
- raise prepare_error_msg(stdout_str, error_str) unless status.success?
80
+ raise prepare_error_msg(out, err) unless status.success?
42
81
  end
43
82
 
44
- def self.prepare_error_msg(stdout_str, error_str)
83
+ def self.prepare_error_msg(stdout, stderr)
45
84
  # Strip default mn2pdf message
46
- stdout_str = stdout_str.gsub("Preparing...", "").strip
47
- ["[mn2pdf] Fatal:", stdout_str, error_str].join(" ").strip
85
+ stdout = stdout.gsub("Preparing...", "").strip
86
+ ["[mn2pdf] Fatal:", stdout, stderr].join(" ").strip
87
+ end
88
+
89
+ def self.quote(str)
90
+ return str if /^'.*'$/.match(str) || /^".*"$/.match(str)
91
+
92
+ %("#{str}")
93
+ end
94
+
95
+ def self.dump_fontist_manifest_locations(manifest)
96
+ Tempfile.create(["fontist_locations", ".yml"]) do |f|
97
+ f.write manifest.to_yaml
98
+ f.flush
99
+
100
+ yield f.path
101
+ end
48
102
  end
49
103
  end
data/mn2pdf.gemspec CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.require_paths = ["lib"]
21
21
  spec.files = `git ls-files`.split("\n")
22
22
  spec.test_files = `git ls-files -- {spec}/*`.split("\n")
23
- spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
23
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
24
24
 
25
25
  # Specify which files should be added to the gem when it is released.
26
26
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mn2pdf
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.36'
4
+ version: 1.38.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-07 00:00:00.000000000 Z
11
+ date: 2021-10-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  mn2pdf converts Metanorma XML into PDF.
@@ -41,7 +41,7 @@ homepage: https://github.com/metanorma/mn2pdf-ruby
41
41
  licenses:
42
42
  - BSD-2-Clause
43
43
  metadata: {}
44
- post_install_message:
44
+ post_install_message:
45
45
  rdoc_options: []
46
46
  require_paths:
47
47
  - lib
@@ -49,15 +49,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
49
49
  requirements:
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
- version: 2.4.0
52
+ version: 2.5.0
53
53
  required_rubygems_version: !ruby/object:Gem::Requirement
54
54
  requirements:
55
55
  - - ">="
56
56
  - !ruby/object:Gem::Version
57
57
  version: '0'
58
58
  requirements: []
59
- rubygems_version: 3.0.3.1
60
- signing_key:
59
+ rubygems_version: 3.2.22
60
+ signing_key:
61
61
  specification_version: 4
62
62
  summary: mn2pdf converts Metanorma XML into PDF.
63
63
  test_files: []