forked from heroku/12factor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.rb
39 lines (32 loc) · 843 Bytes
/
web.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
require 'sinatra'
require 'maruku'
get '/' do
erb :home
end
TOC = %w(codebase dependencies config backing-services build-release-run processes port-binding concurrency disposability dev-prod-parity logs admin-processes)
get '/:factor' do |factor|
halt 404 unless TOC.include?(factor)
@factor = factor
erb :factor
end
helpers do
def render_markdown(file)
markdown = File.read("content/#{file}.md")
Maruku.new(markdown).to_html
rescue Errno::ENOENT
puts "No content for #{file}, skipping"
end
def render_prev(factor)
idx = TOC.index(factor)
return if idx == 0
"<a href=\"/#{TOC[idx-1]}\">« Previous</a>"
end
def render_next(factor)
idx = TOC.index(factor)
return if idx == TOC.size-1
"<a href=\"/#{TOC[idx+1]}\">Next »</a>"
end
end
not_found do
"Page not found"
end