metanorma-cli 1.4.4 → 1.4.7pre

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e9deaa593010eb7f9d96c58869a852e1c11d00324ba1b1b4dca8e875c334aed
4
- data.tar.gz: abca4cf485a7b9f74e9f38cd20ba0af01ddde93ae7ee8e04cfaa7b813f0fbd4a
3
+ metadata.gz: 84fa2274950b2c9c8da2117de43fa05558192899f2c4b127d5f6f382b96cd7ea
4
+ data.tar.gz: cd45f93af207ac93aefb16bdd488ecca61827feea75e16ede69ea35bdc5c24cb
5
5
  SHA512:
6
- metadata.gz: e39d75f8a89d42e92ee90088d7353164883d9f2da55f6c7dfee031c4fa27f73b757a7ef41c5d1a1c83c927edfd2ce74b6e1d18f6a5530c4c1f66ff8c23242c0a
7
- data.tar.gz: 2e5e5030d31a17c1b24a94bf8f58ba7a59b777b41c665734a3f347296f4b7429718c05016328723e8d012e5a7ed92ae50345e94d5f05bdc9d7126028d2e27e5e
6
+ metadata.gz: 286a3da9a613f393f40de552c2dcc5c9af6b9340ab1c326ceec5d1e35d51d19eff4c2d40f8f93edbad4453da692ea830c26c93f8b3e83a37a6c6af8783234225
7
+ data.tar.gz: b407066259e6adafc760e1af9926160facdd5bf0f3bb0718bf8e8119153f14d7a42e4784ee60fe1df7c9545146014c4f981f5439c1637236407b960d3346c892
@@ -10,6 +10,9 @@ require "metanorma"
10
10
  module Metanorma
11
11
  module Cli
12
12
  class Command < ThorWithConfig
13
+ class_option :no_progress, aliases: "-s", type: :boolean, default: true,
14
+ desc: "Don't show progress for long running tasks (like download)"
15
+
13
16
  desc "new NAME", "Create new Metanorma document"
14
17
  option :type, aliases: "-t", required: true, desc: "Document type"
15
18
  option :doctype, aliases: "-d", required: true, desc: "Metanorma doctype"
@@ -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.global)
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.global)
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.global)
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
- save_default_config(config_path) unless File.exists?(config_path)
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
@@ -18,6 +18,8 @@ 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
24
  def generate(source_path = Dir.pwd)
23
25
  Cli::SiteGenerator.generate(source_path, options, filter_compile_options(options))
@@ -39,7 +39,7 @@ module Metanorma
39
39
  # ooption, and in that case it will use that template.
40
40
  #
41
41
  def self.run(name, type:, doctype:, **options)
42
- new(name, options.merge(type: type, doctype: doctype)).run
42
+ new(name, **options.merge(type: type, doctype: doctype)).run
43
43
  end
44
44
 
45
45
  private
@@ -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 :site_path, :manifest_file, :collection_name
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
- opts = @compile_options.merge(format: :asciidoc, output_dir: asset_directory)
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, opts)
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
- FileUtils.mkdir_p(@asset_directory) unless @asset_directory.exist?
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
- @options_cache = Metanorma::Cli::Commands::Config.load_configs(original_options)
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
- %i[agree_to_terms no_install_fonts continue_without_fonts].include?(k)
18
- end
18
+ %w[agree_to_terms no_install_fonts continue_without_fonts no_progress].include?(k)
19
+ end.symbolize_all_keys
19
20
  end
20
21
  end
21
22
  end
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Cli
3
- VERSION = "1.4.4"
3
+ VERSION = "1.4.7pre"
4
4
  end
5
5
  end
@@ -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", "~> 12.0"
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"
@@ -35,6 +35,7 @@ Gem::Specification.new do |spec|
35
35
  spec.add_development_dependency "simplecov", "~> 0.15"
36
36
  # need for dev because locally compiled metanorma-iso does not have css
37
37
  spec.add_development_dependency "sassc"
38
+ spec.add_development_dependency "rubocop", "~> 1.5.2"
38
39
 
39
40
  spec.add_runtime_dependency "thor", "~> 1.0"
40
41
  spec.add_runtime_dependency "metanorma-iso", "~> 1.7.0"
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
4
+ version: 1.4.7pre
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-02-08 00:00:00.000000000 Z
11
+ date: 2021-03-29 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: '12.0'
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: '12.0'
40
+ version: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 1.5.2
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 1.5.2
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: thor
155
169
  requirement: !ruby/object:Gem::Requirement
@@ -494,9 +508,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
494
508
  version: 2.4.0
495
509
  required_rubygems_version: !ruby/object:Gem::Requirement
496
510
  requirements:
497
- - - ">="
511
+ - - ">"
498
512
  - !ruby/object:Gem::Version
499
- version: '0'
513
+ version: 1.3.1
500
514
  requirements: []
501
515
  rubygems_version: 3.1.4
502
516
  signing_key: