##################################################################
# Base Template Created By: Andrew Kalek                         #
# Read more about this template at: http://blog.anlek.com        #                    
##################################################################

#HELPERS
def win_env?
  RUBY_PLATFORM=~ /win32/
end

def rake(command, options = {})
  env = options[:env] || 'development'
  log 'rake', "#{command} in #{env} environment "
  sudo = win_env?  ? '' : (options[:sudo] ? 'sudo' : '')
  rake_cmd = win_env? ? "rake.bat" : 'rake'
  in_root { run("#{sudo} #{rake_cmd} #{command} RAILS_ENV=#{env}", false) }
end

# base_template.rb
run "echo TODO > README"

if yes?("Using Subdomains?")
  gem 'mbleigh-subdomain-fu', :lib => "subdomain-fu", :source => "http://gems.github.com", :version => ">=0.0.5" 
end
gem 'RedCloth', :lib => 'redcloth'
gem 'mislav-will_paginate', :version => '~> 2.2.3', :lib => 'will_paginate', :source => 'http://gems.github.com'
rake "gems:install"

if yes?("Do you want to use RSpec and Cucumber?")
  gem("rspec", :lib => false, :version => ">=1.2.2", :env => 'test')
  gem("rspec-rails", :lib => false, :version => ">=1.2.2", :env => 'test')
  gem("webrat", :lib => false, :version => ">=0.4.3", :env => 'test')
  gem("cucumber", :lib => false, :version => ">=0.2.2", :env => 'test')
  
  rake "gems:install", :env => 'test'

  generate :rspec
  generate :cucumber
  in_root {run "cucumber#{win_env? ? '.bat': ''} features -n"}
end

if yes?("Use restful_authentication?")
  plugin 'restful-authentication', 
    :git => 'git://github.com/technoweenie/restful-authentication.git'
  
  user_model = ask("Name of User Model? [user]")
  session_model = ask("Name of Session model? [sessions]")
  generate("authenticated", "#{user_model.blank? ? 'user' : user_model}", "#{session_model.blank? ? 'sessions' : session_model}")
end



git :init

file ".gitignore", <<-END
.DS_Store
.eprj
log/*.log
tmp/**/*
config/database.yml
db/*.sqlite3
END

run "touch tmp/.gitignore log/.gitignore vendor/.gitignore"
run "cp config/database.yml config/example_database.yml"

git :add => "."
git :commit => "-m \"initial commit\""
if yes?("Add home controller?")
  generate :controller, "home show"
  route "map.resource 'home' :controller => 'home'"
  route "map.root :controller => 'home'"
  git :rm => "public/index.html"
  
  git :add => "*"
  git :commit => "-m \"adding home controller and removed index.html\""
end
