Skip to content

Commit

Permalink
wiki create and delete operations work
Browse files Browse the repository at this point in the history
  • Loading branch information
andyl committed Apr 5, 2013
1 parent 985e6f5 commit 8182ec2
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 38 deletions.
30 changes: 21 additions & 9 deletions app/controllers/wiki_controller.rb
Expand Up @@ -9,15 +9,20 @@ def index
end

def new
@dir = params[:dir]
setenv
@cancel = params['cancel']
@path[0] = "new"
end

def show
setenv
end

def create

setenv
#noinspection RubyArgCount
@wiki.write_page(params['newpage'], :markdown, params["text_area"], commit)
redirect_to "/wiki/#{params['newpage']}/show", :notice => "Successful Creation"
end

def edit
Expand All @@ -30,34 +35,42 @@ def rename

def update
setenv
commit = {message: "HELLO THERE",
name: current_member.full_name,
email: current_member.emails.first.address }
#noinspection RubyArgCount
@wiki.update_page(@page, @page.name, @page.format, params["text_area"], commit)
redirect_to "/wiki/#{@page.url_path}/show", :notice => "Successful Update"
end

def reproc
setenv
commit = {message: "HELLO THERE",
name: current_member.full_name,
email: current_member.emails.first.address }
@wiki.rename_page(@page, params['newpage'], commit)
redirect_to "/wiki/#{params['newpage']}/show", :notice => "Successful Update"
end

def destroy
setenv
@wiki.delete_page(@page, commit)
ext = @dir.nil? ? "" : "/#{@dir}"
redirect_to "/wiki#{ext}", :notice => "Page was deleted"
end

private

def commit
{
message: "HELLO THERE",
name: current_member.full_name,
email: current_member.emails.first.address
}
end

def setenv
@wiki = Gollum::Wiki.new(Rails.root.join('wiki').to_s, :base_path => "../wiki")
@dir = params['dir']
page = params['page']
@path = get_path(@wiki, @dir, page)
@dirs = get_dirs(@wiki, @dir)
@pages = get_pages(@wiki, @dir)
#noinspection RubyArgCount
@page = @pages.select {|x| x.url_path.split('/').last == page}.try(:first)
end

Expand All @@ -79,7 +92,6 @@ def get_dirs(wiki, dir)

def get_pages(wiki, dir)
if dir.blank?
"BLANK"
wiki.pages.select {|x| ! x.url_path.include? '/'}
else
wiki.pages.select {|x| x.url_path.include? "#{dir}/"}
Expand Down
50 changes: 44 additions & 6 deletions app/helpers/wiki_helper.rb
@@ -1,9 +1,19 @@
module WikiHelper

def wiki_path
return "wiki" if @path.length == 1
return "<a href='/wiki'>wiki</a> / #{@path[1]}" if @path.length == 2
"<a href='/wiki'>wiki</a> / <a href='/wiki/#{@path[1]}'>#{@path[1]}</a> / #{@path[2]}"
def wiki_nav_path
wiklink = "<a href='/wiki'>wiki</a>"
if @path.first == "new"
case @path.length
when 1 then wiklink
else "#{wiklink} / <a href='/wiki/#{@path[1]}'>#{@path[1]}</a>"
end
else
case @path.length
when 1 then wiklink
when 2 then "<a href='/wiki'>wiki</a> / #{@path[1]}"
else "#{wiklink} / <a href='/wiki/#{@path[1]}'>#{@path[1]}</a> / #{@path[2]}"
end
end
end

def wiki_dirs
Expand All @@ -23,13 +33,18 @@ def wiki_pages
end

def wiki_index_nav
"New"
path = @dir.nil? ? "" : "#{@dir}/"
new = "<a href='/wiki/#{path}new?cancel=/wiki/#{path}'>New</a>"
new
end

def wiki_show_nav
path = @dir.nil? ? "" : "#{@dir}/"
new = "<a href='/wiki/#{path}new?cancel=/wiki/#{@page.try(:url_path)}/show'>New</a>"
edit = "<a href='/wiki/#{@page.try(:url_path)}/edit'>Edit</a>"
rename = "<a href='/wiki/#{@page.try(:url_path)}/rename'>Rename</a>"
"New | #{edit} | #{rename} | Delete"
delete = "<a href='/wiki/#{@page.try(:url_path)}/delete'>Delete</a>"
"#{new} | #{edit} | #{rename} | #{delete}"
end

def wiki_edit_nav
Expand All @@ -42,6 +57,13 @@ def wiki_edit_nav
EOF
end

def wiki_edit_content
<<-EOF
<textarea rows=25 cols=80 name='text_area'>#{@page.raw_data}</textarea>
</form>
EOF
end

def wiki_rename_nav
<<-EOF
<form action="/wiki/#{@page.url_path}/rename" method='post'>
Expand All @@ -59,5 +81,21 @@ def wiki_rename_content
EOF
end

def wiki_new_nav
<<-EOF
<form action="/wiki" method='post'>
<input name='authenticity_token' type='hidden' value='#{form_authenticity_token}'>
<input type='submit' value='Save'/> | <a href='#{@cancel}'>Cancel</a>
EOF
end

def wiki_new_content
<<-EOF
New page name: <input name='newpage' value=''/>
<textarea rows=25 cols=80 name='text_area'>New content here...</textarea>
</form>
EOF
end

end

2 changes: 1 addition & 1 deletion app/views/wiki/_foundation.html.erb
Expand Up @@ -15,7 +15,7 @@

<table width=100% style='background: #c2cfd3;'>
<tr>
<td align=left><%= raw wiki_path %></td>
<td align=left><%= raw wiki_nav_path %></td>
<td align=right><%= raw nav %></td>
</tr>
</table>
Expand Down
2 changes: 1 addition & 1 deletion app/views/wiki/edit.html.erb
Expand Up @@ -4,6 +4,6 @@
render :partial => 'foundation',
:locals => {
:nav => wiki_edit_nav,
:content => "<textarea rows=25 cols=80 name='text_area'>#{@page.raw_data}</textarea></form>"
:content => wiki_edit_content
}
%>
29 changes: 8 additions & 21 deletions app/views/wiki/new.html.erb
@@ -1,23 +1,10 @@
<div id=x_container>
<div id=x_wide_body>
<div id=x_header>
<table width=100%>
<tr>
<td align=left><b>BAMRU Wiki</b></td>
<td align=right>
<%# raw wiki_nav %>
WIKI NAV
</td>
</tr>
</table>
</div>
<%= csrf_meta_tag %>
<div id=x_single_col>
<%=
render :partial => 'foundation',
:locals => {
:nav => wiki_new_nav,
:content => wiki_new_content
}
%>

WIKI NEW

</div>
<div id=x_footer> </div>

</div>
</div>
4 changes: 4 additions & 0 deletions config/routes.rb
Expand Up @@ -2,6 +2,7 @@

get "wiki/new" => "wiki#new"
get "wiki/:dir/new" => "wiki#new"
get "wiki/:dir/:page/new" => "wiki#new"
get "wiki" => "wiki#index"
get "wiki/:dir" => "wiki#index"
get "wiki/:dir/:page/edit" => "wiki#edit"
Expand All @@ -14,6 +15,9 @@
put "wiki/:page/rename" => "wiki#reproc"
put "wiki/:dir/:page" => "wiki#update"
put "wiki/:page" => "wiki#update"
get "wiki/:page/delete" => "wiki#destroy"
get "wiki/:dir/:page/delete" => "wiki#destroy"
post "wiki" => "wiki#create"

get "home/admin"
get "home/index"
Expand Down

0 comments on commit 8182ec2

Please sign in to comment.