forked from davb/minimalistic-boilerplate-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 057ec1f
Showing
19 changed files
with
11,749 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.DS_Store | ||
.ruby-gemset | ||
.env | ||
*.pid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
2.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: bundle exec unicorn -p $PORT -c config/unicorn.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require './app' | ||
run App |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.