require "net/http"
require "net/https"
require "uri"
require 'rbconfig'

say "Building Application with Gypsum..."

def get_remote_https_file(source, destination)
  uri = URI.parse(source)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  request = Net::HTTP::Get.new(uri.request_uri)
  response = http.request(request)
  path = File.join(destination_root, destination)
  File.open(path, "w") { |file| file.write(response.body) }
end

git :init

run 'rm .gitignore'
create_file '.gitignore' do
<<-FILE
.bundle
.DS_Store
log/*.log
tmp/**/*
config/database.yml
db/*.sqlite3
public/system/**/**/**/*
.idea/*
.sass-cache/**/*
*.swp
FILE
end

# Apply Gemfile
apply File.expand_path("../lib/gemfile.rb", __FILE__)

# Apply HAML generator
apply File.expand_path("../lib/haml_generator.rb", __FILE__)

# Apply rails clean up
apply File.expand_path("../lib/rails_clean.rb", __FILE__)

# Apply Test Suite
apply File.expand_path("../lib/test_suite.rb", __FILE__)

# Apply Friendly Id
apply File.expand_path("../lib/friendly_id.rb", __FILE__)

# Apply Devise?
apply File.expand_path("../lib/devise.rb", __FILE__)

# Apply cancan
apply File.expand_path("../lib/cancan.rb", __FILE__) if ENV['PROLOGUE_ROLES']

# Apply db create and migrations
apply File.expand_path("../lib/db.rb", __FILE__)

# Apply db seeds
apply File.expand_path("../lib/db_seed.rb", __FILE__)

# Make a home controller
apply File.expand_path("../lib/home_controller.rb", __FILE__)

# Make initializers
apply File.expand_path("../lib/initializers.rb", __FILE__)

# Clean up generated routes
apply File.expand_path("../lib/clean_routes.rb", __FILE__)

# Remove RSpec stuff we are not gonna use right away
apply File.expand_path("../lib/rspec_clean.rb", __FILE__)


say <<-D


  <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>

  Gypsum just added like 15 minutes to your life.

  Template Installed :: Gypsum default

  Next run...

  rm -rf /

  <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
D