Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
davb committed Mar 7, 2014
0 parents commit 057ec1f
Show file tree
Hide file tree
Showing 19 changed files with 11,749 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.DS_Store
.ruby-gemset
.env
*.pid
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.0.0
8 changes: 8 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
source "https://rubygems.org"

gem 'rake'
gem 'unicorn'
gem 'pg'
gem 'activerecord'
gem 'sinatra'
gem 'grape'
75 changes: 75 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
GEM
remote: https://rubygems.org/
specs:
activemodel (4.0.0)
activesupport (= 4.0.0)
builder (~> 3.1.0)
activerecord (4.0.0)
activemodel (= 4.0.0)
activerecord-deprecated_finders (~> 1.0.2)
activesupport (= 4.0.0)
arel (~> 4.0.0)
activerecord-deprecated_finders (1.0.3)
activesupport (4.0.0)
i18n (~> 0.6, >= 0.6.4)
minitest (~> 4.2)
multi_json (~> 1.3)
thread_safe (~> 0.1)
tzinfo (~> 0.3.37)
arel (4.0.0)
atomic (1.1.14)
backports (3.3.4)
builder (3.1.4)
descendants_tracker (0.0.1)
grape (0.6.0)
activesupport
builder
hashie (>= 1.2.0)
multi_json (>= 1.3.2)
multi_xml (>= 0.5.2)
rack (>= 1.3.0)
rack-accept
rack-mount
virtus
hashie (2.0.5)
i18n (0.6.5)
kgio (2.8.1)
minitest (4.7.5)
multi_json (1.8.0)
multi_xml (0.5.5)
pg (0.17.0)
rack (1.5.2)
rack-accept (0.4.5)
rack (>= 0.4)
rack-mount (0.8.3)
rack (>= 1.0.0)
rack-protection (1.5.0)
rack
raindrops (0.12.0)
rake (10.1.0)
sinatra (1.4.3)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (~> 1.3, >= 1.3.4)
thread_safe (0.1.3)
atomic
tilt (1.4.1)
tzinfo (0.3.37)
unicorn (4.6.3)
kgio (~> 2.6)
rack
raindrops (~> 0.7)
virtus (0.5.5)
backports (~> 3.3)
descendants_tracker (~> 0.0.1)

PLATFORMS
ruby

DEPENDENCIES
activerecord
grape
pg
rake
sinatra
unicorn
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: bundle exec unicorn -p $PORT -c config/unicorn.rb
74 changes: 74 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Minimalistic web app template

*One-file backend, one-file frontend*

Backed by Sinatra and optionally Grape for APIs.

Single-page client app with Backbone.js and Bootstrap.

Great for demos and quick hacking. Production use at your own risk.


## What you get

**Back-end**
* Sinatra and Grape
* Unicorn server
* ActiveRecord
* Ready to deploy on Heroku
* Database migrations with `rake db:migrate`
* A Rails-like console with `rake console`

**Front-end**
* Bootstrap
* Backbone.js
* Lo-dash
* jQuery


## What you don't get (by design)

* A testing framework (but it's easy to add if you need one)
* Well-organized models, views, controllers, presenters...
* CoffeeScript. Just good old Javascript straight into `views/index.erb`.
* LESS or SASS. And guess where your CSS goes?


## Usage

Create an `.env` file with the following:

```bash
# the URL of your application database
DATABASE_URL=postgres://localhost/app_name
```

Run with `foreman`:

```bash
$ foreman start -p 5000
```


## Development

### The two files

All the frontend stuff goes in `views/index.erb`

All the backend stuff goes in `app.rb`. The root route should render
`index.erb` which loads your single-page app, and other routes should
expose a JSON api that the app talks to.

### Rake tasks

> Remember to always run these with `foreman`, or your environment
> variables will be ignored: `foreman run rake task_name`
* `rake db:migrate` and `rake db:rollback` run database
migrations, _à-la_ Rails

* `rake console` opens a shell into the app, just like
`rails console`

* `rake routes` lists the routes exposed by the App
33 changes: 33 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# encoding: UTF-8

# loads the environment
task :environment do
require './config/environment'
end


# similar to Rails `rake console`
task :console => :environment do
require 'irb'
ARGV.clear
IRB.start
end


namespace :db do

# similar to Rails `rake db:migrate`
desc "Migrate the database"
task(:migrate => :environment) do
ActiveRecord::Migration.verbose = true
ActiveRecord::Migrator.migrate("db/migrate")
end

# similar to Rails `rake db:rollback`
desc "Rollback the last migration"
task(:rollback => :environment) do
ActiveRecord::Migration.verbose = true
ActiveRecord::Migrator.rollback("db/migrate")
end

end
14 changes: 14 additions & 0 deletions app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require_relative './config/environment'
require 'sinatra'


class App < Sinatra::Base

set :root, File.dirname(__FILE__)
set :public_folder, Proc.new { File.expand_path("./public") }

get '/' do
erb :index
end

end
2 changes: 2 additions & 0 deletions config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require './app'
run App
14 changes: 14 additions & 0 deletions config/environment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Encoding.default_external = "utf-8"

# default RACK_ENV to `development`
ENV['RACK_ENV'] ||= 'development'

# log to stdout
require 'logger'
$logger = Logger.new STDOUT
STDOUT.sync = true

# connect to the database
require 'active_record'
ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'])
ActiveRecord::Base.logger = $logger
21 changes: 21 additions & 0 deletions config/unicorn.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 1)
timeout 15
preload_app true


before_fork do |server, worker|
Signal.trap 'TERM' do
# Unicorn master intercept TERM and send QUIT instead
Process.kill 'QUIT', Process.pid
end
ActiveRecord::Base.connection.disconnect!
end


after_fork do |server, worker|
Signal.trap 'TERM' do
# Unicorn worker intercept TERM and do nothing.
# Wait for master to send QUIT.
end
ActiveRecord::Base.establish_connection
end
5 changes: 5 additions & 0 deletions db/migrate/001_do_nothing.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class DoNothing < ActiveRecord::Migration
def change
# a very useful migration
end
end
Loading

0 comments on commit 057ec1f

Please sign in to comment.