metanorma-cli 1.3.9 → 1.4.0pre

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: a03b03e99303cba8dba1f9cff78ee1e8b2398f717619b193460a58c8bbcd423d
4
- data.tar.gz: 00a06a5126c12f57e1e5a7a77337a600606cd25b026439865012fb41907af664
3
+ metadata.gz: 88924f3243331ffe69a875d04a60ba95b22a7dc2a580b3d7019f919a4b930da7
4
+ data.tar.gz: 238e5f13c374e907ab8d4245e1ac3794891c6cb24b9da0e3c4abd66c982e9c33
5
5
  SHA512:
6
- metadata.gz: 32ae08f01d0435a30d418978eeb8baa0c482ae7e707de6bf12562dc4899c3dc37bef83b6fbdb7778899e37a659dc0bdf2d30bb8abb298c19e8bd8724eedac01a
7
- data.tar.gz: 184167a6dca3dc0542e0ff1abf90c7cc96ba92135592939bc28658827e8315a0d6d932578c41a074a3075a20ad4b82593b39ce0e72ebb0093584eb0cc6f27b56
6
+ metadata.gz: e45a497c87d344efae6f3c5783ad3d1508ef405dba142adf8044d1fc77c733e2c334091bb263389d9ce4e61398ecb3ac3d3f759f4f81887293beff5e6ccf8c61
7
+ data.tar.gz: 77e5b0b96d5e7ebcb549c3f018f794998c3512165aa13ddc64974ea5ce163b32b919b593206849180a0d22d104d1a275af2be37696f21a49edeb3fec624b8d36
@@ -285,6 +285,21 @@ repository.
285
285
  metanorma template-repo add my-iso https://github.com/you/my-iso-template
286
286
  ----
287
287
 
288
+ === Generate metanorma minisite
289
+
290
+ The `site` interface allows you to manage mini site generation using the CLI.
291
+ To generate a mini site you need to provide the `SOURCE_PATH` and the CLI will
292
+ take care of compiling each of those files and generate deployable site in the
293
+ provided output directory.
294
+
295
+ This interface also supports a YAML manifest file that can be used to customize
296
+ the site generation process. You can check more details here: link:./spec/fixtures/metanorma.yml[metanorma.yml]
297
+
298
+ [source, sh]
299
+ ----
300
+ metanorma site generate SOURCE_PATH -o OUTPUT_PATH -c metanorma.yml
301
+ ----
302
+
288
303
  == Credits
289
304
 
290
305
  This gem is developed, maintained and funded by https://www.metanorma.com/docs/getting-started/[Ribose Inc.]
@@ -10,6 +10,7 @@ module Metanorma
10
10
  "metanorma-iec",
11
11
  "metanorma-ietf",
12
12
  #"metanorma-gb",
13
+ "metanorma-bipm",
13
14
  "metanorma-cc",
14
15
  "metanorma-csa",
15
16
  "metanorma-iho",
@@ -3,6 +3,7 @@ require "metanorma/cli/compiler"
3
3
  require "metanorma/cli/generator"
4
4
  require "metanorma/cli/git_template"
5
5
  require "metanorma/cli/commands/template_repo"
6
+ require "metanorma/cli/commands/site"
6
7
  require "metanorma"
7
8
 
8
9
  module Metanorma
@@ -92,6 +93,9 @@ module Metanorma
92
93
  desc "template-repo", "Manage metanorma templates repository"
93
94
  subcommand :template_repo, Metanorma::Cli::Commands::TemplateRepo
94
95
 
96
+ desc "site", "Manage site for metanorma collections"
97
+ subcommand :site, Metanorma::Cli::Commands::Site
98
+
95
99
  private
96
100
 
97
101
  def single_type_extensions(type)
@@ -0,0 +1,26 @@
1
+ require "pathname"
2
+ require "metanorma/cli/site_generator"
3
+
4
+ module Metanorma
5
+ module Cli
6
+ module Commands
7
+ class Site < Thor
8
+ desc "site generate SOURCE_PATH", "Geneate site from collection"
9
+ option :config, aliases: "-c", desc: "The metanorma configuration file"
10
+ option(
11
+ :output_dir,
12
+ aliases: "-o",
13
+ default: Pathname.new(Dir.pwd).join("site").to_s,
14
+ desc: "Output directory for the generated site",
15
+ )
16
+
17
+ def generate(source_path)
18
+ Cli::SiteGenerator.generate(source_path, options.dup)
19
+ UI.say("Site has been generated at #{options[:output_dir]}")
20
+ rescue Cli::Errors::InvalidManifestFileError
21
+ UI.error("Invalid data in: #{options[:config]}")
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -4,6 +4,7 @@ module Metanorma
4
4
  class DuplicateTemplateError < StandardError; end
