From da88ac7df744d6eaa1e6e173c4fa9d4061e63356 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Thu, 26 Jan 2012 18:10:25 +0400 Subject: [PATCH] [issue #64] Some refactoring --- app/controllers/wiki_controller.rb | 42 ++++++++++++++---------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index ff2a1cd45..64f097df2 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -10,38 +10,23 @@ class WikiController < ApplicationController def index @name = 'Home' - if page = @wiki.page(@name) - @page = page - @content = page.formatted_data - @editable = true - render :show - elsif file = @wiki.file(@name) - render :text => file.raw_data, :content_type => file.mime_type - else - @new = true - @content = '' - render :new - end + @page = @wiki.page(@name) + + show_or_create_page end def show @name = params['id'] + redirect_to project_wiki_index_path(@project) and return if @name == 'Home' + ref = params['ref'] ? params['ref'] : @wiki.ref @page = @wiki.page(@name, ref) if !@page && @wiki.page(@name) flash[:error] = t('flash.wiki.ref_not_exist') - redirect_to project_wiki_path(@project, CGI.escape(@name)) - return + redirect_to project_wiki_path(@project, CGI.escape(@name)) and return end - if @page - @content = @page.formatted_data - @editable = true - render - else - @new = true - render :new - end + show_or_create_page end def edit @@ -233,5 +218,18 @@ class WikiController < ApplicationController def commit commit_message.merge({:name => current_user.name, :email => current_user.email}) end + + def show_or_create_page + if @page + @content = @page.formatted_data + @editable = true + render :show + elsif file = @wiki.file(@name) + render :text => file.raw_data, :content_type => file.mime_type + else + @new = true + render :new + end + end end