#!/usr/bin/env ruby

require 'rubygems'
require 'sinatra/base'
require 'slim'
require 'sass'
require 'coffee-script'
require 'sprockets'

class Assets < Sinatra::Base

  set :root, File.dirname(__FILE__)
  set :assets, (Sprockets::Environment.new(root) { |env| env.logger = Logger.new(STDOUT) })
  set :assets_prefix, 'compiled'
  set :assets_path, File.join(root, 'public', assets_prefix)

  set :assets_js_path, 'app/assets/javascripts/'
  set :assets_precompile_js, %w( app.js )
  set :assets_precompile_css, %w(  )

  configure do
    assets.append_path(root)
  end
  # we are deploying to heroku, which does not have a JVM, which YUI needs, so let's
  # only require and config the compressors / minifiers for dev env
  configure :development do
    if ENV["RACK_ENV"] == "production"
      require 'yui/compressor'
      require 'uglifier'
      assets.css_compressor = YUI::CssCompressor.new
      assets.js_compressor  = Uglifier.new(mangle: true)
    end
  end
  

  get "/*.js" do
    content_type("application/javascript")
    settings.assets["app/assets/javascripts/#{params[:splat].first}.js"]
  end

  get "/*.css" do
    content_type("text/css")
    settings.assets["app/assets/stylesheets/#{params[:splat].first}.css"]
  end

  %w{jpg png}.each do |format|
    get "/*.#{format}" do |image|
      content_type("image/#{format}")
      settings.assets["app/assets/images/#{params[:splat].first}.#{format}"]
    end
  end
  
end
 
class App < Sinatra::Base

  set :public_dir, File.dirname(__FILE__) + '/public/'
  set :views, File.dirname(__FILE__) + '/app/views/'
  
  configure do
    set :protection, :except => :frame_options

    #Compass.add_project_configuration(File.join(Sinatra::Application.root, 'config/compass.rb'))
  end

  # ------------------------------------------
  # Helpers
  # ------------------------------------------
  helpers do
  end
  
  before do
  end
  

  # ------------------------------------------
  # Routes
  # ------------------------------------------
  get '/' do
    slim :index
  end

end