5
5
 
6
6
  class FileNotFoundError < StandardError; end
7
+ class InvalidManifestFileError < StandardError; end
7
8
  end
8
9
  end
9
10
  end
@@ -0,0 +1,130 @@
1
+ require "yaml"
2
+ require "pathname"
3
+ require "fileutils"
4
+
5
+ module Metanorma
6
+ module Cli
7
+ class SiteGenerator
8
+ def initialize(source, options = {})
9
+ @source = find_realpath(source)
10
+ @site_path = options.fetch(:output_dir, "site").to_s
11
+ @manifest_file = find_realpath(options.fetch(:config, nil))
12
+ @asset_folder = options.fetch(:asset_folder, "documents").to_s
13
+ @collection_name = options.fetch(:collection_name, "documents.xml")
14
+
15
+ ensure_site_asset_directory!
16
+ end
17
+
18
+ def self.generate(source, options = {})
19
+ new(source, options).generate
20
+ end
21
+
22
+ def generate
23
+ site_directory = asset_directory.join("..")
24
+
25
+ Dir.chdir(site_directory) do
26
+ select_source_files.each { |source| compile(source) }
27
+
28
+ build_collection_file(collection_name)
29
+ convert_to_html_page(collection_name, "index.html")
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ attr_reader :source, :asset_folder, :asset_directory
36
+ attr_reader :site_path, :manifest_file, :collection_name
37
+
38
+ def find_realpath(source_path)
39
+ Pathname.new(source_path.to_s).realpath if source_path
40
+ rescue Errno::ENOENT
41
+ source_path
42
+ end
43
+
44
+ def select_source_files
45
+ files = source_from_manifest
46
+
47
+ if files.empty?
48
+ files = Dir[File.join(source, "**", "*.adoc")]
49
+ end
50
+
51
+ files.flatten.uniq.reject { |file| File.directory?(file) }
52
+ end
53
+
54
+ def build_collection_file(collection_name)
55
+ collection_path = [site_path, collection_name].join("/")
56
+ UI.info("Building collection file: #{collection_path} ...")
57
+
58
+ Relaton::Cli::RelatonFile.concatenate(
59
+ asset_folder,
60
+ collection_name,
61
+ title: manifest[:collection_name],
62
+ organization: manifest[:collection_organization],
63
+ )
64
+ end
65
+
66
+ def compile(source)
67
+ UI.info("Compiling #{source} ...")
68
+
69
+ Metanorma::Cli::Compiler.compile(
70
+ source.to_s, format: :asciidoc, "output-dir" => asset_folder
71
+ )
72
+ end
73
+
74
+ def convert_to_html_page(collection, page_name)
75
+ UI.info("Generating html site in #{site_path} ...")
76
+
77
+ Relaton::Cli::XMLConvertor.to_html(collection)
78
+ File.rename(Pathname.new(collection).sub_ext(".html").to_s, page_name)
79
+ end
80
+
81
+ def manifest
82
+ @manifest ||= config_from_manifest || {
83
+ files: [], collection_name: "", collection_organization: ""
84
+ }
85
+ end
86
+
87
+ def config_from_manifest
88
+ if manifest_file
89
+ manifest_config(YAML.safe_load(File.read(manifest_file.to_s)))
90
+ end
91
+ end
92
+
93
+ def manifest_config(manifest)
94
+ {
95
+ files: extract_config_data(
96
+ manifest["metanorma"]["source"], "files"
97
+ ) || [],
98
+
99
+ collection_name: extract_config_data(
100
+ manifest["relaton"]["collection"], "name"
101
+ ),
102
+
103
+ collection_organization: extract_config_data(
104
+ manifest["relaton"]["collection"], "organization"
105
+ ),
106
+ }
107
+ rescue NoMethodError
108
+ raise Errors::InvalidManifestFileError.new("Invalid manifest file")
109
+ end
110
+
111
+ def extract_config_data(node, key)
112
+ node ? node[key] : nil
113
+ end
114
+
115
+ def source_from_manifest
116
+ @source_from_manifest ||= manifest[:files].map do |source_file|
117
+ file_path = source.join(source_file).to_s
118
+ file_path.include?("*") ? Dir.glob(file_path) : file_path
119
+ end.flatten
120
+ end
121
+
122
+ def ensure_site_asset_directory!
123
+ asset_path = [site_path, asset_folder].join("/")
124
+ @asset_directory = Pathname.new(Dir.pwd).join(asset_path)
125
+
126
+ FileUtils.mkdir_p(@asset_directory) unless @asset_directory.exist?
127
+ end
128
+ end
129
+ end
130
+ end
@@ -11,6 +11,10 @@ module Metanorma
11
11
  new.say(message)
