This repository has been archived by the owner on Jul 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
post.rb
89 lines (79 loc) · 3.36 KB
/
post.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
class Utterson < Sinatra::Application
get '/post/list' do
posts = Post.all( session[:site_id] )
erb :'post/list', :locals => { :posts => posts }
end
get '/post/create' do
site = Site.get( session[:site_id] )
post = Post.new
erb :'post/create', :locals => { :site => site, :post => post }
end
post '/post/create' do
site = Site.get( session[:site_id] )
post = Post.new
post.settings['title'] = params['title'].strip
post.settings['published'] = params['published'].strip
post.settings['layout'] = params['layout'].strip
post.settings['date'] = params['date'].strip
post.content = params['content']
if post.create( site.id, params['name'].strip.downcase.gsub(' ', '-') )
Commandline.git_add( site.id, post.git_filename, 'Creating post: ' + post.id.shellescape )
redirect '/post/edit/' + post.id + '?created=true'
end
erb :'post/create', :locals => { :site => site, :post => post }
end
get '/post/edit/:id' do
site = Site.get( session[:site_id] )
post = Post.get( session[:site_id], params['id'] )
erb :'post/edit', :locals => { :site => site, :post => post }
end
post '/post/edit/:id' do
site = Site.get( session[:site_id] )
post = Post.get( session[:site_id], params['id'] )
post.settings['title'] = params['title'].strip
post.settings['published'] = params['published'].strip
post.settings['layout'] = params['layout'].strip
post.settings['date'] = params['date'].strip
post.content = params['content']
if post.save
Commandline.git_add( site.id, post.git_filename , 'Updating post: ' + post.id.shellescape )
end
erb :'post/edit', :locals => { :site => site, :post => post }
end
get '/post/categories/:id' do
site = Site.get( session[:site_id] )
post = Post.get( session[:site_id], params['id'] )
erb :'post/categories', :locals => { :site => site, :post => post }
end
post '/post/categories/:id' do
site = Site.get( session[:site_id] )
post = Post.get( session[:site_id], params['id'] )
case params['action']
when 'add'
params['categories'].each do |category|
post.settings['categories'] << category
end
when 'create'
post.settings['categories'] << params['category'].strip
when 'remove'
params['categories'].each do |category|
post.settings['categories'].delete(category)
end
end
if post.save
Commandline.git_add( site.id, post.git_filename , 'Updating categories for post: ' + post.id.shellescape )
end
erb :'post/categories', :locals => { :site => site, :post => post }
end
get '/post/delete/:id' do
site = Site.get( session[:site_id] )
post = Post.get( session[:site_id], params['id'] )
erb :'post/delete', :locals => { :site => site, :post => post }
end
post '/post/delete/:id' do
site = Site.get( session[:site_id] )
post = Post.get( session[:site_id], params['id'] )
Commandline.git_rm( site.id, post.git_filename, 'Deleting post: ' + post.id.shellescape )
erb :'post/delete', :locals => { :site => site, :post => post }
end
end