metanorma-cli 1.5.4 → 1.5.5pre
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.
- checksums.yaml +4 -4
- data/lib/metanorma/cli/collection.rb +57 -0
- data/lib/metanorma/cli/command.rb +6 -6
- data/lib/metanorma/cli/site_generator.rb +23 -0
- data/lib/metanorma/cli/version.rb +1 -1
- data/lib/metanorma/cli.rb +4 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 216941505e4823840c1a68100c614e8176ae6bab6191678c9ecc8672a1689cc9
|
4
|
+
data.tar.gz: e8d4d9687da7271aee62442fe6d8b2a439e09d14d7f0dc632f3cceab9ea2ea98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93e7b276b5e6ba39e2d52b3a1c0a93b8c02e8f40b711f9f540487d313e57c4b48165800d6a380837577662eca58ee8b13755230b35821cdf24aa9e81f1c9fce0
|
7
|
+
data.tar.gz: 208cd9e50cd8733aef8676bd2df1fa6b225edad8b3575f1cdf4e7b39fcef9dd33ec0c2ab875a8ec3635c16756e24f1394968b3a94bc40c17fc6ea1fc6c56fc93
|
@@ -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
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
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
|
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.
|
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-12-
|
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
|
@@ -509,9 +510,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
509
510
|
version: 2.5.0
|
510
511
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
511
512
|
requirements:
|
512
|
-
- - "
|
513
|
+
- - ">"
|
513
514
|
- !ruby/object:Gem::Version
|
514
|
-
version:
|
515
|
+
version: 1.3.1
|
515
516
|
requirements: []
|
516
517
|
rubygems_version: 3.2.32
|
517
518
|
signing_key:
|