12
12
  end
13
13
 
14
+ def self.info(message)
15
+ new.say(["[info]", message].join(": "))
16
+ end
17
+
14
18
  def self.error(message)
15
19
  new.error(message)
16
20
  end
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Cli
3
- VERSION = "1.3.9"
3
+ VERSION = "1.4.0pre"
4
4
  end
5
5
  end
@@ -42,9 +42,10 @@ Gem::Specification.new do |spec|
42
42
  #spec.add_runtime_dependency "metanorma-gb", "~> 1.5.0"
43
43
  spec.add_runtime_dependency "metanorma-iec", "~> 1.2.0"
44
44
  spec.add_runtime_dependency "metanorma-cc", "~> 1.6.0"
45
- spec.add_runtime_dependency "metanorma-csa", "~> 1.6.0"
45
+ spec.add_runtime_dependency "metanorma-csa", "~> 1.7.0"
46
46
  #spec.add_runtime_dependency 'metanorma-ribose', "~> 1.6.0"
47
47
  spec.add_runtime_dependency "metanorma-m3aawg", "~> 1.6.0"
48
+ spec.add_runtime_dependency "metanorma-bipm", "~> 1.0.0"
48
49
  spec.add_runtime_dependency "metanorma-generic", "~> 1.8.0"
49
50
  spec.add_runtime_dependency "metanorma-standoc", "~> 1.6.0"
50
51
  #spec.add_runtime_dependency 'metanorma-mpfa', "~> 0.5.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.3.9
4
+ version: 1.4.0pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-04 00:00:00.000000000 Z
11
+ date: 2020-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -226,14 +226,14 @@ dependencies:
226
226
  requirements:
227
227
  - - "~>"
228
228
  - !ruby/object:Gem::Version
229
- version: 1.6.0
229
+ version: 1.7.0
230
230
  type: :runtime
231
231
  prerelease: false
232
232
  version_requirements: !ruby/object:Gem::Requirement
233
233
  requirements:
234
234
  - - "~>"
235
235
  - !ruby/object:Gem::Version
236
- version: 1.6.0
236
+ version: 1.7.0
237
237
  - !ruby/object:Gem::Dependency
238
238
  name: metanorma-m3aawg
239
239
  requirement: !ruby/object:Gem::Requirement
@@ -248,6 +248,20 @@ dependencies:
248
248
  - - "~>"
249
249
  - !ruby/object:Gem::Version
250
250
  version: 1.6.0
251
+ - !ruby/object:Gem::Dependency
252
+ name: metanorma-bipm
253
+ requirement: !ruby/object:Gem::Requirement
254
+ requirements:
255
+ - - "~>"
256
+ - !ruby/object:Gem::Version
257
+ version: 1.0.0
258
+ type: :runtime
259
+ prerelease: false
260
+ version_requirements: !ruby/object:Gem::Requirement
261
+ requirements:
262
+ - - "~>"
263
+ - !ruby/object:Gem::Version
264
+ version: 1.0.0
251
265
  - !ruby/object:Gem::Dependency
252
266
  name: metanorma-generic
253
267
  requirement: !ruby/object:Gem::Requirement
@@ -447,11 +461,13 @@ files:
447
461
  - lib/metanorma-cli.rb
448
462
  - lib/metanorma/cli.rb
449
463
  - lib/metanorma/cli/command.rb
464
+ - lib/metanorma/cli/commands/site.rb
450
465
  - lib/metanorma/cli/commands/template_repo.rb
451
466
  - lib/metanorma/cli/compiler.rb
452
467
  - lib/metanorma/cli/errors.rb
453
468
  - lib/metanorma/cli/generator.rb
454
469
  - lib/metanorma/cli/git_template.rb
470
+ - lib/metanorma/cli/site_generator.rb
455
471
  - lib/metanorma/cli/template_repo.rb
456
472
  - lib/metanorma/cli/ui.rb
457
473
  - lib/metanorma/cli/version.rb
@@ -475,9 +491,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
475
491
  version: 2.4.0
476
492
  required_rubygems_version: !ruby/object:Gem::Requirement
477
493
  requirements:
478
- - - ">="
494
+ - - ">"
479
495
  - !ruby/object:Gem::Version
480
- version: '0'
496
+ version: 1.3.1
481
497
  requirements: []
482
498
  rubygems_version: 3.0.3
483
499
  signing_key: