This repository was archived by the owner on Feb 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathapp.rb
More file actions
85 lines (66 loc) · 1.33 KB
/
Copy pathapp.rb
File metadata and controls
85 lines (66 loc) · 1.33 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
$LOAD_PATH << '.'
require 'bundler/setup'
require 'docify'
require 'sinatra'
require 'sinatra/assetpack'
require 'app/lib/highlight'
VERSION = '0.3.8'
configure do
set :views, 'app/views'
end
configure :production do
set :show_exceptions, false
set :dump_errors, false
set :raise_errors, false
end
assets do
serve '/js', :from => 'app/js'
serve '/css', :from => 'app/css'
css :app, [
'/css/master.css',
'/css/github.css',
'/css/jquery-ui.min.css'
]
js :app, [
'/js/jquery.min.js',
'/js/jquery-ui.min.js',
'/js/tabby.js',
'/js/highlight.pack.js',
'/js/application.js'
]
prebuild true
end
helpers do
def app_version
VERSION
end
def gist_content(id)
url = Faraday.get("https://gist.github.com/#{id}").headers['Location']
Faraday.get("#{url}/raw").body
end
end
get '/' do
erb :editor
end
get '/sample' do
@content = File.read(File.join(settings.root, 'README.md'))
erb :editor
end
get '/gist/:id' do
@content = gist_content(params[:id]) rescue nil
if @content.nil?
redirect '/'
end
erb :editor
end
post '/render' do
content = params[:content].to_s
markup = params[:markup] || 'markdown'
if content.empty?
return ""
end
if !Docify.valid_format?(params[:markup])
halt 400, "Invalid markup"
end
Highlight.render(content, markup)
end