GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Fork of sr/git-wiki
Description: A quick & dirty git-powered Sinatra wiki
Homepage: http://atonie.org/2008/02/git-wiki
Clone URL: git://github.com/willcodeforfoo/git-wiki.git
Delete page, a little heavy handed with not much error checking though
Tue Feb 19 16:06:59 -0800 2008
commit  6d44d355f878f3becb032aa035e127e080e59041
tree    99b49b9187d6c9efc672f71b843c8103b6dcdfe4
parent  d99d9328a948ed936c0e039e019268f9aaf94209
...
62
63
64
 
 
 
 
65
66
67
...
74
75
76
77
 
78
79
80
...
107
108
109
 
 
 
 
 
 
 
 
 
 
 
 
110
111
112
...
131
132
133
 
 
 
 
 
 
 
 
 
 
 
 
 
134
135
136
...
62
63
64
65
66
67
68
69
70
71
...
78
79
80
 
81
82
83
84
...
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
...
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
0
@@ -62,6 +62,10 @@ class Page
0
     @raw_body ||= File.exists?(@filename) ? File.read(@filename) : ''
0
   end
0
 
0
+ def destroy!
0
+ `cd #{GIT_REPO} && git rm #{@name} && git commit -m "Destroyed #{@name}"`
0
+ end
0
+
0
   def body=(content)
0
     File.open(@filename, 'w') { |f| f << content }
0
     message = tracked? ? "Edited #{@name}" : "Created #{@name}"
0
@@ -74,7 +78,7 @@ class Page
0
   end
0
 
0
   def to_s
0
- "<li><strong><a href='/#{@name}'>#{@name}</a></strong> — <a href='/e/#{@name}'>edit</a></li>"
0
+ "<li><strong><a href='/#{@name}'>#{@name}</a></strong> — <a href='/e/#{@name}'>edit</a> - <a href='/d/#{@name}'>destroy</a></li>"
0
   end
0
 end
0
 
0
@@ -107,6 +111,18 @@ post '/e/:page' do
0
   redirect '/' + @page.name
0
 end
0
 
0
+get '/d/:page' do
0
+ @page = Page.new(params[:page])
0
+ haml(destroy)
0
+end
0
+
0
+post '/d/:page' do
0
+ @page = Page.new(params[:page])
0
+ @page.destroy!
0
+
0
+ redirect '/' + HOMEPAGE
0
+end
0
+
0
 def layout(title, content)
0
   %Q(
0
 %html
0
@@ -131,6 +147,19 @@ def show
0
   ))
0
 end
0
 
0
+def destroy
0
+ layout("Delete #{@page.title}?", %q(
0
+ %h1
0
+ Delete
0
+ = @page.title
0
+ ?
0
+ %p Are you sure you want to delete this page?
0
+ %form{ :method => 'POST', :action => '/d/' + params[:page]}
0
+ %p
0
+ %input{:type => :submit, :value => 'Yes, delete', :class => :submit}
0
+ ))
0
+end
0
+
0
 def edit
0
   layout("Editing #{@page.title}", %q(
0
     %h1

Comments

    No one has commented yet.