Skip to content

Commit

Permalink
using bundler for gem management
Browse files Browse the repository at this point in the history
  • Loading branch information
tc committed Oct 25, 2010
1 parent 644dab4 commit 0f509d0
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 78 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
gem 'sinatra'
gem 'haml'
10 changes: 4 additions & 6 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ A base Sinatra application template. Just fork and build. Yay!
Includes Haml, Rspec all ready to go.

== Configuration
Dependencies and all configuration is done in <tt>environment.rb</tt>.
Add gems to Gemfile

Add your controller actions in <tt>application.rb</tt>. Views for these actions are placed in the <tt>views</tt> directory. Static files, including a stock stylesheet, go in the <tt>public</tt> directory. Models go in the <tt>lib</tt> directory and are auto-loaded.

== Testing

Add your specs in <tt>spec</tt>; just require <tt>spec_helper.rb</tt> to pre-configure the test environment. A number of samples are provided (including a sample model, which can be removed). To run the specs:

rake spec
TODO

== Getting Started
ruby application.rb
bundle pack
./rackup
39 changes: 4 additions & 35 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,39 +1,8 @@
require 'spec/rake/spectask'
require File.join(File.expand_path(File.dirname(__FILE__)), 'vendor', 'gems', 'environment')

task :default => :test
task :test => :spec

if !defined?(Spec)
puts "spec targets require RSpec"
else
desc "Run all examples"
Spec::Rake::SpecTask.new('spec') do |t|
t.spec_files = FileList['spec/**/*.rb']
t.spec_opts = ['-cfs']
end
end
Bundler.require_env(:test)

namespace :db do
desc 'Auto-migrate the database (destroys data)'
task :migrate => :environment do
DataMapper.auto_migrate!
end

desc 'Auto-upgrade the database (preserves data)'
task :upgrade => :environment do
DataMapper.auto_upgrade!
end
end
task :default => :test

namespace :gems do
desc 'Install required gems'
task :install do
required_gems = %w{ sinatra rspec rack-test dm-core dm-validations
dm-aggregates haml }
required_gems.each { |required_gem| system "sudo gem install #{required_gem}" }
end
end
Dir['tasks/*.rake'].each { |task| load task }

task :environment do
require 'environment'
end
38 changes: 21 additions & 17 deletions application.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
require 'rubygems'
require 'sinatra'
require 'environment'

configure do
set :views, "#{File.dirname(__FILE__)}/views"
end
require 'bundler'
Bundler.setup

error do
e = request.env['sinatra.error']
Kernel.puts e.backtrace.join("\n")
'Application error'
end
require 'sinatra'
require 'haml'
require 'ostruct'
SiteConfig = OpenStruct.new(
:title => 'Your Application Name',
:author => 'Your Name',
:url_base => 'http://localhost:4567/'
)

helpers do
# add your helpers here
end
class Application < Sinatra::Base

# root page
get '/' do
haml :root
configure do
set :public, "#{File.dirname(__FILE__)}/public"
set :views, "#{File.dirname(__FILE__)}/views"
set :haml, { :attr_wrapper => '"' }
end

get "/" do
haml :index
end

end
10 changes: 8 additions & 2 deletions config.ru
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
require 'application'

set :run, false
set :environment, :production
disable :run

use Rack::ShowExceptions
use Rack::Static, :urls => [ '/favicon.ico', '/css' ], :root => "public"

$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/lib")
Dir.glob("#{File.dirname(__FILE__)}/lib/*.rb") { |lib| require File.basename(lib, '.*') }

FileUtils.mkdir_p 'log' unless File.exists?('log')
log = File.new("log/sinatra.log", "a")
$stdout.reopen(log)
$stderr.reopen(log)

run Sinatra::Application
run Application
17 changes: 0 additions & 17 deletions environment.rb

This file was deleted.

4 changes: 4 additions & 0 deletions tasks/test.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
desc "Test"
task :test do
puts "Stub for test"
end
File renamed without changes.
2 changes: 1 addition & 1 deletion views/layout.haml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
!!!
%html
%head
%title= @title || SiteConfig.title
%title= SiteConfig.title
%link{:href => '/stylesheets/main.css', :rel => 'stylesheet', :type => 'text/css'}
%body
#container
Expand Down

0 comments on commit 0f509d0

Please sign in to comment.