metanorma 1.2.7 → 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -61,65 +61,35 @@ module Metanorma
61
61
  end
62
62
 
63
63
  def extract_options(file)
64
- headerextract = file.sub(/\n\n.*$/m, "\n")
65
-
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:htmlcoverpage: (?<htmlcoverpage>[^\n]+)\n/ =~ headerextract
74
- /\n:htmlintropage: (?<htmlintropage>[^\n]+)\n/ =~ headerextract
75
- /\n:scripts: (?<scripts>[^\n]+)\n/ =~ headerextract
76
- /\n:scripts-pdf: (?<scripts_pdf>[^\n]+)\n/ =~ headerextract
77
- /\n:wordstylesheet: (?<wordstylesheet>[^\n]+)\n/ =~ headerextract
78
- /\n:standardstylesheet: (?<standardstylesheet>[^\n]+)\n/ =~ headerextract
79
- /\n:header: (?<header>[^\n]+)\n/ =~ headerextract
80
- /\n:wordcoverpage: (?<wordcoverpage>[^\n]+)\n/ =~ headerextract
81
- /\n:wordintropage: (?<wordintropage>[^\n]+)\n/ =~ headerextract
82
- /\n:ulstyle: (?<ulstyle>[^\n]+)\n/ =~ headerextract
83
- /\n:olstyle: (?<olstyle>[^\n]+)\n/ =~ headerextract
84
- /\n:data-uri-image: (?<datauriimage>[^\n]+)\n/ =~ headerextract
85
- /\n:htmltoclevels: (?<htmltoclevels>[^\n]+)\n/ =~ headerextract
86
- /\n:doctoclevels: (?<doctoclevels>[^\n]+)\n/ =~ headerextract
87
- /\n:(?<hierarchical_assets>hierarchical-assets:[^\n]*)\n/ =~ headerextract
88
- /\n:(?<use_xinclude>use-xinclude:[^\n]*)\n/ =~ headerextract
89
- /\n:(?<break_up_urls_in_tables>break-up-urls-in-tables:[^\n]*)\n/ =~ headerextract
64
+ header = file.sub(/\n\n.*$/m, "\n")
65
+ ret = %w(htmlstylesheet htmlcoverpage htmlintropage scripts
66
+ scripts-pdf wordstylesheet
67
+ standardstylesheet header wordcoverpage wordintropage i18nyaml
68
+ ulstyle olstyle htmlstylesheet-override
69
+ htmltoclevels doctoclevels sectionsplit
70
+ body-font header-font monospace-font title-font
71
+ wordstylesheet-override).each_with_object({}) do |w, acc|
72
+ m = /\n:#{w}: ([^\n]+)\n/.match(header) or next
73
+ acc[w.gsub(/-/, "").sub(/override$/, "_override")
74
+ .sub(/pdf$/, "_pdf").to_sym] = m[1]
75
+ end
76
+ /\n:data-uri-image: (?<datauriimage>[^\n]+)\n/ =~ header
77
+ /\n:(?<hierarchical_assets>hierarchical-assets:[^\n]*)\n/ =~ header
78
+ /\n:(?<use_xinclude>use-xinclude:[^\n]*)\n/ =~ header
79
+ /\n:(?<break_up>break-up-urls-in-tables:[^\n]*)\n/ =~ header
90
80
 
91
81
  defined?(hierarchical_assets) and
92
82
  hierarchical_assets = empty_attr(hierarchical_assets, "hierarchical-assets")
93
83
  defined?(use_xinclude) and
94
84
  use_xinclude = empty_attr(use_xinclude, "use-xinclude")
