Class: Nesta::Commands::New

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

Instance Method Summary collapse

Methods included from Command

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

Constructor Details

#initialize(path, options = {}) ⇒ New

Returns a new instance of New.



55
56
57
58
59
60
# File 'lib/nesta/commands.rb', line 55

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

Instance Method Details

#create_repositoryObject



72
73
74
75
76
77
78
79
80
81
# File 'lib/nesta/commands.rb', line 72

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
    system('git', 'init')
    system('git', 'add', '.')
    system('git', 'commit', '-m', 'Initial commit')
  end
end

#executeObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/nesta/commands.rb', line 83

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)


68
69
70
# File 'lib/nesta/commands.rb', line 68

def have_rake_tasks?
  @options['vlad']
end

#make_directoriesObject



62
63
64
65
66
# File 'lib/nesta/commands.rb', line 62

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