metanorma 1.2.8 → 1.3.4

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.
@@ -15,7 +15,7 @@ module Metanorma
15
15
  attr_accessor :logs
16
16
 
17
17
  def initialize
18
- @logs ||= [:warning, :error, :fatal]
18
+ @logs ||= %i[warning error fatal]
19
19
  end
20
20
  end
21
21
 
@@ -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 bibitem(file), file
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
- case format(file)
54
- when :xml
55
- from_xml Nokogiri::XML(File.read(file, encoding: "UTF-8"))
56
- when :yaml
57
- yaml = File.read(file, encoding: "UTF-8")
58
- Relaton::Cli::YAMLConvertor.convert_single_file(yaml)
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
@@ -3,6 +3,5 @@ require_relative "./input/asciidoc"
3
3
 
4
4
  module Metanorma
5
5
  module Input
6
-
7
6
  end
8
7
  end
@@ -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
- safe: :safe,
13
- backend: type,
14
- header_footer: true,
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, $stderr = $stderr, StringIO.new
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: }.match($stderr.string) and
34
- err = $stderr.string
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
- (!asciimath.nil? && asciimath != ":mn-keep-asciimath: false") : nil
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
- def extract_options(file)
64
- headerextract = file.sub(/\n\n.*$/m, "\n")
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
- /\n:script: (?<script>[^\n]+)\n/ =~ headerextract
67
- /\n:body-font: (?<bodyfont>[^\n]+)\n/ =~ headerextract
68
- /\n:header-font: (?<headerfont>[^\n]+)\n/ =~ headerextract
69
- /\n:monospace-font: (?<monospacefont>[^\n]+)\n/ =~ headerextract
70
- /\n:title-font: (?<titlefont>[^\n]+)\n/ =~ headerextract
71
- /\n:i18nyaml: (?<i18nyaml>[^\n]+)\n/ =~ headerextract
72
- /\n:htmlstylesheet: (?<htmlstylesheet>[^\n]+)\n/ =~ headerextract
73
- /\n:htmlstylesheet-override: (?<htmlstylesheet_override>[^\n]+)\n/ =~ headerextract
74
- /\n:htmlcoverpage: (?<htmlcoverpage>[^\n]+)\n/ =~ headerextract
75
- /\n:htmlintropage: (?<htmlintropage>[^\n]+)\n/ =~ headerextract
76
- /\n:scripts: (?<scripts>[^\n]+)\n/ =~ headerextract
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?(hierarchical_assets) and
94
- hierarchical_assets = empty_attr(hierarchical_assets, "hierarchical-assets")
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?(break_up_urls_in_tables) and
98
- break_up_urls_in_tables = empty_attr(break_up_urls_in_tables, "break-up-urls-in-tables")
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
- htmltoclevels: defined?(htmltoclevels) ? htmltoclevels : nil,
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?(break_up_urls_in_tables) ? break_up_urls_in_tables : nil,
126
- }.reject { |_, val| val.nil? }
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
@@ -4,7 +4,5 @@ require_relative "./output/xslfo"
4
4
 
5
5
  module Metanorma
6
6
  module Output
7
-
8
7
  end
9
8
  end
10
-
@@ -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
- file_url = "file://#{Dir.pwd}/#{url_path}" unless %r{^file://} =~ file_url
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
@@ -11,5 +11,9 @@ module Metanorma
11
11
  exit(1)
12
12
  end
13
13
  end
14
+
15
+ def self.source2dest_filename(name)
16
+ name.sub(%r{^(\./)?(\.\./)+}, "")
17
+ end
14
18
  end
15
19
  end
@@ -1,3 +1,3 @@
1
1
  module Metanorma
2
- VERSION = "1.2.8"
2
+ VERSION = "1.3.4".freeze
3
3
  end
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 = ['Ribose Inc.']
10
- spec.email = ['open.source@ribose.com']
8
+ spec.authors = ["Ribose Inc."]
9
+ spec.email = ["open.source@ribose.com"]
11
10
 
12
- spec.summary = %q{Metanorma is the standard of standards; the metanorma gem allows you to create any standard document type supported by Metanorma.}
13
- spec.description = %q{Library to process any Metanorma standard.}
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 = '>= 2.4.0'
23
+ spec.required_ruby_version = ">= 2.4.0"
25
24
 
26
- spec.add_runtime_dependency 'asciidoctor'
27
- spec.add_runtime_dependency 'htmlentities'
28
- spec.add_runtime_dependency 'nokogiri'
29
- spec.add_runtime_dependency 'mn2pdf', "~> 1"
30
- spec.add_runtime_dependency 'metanorma-utils', "~> 1.1.0"
31
- spec.add_runtime_dependency 'pry'
32
- spec.add_runtime_dependency 'fontist', '~> 1.8'
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