Skip to content

Commit

Permalink
adding sinatra app example
Browse files Browse the repository at this point in the history
  • Loading branch information
mcansky committed Aug 13, 2011
1 parent 2e4195d commit 6838800
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 0 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions sinatra/.bundle/config
@@ -0,0 +1,3 @@
---
BUNDLE_PATH: bundler
BUNDLE_DISABLE_SHARED_GEMS: "1"
1 change: 1 addition & 0 deletions sinatra/.rvmrc
@@ -0,0 +1 @@
rvm ruby-1.9.2-p180@8pom
16 changes: 16 additions & 0 deletions sinatra/Gemfile
@@ -0,0 +1,16 @@
source 'http://rubygems.org'

# sinatra
gem 'sinatra', '1.2.6'

# datamapper
gem "data_mapper"
gem "dm-sqlite-adapter"

gem "haml"

# thor
gem "thor"

# Use unicorn as the web server
gem 'unicorn'
78 changes: 78 additions & 0 deletions sinatra/Gemfile.lock
@@ -0,0 +1,78 @@
GEM
remote: http://rubygems.org/
specs:
addressable (2.2.6)
bcrypt-ruby (2.1.4)
data_mapper (1.1.0)
dm-aggregates (= 1.1.0)
dm-constraints (= 1.1.0)
dm-core (= 1.1.0)
dm-migrations (= 1.1.0)
dm-serializer (= 1.1.0)
dm-timestamps (= 1.1.0)
dm-transactions (= 1.1.0)
dm-types (= 1.1.0)
dm-validations (= 1.1.0)
data_objects (0.10.6)
addressable (~> 2.1)
dm-aggregates (1.1.0)
dm-core (~> 1.1.0)
dm-constraints (1.1.0)
dm-core (~> 1.1.0)
dm-core (1.1.0)
addressable (~> 2.2.4)
dm-do-adapter (1.1.0)
data_objects (~> 0.10.2)
dm-core (~> 1.1.0)
dm-migrations (1.1.0)
dm-core (~> 1.1.0)
dm-serializer (1.1.0)
dm-core (~> 1.1.0)
fastercsv (~> 1.5.4)
json (~> 1.4.6)
dm-sqlite-adapter (1.1.0)
dm-do-adapter (~> 1.1.0)
do_sqlite3 (~> 0.10.2)
dm-timestamps (1.1.0)
dm-core (~> 1.1.0)
dm-transactions (1.1.0)
dm-core (~> 1.1.0)
dm-types (1.1.0)
bcrypt-ruby (~> 2.1.4)
dm-core (~> 1.1.0)
fastercsv (~> 1.5.4)
json (~> 1.4.6)
stringex (~> 1.2.0)
uuidtools (~> 2.1.2)
dm-validations (1.1.0)
dm-core (~> 1.1.0)
do_sqlite3 (0.10.6)
data_objects (= 0.10.6)
fastercsv (1.5.4)
haml (3.1.2)
json (1.4.6)
kgio (2.6.0)
rack (1.3.2)
raindrops (0.7.0)
sinatra (1.2.6)
rack (~> 1.1)
tilt (>= 1.2.2, < 2.0)
stringex (1.2.2)
thor (0.14.6)
tilt (1.3.2)
unicorn (4.0.1)
kgio (~> 2.4)
rack
raindrops (~> 0.6)
uuidtools (2.1.2)

PLATFORMS
ruby

DEPENDENCIES
data_mapper
dm-sqlite-adapter
haml
sinatra (= 1.2.6)
thor
unicorn
19 changes: 19 additions & 0 deletions sinatra/app.rb
@@ -0,0 +1,19 @@
# encoding: utf-8
require "rubygems"
require "sinatra"
require "data_mapper"
require "dm-sqlite-adapter"
require "haml"

require_relative "models"

class MyApp < Sinatra::Application
get "/" do
if Post.all.count > 0
@posts = Post.all
else
@posts = []
end
haml :index
end
end
2 changes: 2 additions & 0 deletions sinatra/config.ru
@@ -0,0 +1,2 @@
require ::File.join( ::File.dirname(__FILE__), 'app' )
run MyApp.new
13 changes: 13 additions & 0 deletions sinatra/models.rb
@@ -0,0 +1,13 @@
# encoding: utf-8
DataMapper.setup(:default, :adapter => "sqlite3", :database => "#{Dir.pwd}/database.sqlite3")

class Post
include DataMapper::Resource

property :id, Serial
property :title, Text
property :text, Text
end

DataMapper.finalize
DataMapper.auto_upgrade!
21 changes: 21 additions & 0 deletions sinatra/tasks/setup.thor
@@ -0,0 +1,21 @@
# encoding: utf-8
require "rubygems"
require "sinatra"
require "data_mapper"
require "dm-sqlite-adapter"

require './models'

class Setup < Thor
include Thor::Actions
desc "quick", "create some articles"
def quick
if Post.all.count == 0
i = 0
3.times do
Post.create(:title => "article ##{i}", :text => "Vous voila armé d'un nouveau marteau, ce n'est pas encore une masse, mais vous avez de quoi forger quelque chose d'intéressant d'hors et déjà.")
i += 1
end
end
end
end
6 changes: 6 additions & 0 deletions sinatra/views/index.haml
@@ -0,0 +1,6 @@
- if @posts.count > 0
- @posts.each do |post|
%h2= post.title
%p= post.text
- else
Pas d'articles

0 comments on commit 6838800

Please sign in to comment.