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(*args) ⇒ New

Returns a new instance of New.



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

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



93
94
95
96
97
98
99
100
101
102
# File 'lib/nesta/commands.rb', line 93

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



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/nesta/commands.rb', line 104

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)


89
90
91
# File 'lib/nesta/commands.rb', line 89

def have_rake_tasks?
  @options['vlad']
end

#make_directoriesObject



83
84
85
86
87
# File 'lib/nesta/commands.rb', line 83

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