-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapplication.rb
43 lines (34 loc) · 971 Bytes
/
application.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
require 'sinatra'
require 'haml'
require 'coffee-script'
require 'redcarpet'
get '/' do
haml :index, format: :html5, layout: !pjax?
end
get '/:javascript.js' do |javascript|
coffee :"/app/assets/javascripts/#{javascript}"
end
get '/:stylesheet.css' do |stylesheet|
sass :"/app/assets/stylesheets/#{stylesheet}"
end
get '/:markdown.mdown' do |markdown|
mdown markdown
end
get '/references/:page' do
haml :"/references/#{params[:page]}", layout: !pjax?
end
helpers do
def pjax?
env['HTTP_X_PJAX']
end
def partial page, variables = {}
haml page.to_sym, { layout: !pjax? }, variables
end
def mdown lesson
partial :'shared/markdown', { markdown: render_markdown(lesson) }
end
def render_markdown filename
redcarpet = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true, :space_after_headers => true)
redcarpet.render(File.read(File.join(File.dirname(__FILE__), "views/lessons/#{filename}.mdown")))
end
end