metanorma-cli 1.5.3pre1 → 1.5.5pre

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: 2b30701b2ca783571d497de62a3d444b6ed716b92b4dbb63a67a8991c28cc56d
4
- data.tar.gz: 18c93604f417f0daa0dd284acf44b7223f31168683a46afa8d016e4d909db6ae
3
+ metadata.gz: 216941505e4823840c1a68100c614e8176ae6bab6191678c9ecc8672a1689cc9
4
+ data.tar.gz: e8d4d9687da7271aee62442fe6d8b2a439e09d14d7f0dc632f3cceab9ea2ea98
5
5
  SHA512:
6
- metadata.gz: 74fb1594c6a4d0bbef8d915837375297dab00d44fada360126b93eef47933bbc14ae1bd9144d1d8307c21793161a6d04f14ff9e9eb6788cf5e365d9663583ff6
7
- data.tar.gz: e1edfcd8b94510b9bf3a16f840dd3708fb6cf9db1f7f22979754597f609e54c7e77f83acbaab6b0650b81336087bdd87dd676afe4db09c9bcfad5e6c8db53f81
6
+ metadata.gz: 93e7b276b5e6ba39e2d52b3a1c0a93b8c02e8f40b711f9f540487d313e57c4b48165800d6a380837577662eca58ee8b13755230b35821cdf24aa9e81f1c9fce0
7
+ data.tar.gz: 208cd9e50cd8733aef8676bd2df1fa6b225edad8b3575f1cdf4e7b39fcef9dd33ec0c2ab875a8ec3635c16756e24f1394968b3a94bc40c17fc6ea1fc6c56fc93
data/exe/metanorma CHANGED
@@ -1,6 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: UTF-8
3
3
 
4
+ Encoding.default_internal = "utf-8"
5
+ Encoding.default_external = "utf-8"
6
+
4
7
  # resolve bin path, ignoring symlinks
5
8
  require "pathname"
6
9
  bin_file = Pathname.new(__FILE__).realpath
@@ -0,0 +1,57 @@
1
+ require "yaml"
2
+
3
+ module Metanorma
4
+ module Cli
5
+ class Collection
6
+ def initialize(file, options)
7
+ @file = file
8
+ @options = Cli.with_indifferent_access(options)
9
+ @compile_options = @options.delete(:compile)
10
+ end
11
+
12
+ def self.render(filename, options = {})
13
+ new(filename, options).render
14
+ end
15
+
16
+ def render
17
+ extract_options_from_file
18
+ collection_file.render(collection_options.compact)
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :file, :options
24
+
25
+ def collection_file
26
+ @collection_file ||= Metanorma::Collection.parse(file)
27
+ end
28
+
29
+ def collection_options
30
+ {
31
+ compile: @compile_options,
32
+ coverpage: options.fetch(:coverpage, nil),
33
+ output_folder: options.fetch(:output_folder, nil),
34
+ format: collection_output_formats(options.fetch(:format, "")),
35
+ }
36
+ end
37
+
38
+ def collection_output_formats(formats)
39
+ if formats.is_a?(String)
40
+ formats = formats.split(",")
41
+ end
42
+
43
+ (formats || []).map { |extension| extension.strip.to_sym }
44
+ end
45
+
46
+ def extract_options_from_file
47
+ if options.empty?
48
+ yaml_file = YAML.safe_load(File.read(@file.to_s))
49
+
50
+ @options = Cli.with_indifferent_access(
51
+ yaml_file.slice("coverpage", "format", "output_folder"),
52
+ )
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -1,5 +1,6 @@
1
1
  require "metanorma/cli/compiler"
2
2
  require "metanorma/cli/generator"
3
+ require "metanorma/cli/collection"
3
4
  require "metanorma/cli/git_template"
4
5
  require "metanorma/cli/thor_with_config"
5
6
  require "metanorma/cli/commands/config"
@@ -67,12 +68,11 @@ module Metanorma
67
68
 
