Created
February 4, 2009 03:58
-
-
Save kematzy/57919 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# set the root of the whole app | |
APP_ROOT = File.expand_path(File.dirname(__FILE__)) unless defined?(APP_ROOT) | |
# running on Edge?, if so grab that version | |
# sin_version = 'sinatra-hacked' | |
sin_version = 'sinatra' | |
$LOAD_PATH.unshift "#{APP_ROOT}/vendor/#{sin_version}/lib" if File.directory?("#{APP_ROOT}/vendor/#{sin_version}") | |
# $LOAD_PATH.unshift "#{APP_ROOT}/vendor/sinatras-hat/lib" if File.directory?("#{APP_ROOT}/vendor/sinatras-hat") | |
### Make sure my own gem path is included first | |
if (ENV['HOME'] =~ /^\/home\//) ## DREAMHOST | |
ENV['GEM_HOME'] = "#{ENV['HOME']}/.gems" | |
ENV['GEM_PATH'] = "#{ENV['HOME']}/.gems:/usr/lib/ruby/gems/1.8" | |
require 'rubygems' | |
Gem.clear_paths | |
else | |
ENV['PATH']="/opt/local/bin:/opt/local/sbin:#{ENV['PATH']}" | |
require 'rubygems' | |
end | |
%w(sinatra/base compass ostruct ).each {|g| require g } | |
# %w(sinatra/base sinatras-hat compass ostruct ).each {|g| require g } | |
class MyApp < Sinatra::Base | |
## INCLUDES: | |
load "#{APP_ROOT}/app/models/models.rb" | |
load "#{APP_ROOT}/lib/helpers.rb" | |
# load "#{APP_ROOT}/lib/sinatra_rest.rb" | |
## Import the Site Configs | |
::Settings = ::OpenStruct.new(YAML.load_file("#{APP_ROOT}/config/settings.yml")) | |
::Page = ::OpenStruct.new(:title => "Undefined") | |
### CONFIGURE | |
configure do | |
::DataMapper.setup(:default, "sqlite3:db/#{Sinatra::Base.environment}.sqlite3") | |
# Auto-migrates all classes that include Resource. | |
::DataMapper.auto_upgrade! | |
# DataObjects::Sqlite3.logger = DataObjects::Logger.new('log/dm.log', 0) | |
# DataMapper.logger.set_log(STDOUT, :debug) | |
::DataMapper.logger.set_log('log/dm.log', :debug) | |
### ENABLE LOGGING | |
# log = File.new("#{APP_ROOT}/log/#{Time.now.strftime("%Y-%m-%d")}-sinatra.log", "a") | |
# STDOUT.reopen(log) | |
# STDERR.reopen(log) | |
end | |
configure :development do | |
#### ENABLE | |
enable :reload | |
end | |
### HELPERS | |
include Rack::Utils | |
alias_method :h, :escape_html | |
### SET | |
## Make sure files from the public directory can be seen/read | |
enable :static | |
enable :public | |
set :public, "#{APP_ROOT}/public" | |
set :views, "#{APP_ROOT}/app/views" | |
# set :run, false | |
set :logging, true | |
set :layout, 'layout' | |
# set :layout, "application" | |
set :haml, { :format => :html4, :attr_wrapper => '"' } | |
set :sass, { | |
:style => :compact, | |
# :template_location => File.join(APP_ROOT, 'app', 'views', 'stylesheets'), | |
# :load_paths => File.join(APP_ROOT, 'app', 'views', 'stylesheets') | |
} | |
### WEB URL/HANDLERS | |
## HOME | |
get '/' do | |
@title = 'HOME' | |
@posts = Post.all | |
# erb(:index ) | |
erb(:index, :layout => :application) | |
end | |
## ABOUT | |
get '/about/?' do | |
erb(:about, :layout => :layout ) | |
end | |
# mount(Post, :layout => :false) do | |
# | |
# finder { |model, params| model.all } | |
# record { |model, params| model.get!(params[:id]) } | |
# | |
# # Mount children as a nested resource | |
# mount(Comment) do | |
# finder { |model, params| model.all } | |
# record { |model, params| model.get!(params[:id]) } | |
# end | |
# end | |
# include Sinatra::Rest | |
# rest(Comment, :renderer => :erb) | |
get '/sinatra' do | |
out = "Powered by Sinatra v#{Sinatra::VERSION} running in '#{Sinatra::Base.environment}' mode.\n" | |
erb( out ) | |
end | |
get "/stylesheets/*.css", :layout => false do | |
content_type 'text/css', :charset => 'utf-8' | |
# Use views/stylesheets & blueprint's stylesheet dirs in the Sass load path | |
sass "stylesheets/#{params[:splat]}".to_sym, { | |
:sass => { | |
:style => :compact, | |
:load_paths => ( | |
[ File.join(APP_ROOT, 'app', 'views', 'stylesheets') ] + Compass::Frameworks::ALL.map { |f| f.stylesheets_directory } | |
) | |
} | |
} | |
end | |
end #/class MyApp | |
# | |
MyApp.run! | |
# EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment