forked from gjtorikian/markdowntutorial.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.rb
More file actions
75 lines (61 loc) · 1.43 KB
/
Copy pathapp.rb
File metadata and controls
75 lines (61 loc) · 1.43 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
require 'sinatra/base'
require 'sinatra/assetpack'
require 'redcarpet'
require 'sass'
class MarkdownTutorial < Sinatra::Base
set :root, File.dirname(__FILE__)
register Sinatra::AssetPack
# "Thin is a supremely better performing web server so do please use it!"
set :server, %w[thin webrick]
assets {
js :app, [
'/js/*.js'
]
css :application, [
'/css/*.css'
]
js_compression :closure, :level => "SIMPLE_OPTIMIZATIONS"
css_compression :sass
}
# trim trailing slashes
before do
@page_count = 0
@is_conclusion = false
request.path_info.sub! %r{/$}, ''
end
not_found do
markdown :notfound, :locals => {:force => false}
end
# for all markdown files, keep using layout.erb
set :markdown, :layout_engine => :erb
get "/" do
markdown :index
end
get "/conclusion" do
@is_conclusion = true
markdown :conclusion
end
get '/lesson/:number' do
erb :"lesson#{params[:number]}"
end
helpers do
def title(number=nil)
title = "Markdown Tutorial"
# helper for formatting your title string
if number
title + " | Lesson #{number}"
else
title
end
end
# Draws a blank circle in the nav bar for every other page
def current_page_icon(force=false)
@page_count += 1
if @page_count == params[:number].to_i || (force and @is_conclusion)
""
else
"-blank"
end
end
end
end