forked from adamwiggins/12factor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb.rb
49 lines (42 loc) · 1.13 KB
/
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
40
41
42
43
44
45
46
47
48
49
require 'sinatra'
require 'redcarpet'
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)
text = File.read("content/#{file}.md")
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,
:fenced_code_blocks => true,
:no_intra_emphasis => true,
:autolink => true,
:strikethrough => true,
:lax_html_blocks => true,
:superscript => true,
:hard_wrap => true,
:tables => true,
:xhtml => true)
markdown.render(text)
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