forked from sosedoff/markup-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
41 lines (32 loc) · 737 Bytes
/
app.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
require 'bundler/setup'
require 'docify'
require 'sinatra'
VERSION = '0.2.0'
configure do
set :views, 'app/views'
end
configure :production do
set :show_exceptions, false
set :dump_errors, false
set :raise_errors, false
end
helpers do
def app_version
VERSION
end
end
get '/' do
erb :editor
end
get '/sample' do
@content = File.read(File.join(settings.root, 'README.md'))
erb :editor
end
post '/render' do
content = params[:content].to_s
markup = params[:markup].to_s
halt 400, "Content required" if content.empty?
halt 400, "Markup required" if markup.empty?
halt 400, "Invalid markup" if !Docify.valid_format?(params[:markup])
Docify.render(params[:content], params[:markup])
end