Class: Metanorma::Cli::GitTemplate

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ GitTemplate

Returns a new instance of GitTemplate.



6
7
8
9
# File 'lib/metanorma/cli/git_template.rb', line 6

def initialize(name, options = {})
  @name = name
  @options = options
end

Class Method Details

.download(name, repo:, remote: true) ⇒ Object

Download a template

This interface expects a name, and remote repository link for a template, then it will download that template and it will return the downloaded path.

By default, downloaded tempaltes will be stored in a sub directoy inside metanorma’s tempaltes directory, but if you don’t want then you can set the ‘remote` to false.



48
49
50
# File 'lib/metanorma/cli/git_template.rb', line 48

def self.download(name, repo:, remote: true)
  new(name, repo: repo, remote: remote).download
end

.find_or_download_by(name) ⇒ Object

Find or Download

This interface expects a name / type, and then it will find that template, or if non exist then it will download and return the downloaded path.



34
35
36
# File 'lib/metanorma/cli/git_template.rb', line 34

def self.find_or_download_by(name)
  new(name).find_or_download
end

Instance Method Details

#downloadObject



16
17
18
19
20
21
22
# File 'lib/metanorma/cli/git_template.rb', line 16

def download
  remove!
  clone_git_template(options[:repo])
rescue Git::GitExecuteError => e
  UI.say("Invalid template repository: #{e}!")
  nil
end

#find_or_downloadObject



24
25
26
# File 'lib/metanorma/cli/git_template.rb', line 24

def find_or_download
  find_template || download_template
end

#remove!Object



11
12
13
14
# File 'lib/metanorma/cli/git_template.rb', line 11

def remove!
  remove_template
  true
end