Permalink
Browse files

initial import

  • Loading branch information...
0 parents commit 390cd396aae7d2199b889e40d8b0e17ff883c794 @zapnap committed Jan 23, 2009
Showing with 243 additions and 0 deletions.
  1. +20 −0 MIT-LICENSE
  2. +21 −0 README.rdoc
  3. +27 −0 Rakefile
  4. +22 −0 application.rb
  5. +23 −0 environment.rb
  6. +11 −0 lib/profile.rb
  7. +52 −0 public/main.css
  8. +13 −0 spec/application_spec.rb
  9. +17 −0 spec/profile_spec.rb
  10. +19 −0 spec/spec_helper.rb
  11. +14 −0 views/layout.haml
  12. +4 −0 views/root.haml
20 MIT-LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2009 Nick Plante
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 README.rdoc
@@ -0,0 +1,21 @@
+= Sinatra Application Template
+
+A base Sinatra application template. Just fork and build. Yay!
+Includes DataMapper, RSpec, and Haml, all ready to go.
+
+== Configuration
+
+Dependencies and all configuration is done in +environment.rb+. Your database is also set up here. DataMapper will use sqlite3 by default. Tests use the sqlite3-memory adapter (no configuration needed).
+
+Add your controller actions in +application.rb+. Views for these actions are placed in the +views+ directory. Static files, including a stock stylesheet, go in the +public+ directory. Models go in the +lib+ directory and are auto-loaded.
+
+== Testing
+
+Add your specs in +spec+; just require +spec_helper.rb+ 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
+
+== Getting Started
+
+ rake db:migrate
+ ruby main.rb
27 Rakefile
@@ -0,0 +1,27 @@
+require 'environment'
+require 'spec/rake/spectask'
+
+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
+
+namespace :db do
+ desc 'Auto-migrate the database (destroys data)'
+ task :migrate do
+ DataMapper.auto_migrate!
+ end
+
+ desc 'Auto-upgrade the database (preserves data)'
+ task :upgrade do
+ DataMapper.auto_upgrade!
+ end
+end
22 application.rb
@@ -0,0 +1,22 @@
+require 'sinatra'
+require 'environment'
+
+configure do
+ set :views, "#{File.dirname(__FILE__)}/views"
+end
+
+error do
+ e = request.env['sinatra.error']
+ puts e.to_s
+ puts e.backtrace.join('\n')
+ 'Application error'
+end
+
+helpers do
+ # add your helpers here
+end
+
+# root page
+get '/' do
+ haml :root
+end
23 environment.rb
@@ -0,0 +1,23 @@
+require 'rubygems'
+require 'dm-core'
+require 'dm-timestamps'
+require 'dm-validations'
+require 'dm-aggregates'
+require 'haml'
+require 'ostruct'
+
+require 'sinatra' unless defined?(Sinatra)
+
+configure do
+ SiteConfig = OpenStruct.new(
+ :title => 'Your Application Name',
+ :author => 'Your Name',
+ :url_base => 'http://localhost:4567/'
+ )
+
+ DataMapper.setup(:default, "sqlite3:///#{File.expand_path(File.dirname(__FILE__))}/#{Sinatra::Base.environment}.db")
+
+ # load models
+ $LOAD_PATH.unshift("#{File.dirname(__FILE__)}/lib")
+ Dir.glob("#{File.dirname(__FILE__)}/lib/*.rb") { |lib| require File.basename(lib, '.*') }
+end
11 lib/profile.rb
@@ -0,0 +1,11 @@
+# example model file
+class Profile
+ include DataMapper::Resource
+
+ property :id, Serial
+ property :name, String
+ property :created_at, DateTime
+ property :updated_at, DateTime
+
+ validates_present :name
+end
52 public/main.css
@@ -0,0 +1,52 @@
+body {
+ background: #FFF;
+ color: #1B1B1B;
+ font-family: Verdana, Arial, Helvetica, sans-serif;
+}
+#container {
+ margin: 0 auto;
+ width: 800px;
+}
+#header {
+ padding: 0.5em 0 0 0;
+ margin: 0;
+ text-align: center;
+ border-bottom: 3px solid #000;
+}
+#content {
+ padding: 0;
+ margin: 0;
+}
+#footer {
+ padding: 0;
+ margin: 0;
+ font-size: 0.7em;
+ text-align: center;
+ border-top: 3px solid #000;
+}
+h1, h2, h3, h4, h5, h6 {
+ margin-top: 0em;
+ margin-bottom: .25em;
+ font-weight: bold;
+}
+h1 { font-size: 2.2em; }
+h2 { font-size: 1.6em; }
+h3 { font-size: 1.4em; }
+h4 { font-size: 1.3em; }
+h5 { font-size: 1.2em; }
+h6 { font-size: 1.1em; }
+p {
+ margin-bottom: 1em;
+ line-height: 1.3;
+}
+a {
+ color: #095EAE;
+ font-weight: bold;
+ text-decoration: none;
+}
+a:hover {
+ text-decoration: underline;
+}
+#logo a:hover {
+ text-decoration: none;
+}
13 spec/application_spec.rb
@@ -0,0 +1,13 @@
+require "#{File.dirname(__FILE__)}/spec_helper"
+
+describe 'main application' do
+ specify 'should show the default index page' do
+ get '/'
+ @response.should be_ok
+ @response.body.should match(/Main Page/)
+ end
+
+ specify 'should have more specs' do
+ pending
+ end
+end
17 spec/profile_spec.rb
@@ -0,0 +1,17 @@
+require "#{File.dirname(__FILE__)}/spec_helper"
+
+describe 'profile' do
+ before(:each) do
+ @profile = Profile.new(:name => 'test user')
+ end
+
+ specify 'should be valid' do
+ @profile.should be_valid
+ end
+
+ specify 'should require a name' do
+ @profile = Profile.new
+ @profile.save.should be_false
+ @profile.errors[:name].should include("Name must not be blank")
+ end
+end
19 spec/spec_helper.rb
@@ -0,0 +1,19 @@
+require 'rubygems'
+require 'sinatra'
+require 'sinatra/test/rspec'
+
+# set test environment
+set :environment, :test
+set :run, false
+set :raise_errors, true
+set :logging, false
+
+require 'application'
+
+# establish in-memory database for testing
+DataMapper.setup(:default, "sqlite3::memory:")
+
+Spec::Runner.configure do |config|
+ # reset database before each example is run
+ config.before(:each) { DataMapper.auto_migrate! }
+end
14 views/layout.haml
@@ -0,0 +1,14 @@
+!!!
+%html
+ %head
+ %title= @title || SiteConfig.title
+ %link{:href => '/main.css', :rel => 'stylesheet', :type => 'text/css'}
+ %body
+ #container
+ #header
+ #logo
+ %h1
+ %a{:href => '/'}= SiteConfig.title
+ #content= yield
+ #footer
+ %p#legal= "— © #{Time.now.strftime('%Y')} #{SiteConfig.author} —"
4 views/root.haml
@@ -0,0 +1,4 @@
+%h2 Main Page
+%p Here is some text.
+%p Here is a <a href='/'>link</a>.
+%p ttys!

0 comments on commit 390cd39

Please sign in to comment.