Class: Metanorma::Cli::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/metanorma/cli/generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type:, doctype:, **options) ⇒ Generator

Returns a new instance of Generator.



9
10
11
12
13
14
15
# File 'lib/metanorma/cli/generator.rb', line 9

def initialize(name, type:, doctype:, **options)
  @name = name
  @type = type
  @doctype = doctype
  @options = options
  @template = options.fetch(:template, nil)
end

Class Method Details

.run(name, type:, doctype:, **options) ⇒ Object

Generator.run

This interface find / downloads the specified template and then run the generator to create a new metanorma document.

By default it usages the default templates but user can also provide a remote git teplate repo using –template ooption, and in that case it will use that template.



41
42
43
# File 'lib/metanorma/cli/generator.rb', line 41

def self.run(name, type:, doctype:, **options)
  new(name, **options.merge(type: type, doctype: doctype)).run
end

Instance Method Details

#runObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/metanorma/cli/generator.rb', line 17

def run
  if Cli.writable_templates_path?
    if name && document_path.exist?
      return unless overwrite?(document_path)

      document_path.rmtree
    end

    create_metanorma_document
  end
rescue Errno::EACCES
  permission_missing_error
end