68
69
  def collection(filename = nil)
69
70
  if filename
70
- opts = options
71
- opts[:format] &&= opts[:format].split(",").map &:to_sym
72
- opts[:compile] = filter_compile_options(opts)
73
- coll = Metanorma::Collection.parse filename
74
- coll.render opts
75
- else UI.say("Need to specify a file to process")
71
+ coll_options = options.dup
72
+ coll_options[:compile] = filter_compile_options(coll_options)
73
+ Metanorma::Cli::Collection.render(filename, coll_options)
74
+ else
75
+ UI.say("Need to specify a file to process")
76
76
  end
77
77
  rescue ArgumentError => e
78
78
  UI.say e.message
@@ -6,6 +6,7 @@ module Metanorma
6
6
  module Cli
7
7
  class SiteGenerator
8
8
  def initialize(source, options = {}, compile_options = {})
9
+ @collection_queue = []
9
10
  @source = find_realpath(source)
10
11
  @site_path = options.fetch(:output_dir, "site").to_s
11
12
  @asset_folder = options.fetch(:asset_folder, "documents").to_s
@@ -31,6 +32,8 @@ module Metanorma
31
32
  build_collection_file(collection_name)
32
33
  convert_to_html_page(collection_name, "index.html")
33
34
  end
35
+
36
+ dequeue_jobs
34
37
  end
35
38
 
36
39
  private
@@ -72,6 +75,10 @@ module Metanorma
72
75
  end
73
76
 
74
77
  def compile(source)
78
+ if collection_file?(source)
79
+ return
80
+ end
81
+
75
82
  UI.info("Compiling #{source} ...")
76
83
 
77
84
  options = @compile_options.merge(
@@ -158,6 +165,22 @@ module Metanorma
158
165
 
159
166
  output_directory
160
167
  end
168
+
169
+ def collection_file?(source)
170
+ ext = File.extname(source)&.downcase
171
+
172
+ if [".yml", ".yaml"].include?(ext)
173
+ @collection_queue << source
174
+ end
175
+ end
176
+
177
+ def dequeue_jobs
178
+ job = @collection_queue.pop
179
+
180
+ if job
181
+ Cli::Collection.render(job, compile: @compile_options)
182
+ end
183
+ end
161
184
  end
162
185
  end
163
186
  end
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Cli
3
- VERSION = "1.5.3pre1".freeze
3
+ VERSION = "1.5.5pre".freeze
4
4
  end
5
5
  end
data/lib/metanorma/cli.rb CHANGED
@@ -82,6 +82,10 @@ module Metanorma
82
82
  Pathname.new(Cli.root).join("..")
83
83
  end
84
84
 
85
+ def self.with_indifferent_access(options)
86
+ Thor::CoreExt::HashWithIndifferentAccess.new(options)
87
+ end
88
+
85
89
  def self.find_command(arguments)
86
90
  commands = Metanorma::Cli::Command.all_commands.keys
87
91
  commands.select { |cmd| arguments.include?(cmd.gsub("_", "-")) == true }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.3pre1
4
+ version: 1.5.5pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-11-30 00:00:00.000000000 Z
11
+ date: 2021-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: debug
@@ -474,6 +474,7 @@ files:
474
474
  - i18n.yaml
475
475
  - lib/metanorma-cli.rb
476
476
  - lib/metanorma/cli.rb
477
+ - lib/metanorma/cli/collection.rb
477
478
  - lib/metanorma/cli/command.rb
478
479
  - lib/metanorma/cli/commands/config.rb
479
480
  - lib/metanorma/cli/commands/site.rb
@@ -513,7 +514,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
513
514
  - !ruby/object:Gem::Version
514
515
  version: 1.3.1
515
516
  requirements: []
516
- rubygems_version: 3.2.22
517
+ rubygems_version: 3.2.32
517
518
  signing_key:
518
519
  specification_version: 4
519
520
  summary: Metanorma is the standard of standards; the metanorma gem allows you to create