Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

initial import

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

0 notes on commit 390cd39

Please sign in to comment.
Something went wrong with that request. Please try again.