class Metanorma::Cli::GitTemplate

Attributes

name[R]
options[R]

Public Class Methods

download(name, repo:, remote: true) click to toggle source

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.

# 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) click to toggle source

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.

# File lib/metanorma/cli/git_template.rb, line 34
def self.find_or_download_by(name)
  new(name).find_or_download
end
new(name, options = {}) click to toggle source
# File lib/metanorma/cli/git_template.rb, line 6
def initialize(name, options = {})
  @name = name
  @options = options
end

Public Instance Methods

download() click to toggle source
# File lib/metanorma/cli/git_template.rb, line 16
def download
  remove!
  clone_git_template(options[:repo])
rescue Git::GitExecuteError
  UI.say("Invalid template reoository!")
  nil
end
find_or_download() click to toggle source
# File lib/metanorma/cli/git_template.rb, line 24
def find_or_download
  find_template || download_template
end
remove!() click to toggle source
# File lib/metanorma/cli/git_template.rb, line 11
def remove!
  remove_template
  true
end

Private Instance Methods

build_templates_path() click to toggle source
# File lib/metanorma/cli/git_template.rb, line 96
def build_templates_path
  sub_directory = options[:remote] == true ? "git" : nil
  Metanorma::Cli.templates_path.join(sub_directory.to_s)
end
clone_git_template(repo) click to toggle source
# File lib/metanorma/cli/git_template.rb, line 76
def clone_git_template(repo)
  clone = Git.clone(repo, name, path: templates_path)
  template_path unless clone.nil?
end
download_template() click to toggle source
# File lib/metanorma/cli/git_template.rb, line 62
def download_template
  template_repo = git_repos[name.to_sym]

  if template_repo
    clone_git_template(template_repo)
  end
end
find_template() click to toggle source
# File lib/metanorma/cli/git_template.rb, line 56
def find_template
  if template_path.exist?
    template_path
  end
end
git_repos() click to toggle source
# File lib/metanorma/cli/git_template.rb, line 81
def git_repos
  @git_repos ||= {
    csd: "https://github.com/metanorma/mn-templates-csd",
    ogc: "https://github.com/metanorma/mn-templates-ogc",
    iso: "https://github.com/metanorma/mn-templates-iso",
    iec: "https://github.com/metanorma/mn-templates-iec",
    itu: "https://github.com/metanorma/mn-templates-itu",
    ietf: "https://github.com/metanorma/mn-templates-ietf",
  }
end
remove_template() click to toggle source
# File lib/metanorma/cli/git_template.rb, line 70
def remove_template
  if template_path.exist?
    template_path.rmtree
  end
end
template_path() click to toggle source
# File lib/metanorma/cli/git_template.rb, line 101
def template_path
  @template_path ||= templates_path.join(name.to_s.downcase)
end
templates_path() click to toggle source
# File lib/metanorma/cli/git_template.rb, line 92
def templates_path
  @templates_path ||= build_templates_path
end