app/controllers/wiki_controller.rb in instiki-0.10.1 vs app/controllers/wiki_controller.rb in instiki-0.10.2

- old
+ new

@@ -40,18 +40,18 @@ # Within a single web --------------------------------------------------------- def authors - @authors = @web.select.authors + @authors = @web.select.authors.sort end def export_html export_pages_as_zip('html') do |page| @page = page @link_mode = :export - render_to_string('wiki/print', use_layout = true) + render_to_string('wiki/print', use_layout = (@params['layout'] != 'no')) end end def export_markup export_pages_as_zip(@web.markup) { |page| page.content } @@ -120,11 +120,11 @@ redirect_to_page(@page_name) end def edit if @page.nil? - redirect_to :action => 'index' + redirect_home elsif @page.locked?(Time.now) and not @params['break_lock'] redirect_to :web => @web_name, :action => 'locked', :id => @page_name else @page.lock(Time.now, @author) end @@ -170,32 +170,32 @@ def rollback get_page_and_revision end def save - redirect_to :action => 'index' if @page_name.nil? + redirect_home if @page_name.nil? cookies['author'] = @params['author'] begin - page = @web.pages[@page_name] - if @web.pages[@page_name] - wiki.revise_page( - @web_name, @page_name, @params['content'], Time.now, - Author.new(@params['author'], remote_ip) - ) - page.unlock + if @page + wiki.revise_page(@web_name, @page_name, @params['content'], Time.now, + Author.new(@params['author'], remote_ip)) + @page.unlock else - wiki.write_page( - @web_name, @page_name, @params['content'], Time.now, - Author.new(@params['author'], remote_ip) - ) + wiki.write_page(@web_name, @page_name, @params['content'], Time.now, + Author.new(@params['author'], remote_ip)) end redirect_to_page @page_name - rescue Instiki::ValidationError => e - page.unlock if defined? page + rescue => e flash[:error] = e - return_to_last_remembered + flash[:content] = @params['content'] + if @page + @page.unlock + redirect_to :action => 'edit', :web => @web_name, :id => @page_name + else + redirect_to :action => 'new', :web => @web_name, :id => @page_name + end end end def show if @page @@ -203,13 +203,13 @@ render_action 'page' # TODO this rescue should differentiate between errors due to rendering and errors in # the application itself (for application errors, it's better not to rescue the error at all) rescue => e logger.error e + flash[:error] = e.message if in_a_web? - redirect_to :web => @web_name, :action => 'edit', - :action_suffix => "#{@page_name}?msg=#{e.message}" + redirect_to :action => 'edit', :web => @web_name, :id => @page_name else raise e end end else @@ -258,17 +258,12 @@ zip_out.puts(block.call(page)) end # add an index file, if exporting to HTML if file_type.to_s.downcase == 'html' zip_out.put_next_entry 'index.html' - zip_out.puts <<-EOL - <html> - <head> - <META HTTP-EQUIV="Refresh" CONTENT="0;URL=HomePage.#{file_type}"> - </head> - </html> - EOL + zip_out.puts "<html><head>" + + "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0;URL=HomePage.#{file_type}\"></head></html>" end end FileUtils.rm_rf(Dir[File.join(@wiki.storage_path, file_prefix + '*.zip')]) FileUtils.mv(tmp_path, file_path) send_file file_path @@ -336,12 +331,15 @@ end end def render_to_string(template_name, with_layout = false) add_variables_to_assigns - @content_for_layout = @template.render_file(template_name) - if with_layout then @template.render_file('layouts/default'); - else @content_for_layout; end + self.assigns['content_for_layout'] = @template.render_file(template_name) + if with_layout + @template.render_file('layouts/default') + else + self.assigns['content_for_layout'] + end end def rss_with_content_allowed? @web.password.nil? or @web.published end