forked from hallison/sinatra-mapping
-
Notifications
You must be signed in to change notification settings - Fork 0
/
classic_application.rb
69 lines (55 loc) · 1.9 KB
/
classic_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
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
require 'rubygems'
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../../lib/")
require 'sinatra'
require 'sinatra/mapping'
class Sinatra::Application
def env
@env.update('SCRIPT_NAME' => '/test')
end
end
map :root, "blog" # root_path => /blog/
map :about # about_path => /blog/about
mapping :posts => "articles", # posts_path => /blog/articles
:archive => "archive/articles", # archive_path => /blog/archive/articles
:search => "find-articles", # search_path => /blog/find-articles
:drafts => "unpublished", # drafts_path => /blog/unpublished
:profile => "users/:user_id" # profile_path => /user/:user_id
before do
@date = Date.today
end
get root_path do
"#{title_path :root, :path}:#{path_to :root}"
end
get posts_path do
"#{title_path :posts, :published}:#{path_to :posts}"
end
get posts_path "/:year/:month/:day/:permalink" do |year, month, day, permalink|
"#{title_path :posts}:" + path_to(:posts, "#{@date.to_s.gsub('-','/')}/#{permalink}")
end
get archive_path do
"#{title_path :archive}:#{path_to :archive}"
end
get archive_path "/:year/:month/:day/:permalink" do |year, month, day, permalink|
"#{title_path :archive}:" + path_to(:archive, "#{@date.to_s.gsub('-','/')}/#{permalink}")
end
get about_path do
"#{title_path :about}:#{path_to :about}"
end
get search_path do
<<-end_content.gsub(/^ /,'')
#{title_path :search}:#{path_to :search, :keywords => 'ruby'}
#{link_to "Search", :search, :title => 'Search'}
#{link_to "Search", :search, :title => 'Search', :keywords => 'ruby'}
end_content
end
get drafts_path do
<<-end_content.gsub(/^ /,'')
#{title_path :drafts}:#{path_to [:drafts, :posts]}
#{link_to "Unpublished", :drafts, :posts, :title => 'Unpublished'}
end_content
end
get profile_path do |user_id|
<<-end_content.gsub(/^ /,'')
"Im user number #{user_id}"
end_content
end