95
- defined?(break_up_urls_in_tables) and
96
- break_up_urls_in_tables = empty_attr(break_up_urls_in_tables, "break-up-urls-in-tables")
97
- {
98
- script: defined?(script) ? script : nil,
99
- bodyfont: defined?(bodyfont) ? bodyfont : nil,
100
- headerfont: defined?(headerfont) ? headerfont : nil,
101
- monospacefont: defined?(monospacefont) ? monospacefont : nil,
102
- titlefont: defined?(titlefont) ? titlefont : nil,
103
- i18nyaml: defined?(i18nyaml) ? i18nyaml : nil,
104
- htmlstylesheet: defined?(htmlstylesheet) ? htmlstylesheet : nil,
105
- htmlcoverpage: defined?(htmlcoverpage) ? htmlcoverpage : nil,
106
- htmlintropage: defined?(htmlintropage) ? htmlintropage : nil,
107
- scripts: defined?(scripts) ? scripts : nil,
108
- scripts_pdf: defined?(scripts_pdf) ? scripts_pdf : nil,
109
- wordstylesheet: defined?(wordstylesheet) ? wordstylesheet : nil,
110
- standardstylesheet: defined?(standardstylesheet) ? standardstylesheet : nil,
111
- header: defined?(header) ? header : nil,
112
- wordcoverpage: defined?(wordcoverpage) ? wordcoverpage : nil,
113
- wordintropage: defined?(wordintropage) ? wordintropage : nil,
114
- ulstyle: defined?(ulstyle) ? ulstyle : nil,
115
- olstyle: defined?(olstyle) ? olstyle : nil,
85
+ defined?(break_up) and
86
+ break_up = empty_attr(break_up, "break-up-urls-in-tables")
87
+ ret.merge({
116
88
  datauriimage: defined?(datauriimage) ? datauriimage != "false" : nil,
117
- htmltoclevels: defined?(htmltoclevels) ? htmltoclevels : nil,
118
- doctoclevels: defined?(doctoclevels) ? doctoclevels : nil,
119
89
  hierarchical_assets: defined?(hierarchical_assets) ? hierarchical_assets : nil,
120
90
  use_xinclude: defined?(use_xinclude) ? use_xinclude : nil,
121
- break_up_urls_in_tables: defined?(break_up_urls_in_tables) ? break_up_urls_in_tables : nil,
122
- }.reject { |_, val| val.nil? }
91
+ break_up_urls_in_tables: defined?(break_up) ? break_up : nil,
92
+ }).reject { |_, val| val.nil? }
123
93
  end
124
94
 
125
95
  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.7"
2
+ VERSION = "1.3.3".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,27 +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.0.3"
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"
43
+ spec.add_development_dependency "rubocop", "~> 1.5.2"
44
44
  spec.add_development_dependency "sassc", "~> 2.4.0"
45
45
  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.2.7
4
+ version: 1.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-16 00:00:00.000000000 Z
11
+ date: 2021-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: fontist
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.8'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: htmlentities
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -39,19 +53,19 @@ dependencies:
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
- name: nokogiri
56
+ name: metanorma-utils
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - ">="
59
+ - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '0'
61
+ version: 1.2.0
48
62
  type: :runtime
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - ">="
66
+ - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '0'
68
+ version: 1.2.0
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: mn2pdf
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -67,19 +81,19 @@ dependencies:
67
81
  - !ruby/object:Gem::Version
68
82
  version: '1'
69
83
  - !ruby/object:Gem::Dependency
70
- name: metanorma-utils
84
+ name: nokogiri
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - "~>"
87
+ - - ">="
74
88
  - !ruby/object:Gem::Version
75
- version: 1.0.3
89
+ version: '0'
76
90
  type: :runtime
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - "~>"
94
+ - - ">="
81
95
  - !ruby/object:Gem::Version
82
- version: 1.0.3
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: pry
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -95,103 +109,103 @@ dependencies:
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
- name: fontist
112
+ name: byebug
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - "~>"
102
116
  - !ruby/object:Gem::Version
103
- version: '1.8'
104
- type: :runtime
117
+ version: '10.0'
118
+ type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
122
  - - "~>"
109
123
  - !ruby/object:Gem::Version
110
- version: '1.8'
124
+ version: '10.0'
111
125
  - !ruby/object:Gem::Dependency
112
- name: rake
126
+ name: equivalent-xml
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
129
  - - "~>"
116
130
  - !ruby/object:Gem::Version
117
- version: '13.0'
131
+ version: '0.6'
118
132
  type: :development
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
136
  - - "~>"
