metanorma-cli 1.4.3 → 1.4.6pre
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/command.rb +16 -4
- data/lib/metanorma/cli/commands/config.rb +11 -6
- data/lib/metanorma/cli/commands/site.rb +4 -2
- data/lib/metanorma/cli/site_generator.rb +34 -6
- data/lib/metanorma/cli/thor_with_config.rb +5 -4
- data/lib/metanorma/cli/version.rb +1 -1
- data/metanorma-cli.gemspec +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f816a508f6849109c1993d57abe21d440e0ba7a5a9889ac3b94af22cece3460
|
4
|
+
data.tar.gz: 9cd0d1d840404896b0fc84b7538fc92cf0c871cad618e29229af4323682b24a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c52209957baded4b395c2294eaf2d1101dd25733d53847f8c9aaedb9cf99cf707a7d2327a0803732a90b61bf1d902126cd788543af78685cdf6487618ab5288
|
7
|
+
data.tar.gz: 725c5b172877a8819bea002e1ac4d7a5403d17e338c272a03ef306060562ac0dda09b89e1714fab9d49c6a613d7c5d155a63169d07d32e506f2cf53eb8ca66ff
|
@@ -39,10 +39,8 @@ module Metanorma
|
|
39
39
|
|
40
40
|
def compile(file_name = nil)
|
41
41
|
if file_name && !options[:version]
|
42
|
-
|
43
|
-
|
44
|
-
errs.each { |e| Util.log e, :error }
|
45
|
-
exit(1) if errs.any?
|
42
|
+
documents = select_wildcard_documents(file_name) || [file_name]
|
43
|
+
documents.each { |document| compile_document(document, options.dup) }
|
46
44
|
|
47
45
|
elsif options[:version]
|
48
46
|
invoke(:version, [], type: options[:type], format: options[:format])
|
@@ -198,6 +196,20 @@ module Metanorma
|
|
198
196
|
|
199
197
|
UI.table(["Type", "Input", "Supported output format"], table_data)
|
200
198
|
end
|
199
|
+
|
200
|
+
def select_wildcard_documents(filename)
|
201
|
+
if filename.include?("*")
|
202
|
+
Dir.glob(Pathname.new(filename))
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
def compile_document(filename, options)
|
207
|
+
Metanorma::Cli.load_flavors
|
208
|
+
errors = Metanorma::Cli::Compiler.compile(filename, options)
|
209
|
+
errors.each { |error| Util.log(error, :error) }
|
210
|
+
|
211
|
+
exit(1) if errors.any?
|
212
|
+
end
|
201
213
|
end
|
202
214
|
end
|
203
215
|
end
|
@@ -10,9 +10,9 @@ module Metanorma
|
|
10
10
|
|
11
11
|
desc "get NAME", "Get config value"
|
12
12
|
def get(name = nil)
|
13
|
-
config, config_path = load_config(options
|
13
|
+
config, config_path = load_config(options[:global], create_default_config: false)
|
14
14
|
|
15
|
-
if name.nil?
|
15
|
+
if name.nil? && File.exists?(config_path)
|
16
16
|
UI.say File.read(config_path, encoding: "utf-8")
|
17
17
|
else
|
18
18
|
UI.say(config.dig(*dig_path(name)) || "nil")
|
@@ -21,7 +21,7 @@ module Metanorma
|
|
21
21
|
|
22
22
|
desc "set NAME VALUE", "Set config value"
|
23
23
|
def set(name, value = nil)
|
24
|
-
config, config_path = load_config(options
|
24
|
+
config, config_path = load_config(options[:global])
|
25
25
|
|
26
26
|
value = try_convert_to_bool(value)
|
27
27
|
ypath = dig_path(name)
|
@@ -32,7 +32,7 @@ module Metanorma
|
|
32
32
|
|
33
33
|
desc "unset [name]", "Set config [value] for [name]"
|
34
34
|
def unset(name)
|
35
|
-
config, config_path = load_config(options
|
35
|
+
config, config_path = load_config(options[:global])
|
36
36
|
|
37
37
|
ypath = dig_path(name)
|
38
38
|
deep_unset(config, *ypath)
|
@@ -75,9 +75,14 @@ module Metanorma
|
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
|
-
def load_config(global_config)
|
78
|
+
def load_config(global_config, create_default_config: true)
|
79
79
|
config_path = Metanorma::Cli.config_path(global_config)
|
80
|
-
|
80
|
+
|
81
|
+
unless File.exists?(config_path) || create_default_config
|
82
|
+
config_path = Metanorma::Cli.config_path(true)
|
83
|
+
end
|
84
|
+
|
85
|
+
save_default_config(config_path)
|
81
86
|
|
82
87
|
[::YAML::load_file(config_path).symbolize_all_keys || {}, config_path]
|
83
88
|
end
|
@@ -6,7 +6,7 @@ module Metanorma
|
|
6
6
|
module Cli
|
7
7
|
module Commands
|
8
8
|
class Site < ThorWithConfig
|
9
|
-
desc "generate SOURCE_PATH", "Generate site from collection"
|
9
|
+
desc "generate [SOURCE_PATH]", "Generate site from collection"
|
10
10
|
option :config, aliases: "-c", desc: "Metanorma configuration file"
|
11
11
|
option(
|
12
12
|
:output_dir,
|
@@ -18,8 +18,10 @@ module Metanorma
|
|
18
18
|
"presented (WARNING: do know what you are agreeing with!)"
|
19
19
|
option :no_install_fonts, type: :boolean, desc: "Skip the font installation process"
|
20
20
|
option :continue_without_fonts, type: :boolean, desc: "Continue processing even when fonts are missing"
|
21
|
+
option :stylesheet, alias: "-s", desc: "Stylesheet file path for rendering HTML page"
|
22
|
+
option :template_dir, alias: "-t", desc: "Liquid template directory to render site design"
|
21
23
|
|
22
|
-
def generate(source_path)
|
24
|
+
def generate(source_path = Dir.pwd)
|
23
25
|
Cli::SiteGenerator.generate(source_path, options, filter_compile_options(options))
|
24
26
|
UI.say("Site has been generated at #{options[:output_dir]}")
|
25
27
|
rescue Cli::Errors::InvalidManifestFileError
|
@@ -10,7 +10,11 @@ module Metanorma
|
|
10
10
|
@site_path = options.fetch(:output_dir, "site").to_s
|
11
11
|
@asset_folder = options.fetch(:asset_folder, "documents").to_s
|
12
12
|
@collection_name = options.fetch(:collection_name, "documents.xml")
|
13
|
+
|
13
14
|
@manifest_file = find_realpath(options.fetch(:config, default_config))
|
15
|
+
@template_dir = options.fetch(:template_dir, template_data("path"))
|
16
|
+
@stylesheet = options.fetch(:stylesheet, template_data("stylesheet"))
|
17
|
+
|
14
18
|
@compile_options = compile_options
|
15
19
|
ensure_site_asset_directory!
|
16
20
|
end
|
@@ -31,8 +35,8 @@ module Metanorma
|
|
31
35
|
|
32
36
|
private
|
33
37
|
|
34
|
-
attr_reader :source, :asset_folder, :asset_directory
|
35
|
-
attr_reader :
|
38
|
+
attr_reader :source, :asset_folder, :asset_directory, :site_path
|
39
|
+
attr_reader :manifest_file, :collection_name, :stylesheet, :template_dir
|
36
40
|
|
37
41
|
def find_realpath(source_path)
|
38
42
|
Pathname.new(source_path.to_s).realpath if source_path
|
@@ -70,18 +74,25 @@ module Metanorma
|
|
70
74
|
def compile(source)
|
71
75
|
UI.info("Compiling #{source} ...")
|
72
76
|
|
73
|
-
|
77
|
+
options = @compile_options.merge(
|
78
|
+
format: :asciidoc, output_dir: build_asset_output_directory(source)
|
79
|
+
)
|
74
80
|
|
75
|
-
Metanorma::Cli::Compiler.compile(source.to_s,
|
81
|
+
Metanorma::Cli::Compiler.compile(source.to_s, options)
|
76
82
|
end
|
77
83
|
|
78
84
|
def convert_to_html_page(collection, page_name)
|
79
85
|
UI.info("Generating html site in #{site_path} ...")
|
80
86
|
|
81
|
-
Relaton::Cli::XMLConvertor.to_html(collection)
|
87
|
+
Relaton::Cli::XMLConvertor.to_html(collection, stylesheet, template_dir)
|
82
88
|
File.rename(Pathname.new(collection).sub_ext(".html").to_s, page_name)
|
83
89
|
end
|
84
90
|
|
91
|
+
def template_data(node)
|
92
|
+
template_node = manifest[:template]
|
93
|
+
template_node&.fetch(node.to_s, nil)
|
94
|
+
end
|
95
|
+
|
85
96
|
def manifest
|
86
97
|
@manifest ||= config_from_manifest || {
|
87
98
|
files: [], collection_name: "", collection_organization: ""
|
@@ -107,6 +118,8 @@ module Metanorma
|
|
107
118
|
collection_organization: extract_config_data(
|
108
119
|
manifest["metanorma"]["collection"], "organization"
|
109
120
|
),
|
121
|
+
|
122
|
+
template: extract_config_data(manifest["metanorma"], "template"),
|
110
123
|
}
|
111
124
|
rescue NoMethodError
|
112
125
|
raise Errors::InvalidManifestFileError.new("Invalid manifest file")
|
@@ -127,7 +140,22 @@ module Metanorma
|
|
127
140
|
asset_path = [site_path, asset_folder].join("/")
|
128
141
|
@asset_directory = Pathname.new(Dir.pwd).join(asset_path)
|
129
142
|
|
130
|
-
|
143
|
+
create_directory_if_not_present!(@asset_directory)
|
144
|
+
end
|
145
|
+
|
146
|
+
def create_directory_if_not_present!(directory)
|
147
|
+
FileUtils.mkdir_p(directory) unless directory.exist?
|
148
|
+
end
|
149
|
+
|
150
|
+
def build_asset_output_directory(source)
|
151
|
+
sub_directory = Pathname.new(source.gsub(@source.to_s, "")).dirname.to_s
|
152
|
+
sub_directory.gsub!("/sources", "")
|
153
|
+
sub_directory.slice!(0)
|
154
|
+
|
155
|
+
output_directory = asset_directory.join(sub_directory)
|
156
|
+
create_directory_if_not_present!(output_directory)
|
157
|
+
|
158
|
+
output_directory
|
131
159
|
end
|
132
160
|
end
|
133
161
|
end
|
@@ -7,15 +7,16 @@ module Metanorma
|
|
7
7
|
class ThorWithConfig < Thor
|
8
8
|
no_commands do
|
9
9
|
def options
|
10
|
-
@options_cache
|
11
10
|
original_options = super.to_hash.symbolize_all_keys
|
12
|
-
|
11
|
+
Thor::CoreExt::HashWithIndifferentAccess.new(
|
12
|
+
Metanorma::Cli::Commands::Config.load_configs(original_options)
|
13
|
+
)
|
13
14
|
end
|
14
15
|
|
15
16
|
def filter_compile_options(options)
|
16
17
|
options.select do |k, _|
|
17
|
-
%
|
18
|
-
end
|
18
|
+
%w[agree_to_terms no_install_fonts continue_without_fonts].include?(k)
|
19
|
+
end.symbolize_all_keys
|
19
20
|
end
|
20
21
|
end
|
21
22
|
end
|
data/metanorma-cli.gemspec
CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.required_ruby_version = '>= 2.4.0'
|
26
26
|
|
27
27
|
spec.add_development_dependency "pry"
|
28
|
-
spec.add_development_dependency "rake", "~>
|
28
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
29
29
|
spec.add_development_dependency "rspec", "~> 3.0"
|
30
30
|
spec.add_development_dependency "byebug", "~> 10.0"
|
31
31
|
spec.add_development_dependency "rspec-command", "~> 1.0.3"
|
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.4.
|
4
|
+
version: 1.4.6pre
|
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
|
+
date: 2021-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '13.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '13.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -494,11 +494,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
494
494
|
version: 2.4.0
|
495
495
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
496
496
|
requirements:
|
497
|
-
- - "
|
497
|
+
- - ">"
|
498
498
|
- !ruby/object:Gem::Version
|
499
|
-
version:
|
499
|
+
version: 1.3.1
|
500
500
|
requirements: []
|
501
|
-
rubygems_version: 3.
|
501
|
+
rubygems_version: 3.1.4
|
502
502
|
signing_key:
|
503
503
|
specification_version: 4
|
504
504
|
summary: Metanorma is the standard of standards; the metanorma gem allows you to create
|