Class: Nesta::Commands::New

Inherits:
Object
  • Object
show all
Includes:
Command
Defined in:
lib/nesta/commands/new.rb

Instance Method Summary collapse

Methods included from Command

#copy_template, #copy_templates, #fail, #run_process, #template_root, #update_config_yaml

Constructor Details

#initialize(*args) ⇒ New

Returns a new instance of New



8
9
10
11
12
13
14
15
16
17
# File 'lib/nesta/commands/new.rb', line 8

def initialize(*args)
  path = args.shift
  options = args.shift || {}
  path.nil? && (raise UsageError.new('path not specified'))
  if File.exist?(path)
    raise RuntimeError.new("#{path} already exists") 
  end
  @path = path
  @options = options
end

Instance Method Details

#create_repositoryObject



29
30
31
32
33
34
35
36
37
38
# File 'lib/nesta/commands/new.rb', line 29

def create_repository
  FileUtils.cd(@path) do
    File.open('.gitignore', 'w') do |file|
      file.puts %w[._* .*.swp .bundle .DS_Store .sass-cache].join("\n")
    end
    run_process('git', 'init')
    run_process('git', 'add', '.')
    run_process('git', 'commit', '-m', 'Initial commit')
  end
end

#executeObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/nesta/commands/new.rb', line 40

def execute
  make_directories
  templates = {
    'config.ru' => "#{@path}/config.ru",
    'config/config.yml' => "#{@path}/config/config.yml",
    'index.haml' => "#{@path}/content/pages/index.haml",
    'Gemfile' => "#{@path}/Gemfile"
  }
  templates['Rakefile'] = "#{@path}/Rakefile" if have_rake_tasks?
  if @options['vlad']
    templates['config/deploy.rb'] = "#{@path}/config/deploy.rb"
  end
  copy_templates(templates)
  create_repository if @options['git']
end

#have_rake_tasks?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/nesta/commands/new.rb', line 25

def have_rake_tasks?
  @options['vlad']
end

#make_directoriesObject



19
20
21
22
23
# File 'lib/nesta/commands/new.rb', line 19

def make_directories
  %w[content/attachments content/pages].each do |dir|
    FileUtils.mkdir_p(File.join(@path, dir))
  end
end