-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathapp.rb
More file actions
96 lines (72 loc) · 1.97 KB
/
app.rb
File metadata and controls
96 lines (72 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# encoding: utf-8
#first off, we need to include rubygems and sinatra
require 'rubygems'
#this bundler stuff needed for heroku
require 'bundler'
Bundler.setup
require 'sinatra'
#this lets us send emails
require 'pony'
#haml gives us all of our templates
require 'haml'
#mongomapper connects us to our database
require 'mongo_mapper'
#rack-flash gives us nice flash messages
require 'rack-flash'
#rdiscount lets us write things using markdown
require 'rdiscount'
#we need to set up a secret to encrypt our sessions with
use Rack::Session::Cookie, :secret => 'h4ck3ty h4ck f0r gr347 g00d'
#we also have to let the world know we want to use flashes
use Rack::Flash
require 'sinatra/content_for'
require_relative 'helpers'
#this makes Haml escape any html by default. See here: http://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html#options
set :haml, :escape_html => true
#these configure blocks only run in one environment
configure :test do
PONY_VIA_OPTIONS = {}
end
configure :development do
PONY_VIA_OPTIONS = {}
end
configure :production do
PONY_VIA_OPTIONS = {
:address => "smtp.sendgrid.net",
:port => "25",
:authentication => :plain,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => ENV['SENDGRID_DOMAIN']
}
end
#for all environments,
configure do
if ENV['MONGOHQ_URL']
MongoMapper.config = {ENV['RACK_ENV'] => {'uri' => ENV['MONGOHQ_URL']}}
MongoMapper.database = ENV['MONGOHQ_DATABASE']
MongoMapper.connect("production")
else
MongoMapper.connection = Mongo::Connection.new('localhost')
MongoMapper.database = "hackety-development"
end
#require all of our models!
require_directory "models"
end
require_directory "controllers"
get '/' do
if logged_in?
redirect "/stream"
end
haml :index
end
get '/post' do
haml :post
end
get '/download' do
haml :download
end
get '/stream' do
@content_list = Content.all.reverse
haml :stream
end