-
Notifications
You must be signed in to change notification settings - Fork 2
/
planet.rb
47 lines (33 loc) · 854 Bytes
/
planet.rb
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
# encoding: utf-8
class Planet < Sinatra::Base
#######################
# Models
include Pluto::Models # e.g. Feed, Item, Site, etc.
###################
# Helpers
def feed_path( feed )
"/feed/#{feed.key}"
end
def root_path()
"/"
end
##############################################
# Controllers / Routing / Request Handlers
get '/feed/:key' do |key|
erb :feed, locals: { feed: Feed.find_by_key!( key ), site: find_planet_site }
end
get '/' do
erb :index, locals: { site: find_planet_site }
end
#################
# Utilities
def find_planet_site
site = Site.first # FIX: for now assume one planet per DB (fix later; allow planet key or similar)
if site.present?
site
else
site = Site.new
site.title = 'Planet Untitled'
end
end
end # class Planet