-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.ru
90 lines (71 loc) · 1.75 KB
/
config.ru
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
86
87
88
89
90
require 'sinatra'
require 'tilt'
require 'haml'
require 'mustache'
require 'sinatra/mustache'
require 'cgi'
require './lib/roadmap'
require './lib/helpers'
Tilt.register "ham", Tilt[:haml]
r = Roadmap.new("src")
use Rack::Session::Pool, :expire_after => 60 * 60
set :session_secret, ENV['session_secret']
helpers do
def before_render template, data={}
Mustache.template_file = template
m = Mustache.new
yield m if block_given?
haml m.render data
end
end
before do
expires 500, :public, :must_revalidate
end
before '/' do
request.path_info = '/index.html'
end
## Dynamic content
get '/index_alpha.html' do
before_render "views/index.tmpl" do |m|
m[:parts] = r.all_by_alpha
m[:order] = "ordre alphabétique"
end
end
get '/index_type.html' do
before_render "views/index.tmpl" do |m|
m[:parts] = r.all_by_type
m[:order] = "type"
end
end
get '/*.html' do
src = r.find_by_id(params[:splat].first)
pass unless src
page = before_render "views/practice.tmpl", src
end
get '/comments/:id' do |id|
cache_control :no_cache
@id = id
mustache :disqus, :layout => false
end
## Static content
['index','outils','ebook','inconnu'].each do |static|
get "/#{static}.html" do
haml static.intern
end
end
## Static assets
before '/assets/AgileDeAaZ.pdf' do
puts "PDF: #{@profile.first_name} #{@profile.last_name}" if @profile
end
get '/assets/*' do |file|
send_file File.join('site',request.path)
end
['/*.js','*.css'].each do |path|
get path do |file|
send_file File.join('site/assets',request.path)
end
end
not_found do
"<h1>Cette page n'existe pas</h1>"
end
run Sinatra::Application