-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpiki.rb
More file actions
50 lines (40 loc) · 1.13 KB
/
Copy pathpiki.rb
File metadata and controls
50 lines (40 loc) · 1.13 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
require 'sinatra/base'
#require 'rdiscount'
class Piki < Sinatra::Base
# Configuration
configure do
set :static, true
set :public, File.dirname(__FILE__) + '/static'
end
# End of Configuration
# Helpers
def link_to(url,text=url,opts={})
attributes = ""
opts.each { |key,value| attributes << key.to_s << "=\"" << value << "\" "}
"<a href=\"#{url}\" #{attributes}>#{text}</a>"
end
# Routes
#
# Get Routes
get '/' do
pages = Dir["views/*.mkd"].to_a
erb :all, locals: { pages: pages }
end
get '/show/:file' do
#markdown :esk, :layout_engine => :erb
halt 404 unless FileTest.exist? ((File.dirname(__FILE__) + "/views/#{params[:file]}" + ".mkd") )
markdown :"#{params[:file]}", :layout_engine => :erb
end
get '/show/:file/source' do
halt 404 unless FileTest.exist? ("/views/#{params[:file]}" )
send_file File.dirname(__FILE__) + "/views/#{params[:file]}.mkd",
:type => :text
end
# Post Routes
# Error Handlers
error 404 do
"Sorry, requested page doesn't exist."
end
# Start the server if ruby file executed directly
run! if app_file == $0
end