123
137
  - !ruby/object:Gem::Version
124
- version: '13.0'
138
+ version: '0.6'
125
139
  - !ruby/object:Gem::Dependency
126
- name: rspec
140
+ name: metanorma-iso
127
141
  requirement: !ruby/object:Gem::Requirement
128
142
  requirements:
129
143
  - - "~>"
130
144
  - !ruby/object:Gem::Version
131
- version: '3.0'
145
+ version: 1.8.0
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: '3.0'
152
+ version: 1.8.0
139
153
  - !ruby/object:Gem::Dependency
140
- name: byebug
154
+ name: rake
141
155
  requirement: !ruby/object:Gem::Requirement
142
156
  requirements:
143
157
  - - "~>"
144
158
  - !ruby/object:Gem::Version
145
- version: '10.0'
159
+ version: '13.0'
146
160
  type: :development
147
161
  prerelease: false
148
162
  version_requirements: !ruby/object:Gem::Requirement
149
163
  requirements:
150
164
  - - "~>"
151
165
  - !ruby/object:Gem::Version
152
- version: '10.0'
166
+ version: '13.0'
153
167
  - !ruby/object:Gem::Dependency
154
- name: rspec-command
168
+ name: rspec
155
169
  requirement: !ruby/object:Gem::Requirement
156
170
  requirements:
157
171
  - - "~>"
158
172
  - !ruby/object:Gem::Version
159
- version: '1.0'
173
+ version: '3.0'
160
174
  type: :development
161
175
  prerelease: false
162
176
  version_requirements: !ruby/object:Gem::Requirement
163
177
  requirements:
164
178
  - - "~>"
165
179
  - !ruby/object:Gem::Version
166
- version: '1.0'
180
+ version: '3.0'
167
181
  - !ruby/object:Gem::Dependency
168
- name: equivalent-xml
182
+ name: rspec-command
169
183
  requirement: !ruby/object:Gem::Requirement
170
184
  requirements:
171
185
  - - "~>"
172
186
  - !ruby/object:Gem::Version
173
- version: '0.6'
187
+ version: '1.0'
174
188
  type: :development
175
189
  prerelease: false
176
190
  version_requirements: !ruby/object:Gem::Requirement
177
191
  requirements:
178
192
  - - "~>"
179
193
  - !ruby/object:Gem::Version
180
- version: '0.6'
194
+ version: '1.0'
181
195
  - !ruby/object:Gem::Dependency
182
- name: metanorma-iso
196
+ name: rubocop
183
197
  requirement: !ruby/object:Gem::Requirement
184
198
  requirements:
185
199
  - - "~>"
186
200
  - !ruby/object:Gem::Version
187
- version: 1.7.0
201
+ version: 1.5.2
188
202
  type: :development
189
203
  prerelease: false
190
204
  version_requirements: !ruby/object:Gem::Requirement
191
205
  requirements:
192
206
  - - "~>"
193
207
  - !ruby/object:Gem::Version
194
- version: 1.7.0
208
+ version: 1.5.2
195
209
  - !ruby/object:Gem::Dependency
196
210
  name: sassc
197
211
  requirement: !ruby/object:Gem::Requirement
@@ -238,12 +252,15 @@ files:
238
252
  - lib/metanorma/asciidoctor_extensions.rb
239
253
  - lib/metanorma/asciidoctor_extensions/glob_include_processor.rb
240
254
  - lib/metanorma/collection.rb
255
+ - lib/metanorma/collection_fileparse.rb
241
256
  - lib/metanorma/collection_fileprocess.rb
242
257
  - lib/metanorma/collection_manifest.rb
243
258
  - lib/metanorma/collection_renderer.rb
244
259
  - lib/metanorma/compile.rb
260
+ - lib/metanorma/compile_validate.rb
245
261
  - lib/metanorma/config.rb
246
262
  - lib/metanorma/document.rb
263
+ - lib/metanorma/fontist_utils.rb
247
264
  - lib/metanorma/input.rb
248
265
  - lib/metanorma/input/asciidoc.rb
249
266
  - lib/metanorma/input/base.rb