Class: Skeletal

Inherits:
Object
  • Object
show all
Defined in:
lib/skeletal.rb

Class Method Summary collapse

Class Method Details

.create!(app_name) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/skeletal.rb', line 4

def self.create! app_name
  # Create the initial directory
  # FileUtils.mkpath(File.expand_path(directory))
  
  @app_dir = File.expand_path(app_name)
  puts "Generating application #{app_name}..."
  
  # Create the basic folder structure

folders = %w( app/models app/helpers app/views app/views/layouts lib logs config tasks db/migrations public/images public/js public/css )
unless options[:classic]
	folders << 'app/routes'
end
if options[:rspec]
	folders << 'spec'
end
if options[:cucumber]
	folders << %w( features/step_definitions features/support )
end

folders.flatten.each do |dir|
	puts '> '+dir
	FileUtils.mkpath(File.join(@app_dir, dir))
end

# Create the application file
@app_file = File.join(File.expand_path(app_name), 'app', "#{app_name}.rb")
@class_name = app_name.downcase.gsub(/[-_\s]+/, ' ').split(' ').map{|word| word.capitalize }.join
puts '> '+@app_file
File.open(@app_file, 'w') do |file|
	file.write(%Q{
require 'rubygems'
require 'sinatra'

class #{@class_name} < Sinatra::Application

	configure do
# Configuration here
	end
	
end
})
end

# Add a few files
['Gemfile', '.gitignore', 'spec/spec_helper.rb', "spec/#{app_name}_spec.rb" ].each do |file|
	puts '> '+file
	FileUtils.touch(File.join(@app_dir, file))
end
  
  # Add everything to git
`cd #{@app_dir} && git init && git add . && git commit -m "Initial Commit"`
end