forked from DeMarko/postgresapp.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.rb
61 lines (47 loc) · 1.49 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
50
51
52
53
54
55
56
57
58
59
60
61
class Web < Sinatra::Base
helpers Sinatra::ContentFor
set :markdown, layout_engine: :haml
helpers do
def markdown(template, options = {}, locals = {})
options.merge!({
hard_wrap: true,
filter_html: true,
autolink: true,
no_intraemphasis: true,
fenced_code_blocks: true,
gh_codeblock: true,
with_toc_data: true
})
@toc = render(:markdown, template, options.merge(renderer: Redcarpet::Render::HTML_TOC, layout: false), locals)
render(:markdown, template, options.merge(renderer: Redcarpet::Render::HTML.new(with_toc_data: true)), locals)
end
def version
File.basename(ENV['POSTGRESAPP_DOWNLOAD_URL'], ".zip").scan(/\d+/)[0...3].join(".")
end
end
get '/' do
# cache_control :public, :must_revalidate, max_age: 3600
haml :index
end
get '/download' do
redirect ENV['POSTGRESAPP_DOWNLOAD_URL']
end
get '/documentation' do
cache_control :public, :must_revalidate, max_age: 3600
@title = "Documentation"
haml :documentation, locals: {text: markdown(:'README', layout: false, views: ::File.expand_path(::File.dirname(__FILE__), ".."))}
end
end
class HTMLwithAlbino < Redcarpet::Render::HTML
def block_code(code, language)
Albino.colorize((code || "").strip, language || :text)
end
end
module Haml::Filters::Markdown
require 'redcarpet/compat'
include Haml::Filters::Base
lazy_require "redcarpet"
def render(text)
::Markdown.new(text).to_html
end
end