Class: AppArchetype::Commands::NewTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/app_archetype/commands/new_template.rb

Overview

Creates new blank template for a user

Instance Method Summary collapse

Constructor Details

#initialize(template_dir, options = Hashie::Mash.new) ⇒ NewTemplate

Returns a new instance of NewTemplate.



7
8
9
10
11
# File 'lib/app_archetype/commands/new_template.rb', line 7

def initialize(template_dir, options = Hashie::Mash.new)
  @template_dir = template_dir
  @options = options
  @prompt = TTY::Prompt.new
end

Instance Method Details

#runObject

Renders a new empty template and manifest

First it looks to the name option for a relative path from the template dir

If this is not provided then the user is prompted for input.

Once we have a name, the destination folder is created and the generator renders an empty template there.

If the operation is successful then a success message is printed to STDOUT confirming this.



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/app_archetype/commands/new_template.rb', line 28

def run
  rel = @options.name
  rel ||= @prompt.ask('Please enter a name for the new template')

  dest = File.join(@template_dir, rel)
  FileUtils.mkdir_p(dest)

  name = File.basename(rel)
  AppArchetype::Generators.render_empty_template(name, dest)

  puts("✔ Template `#{name}` created at #{dest}")
end