From 47d3232e4e0a53d2920e88395cd5b90c5d00b732 Mon Sep 17 00:00:00 2001 From: sandoz Date: Wed, 19 Aug 2009 22:59:53 +0200 Subject: [PATCH] Fix problem in breadcrumps, when no "Home"-page exists. --- app/helpers/pages_helper.rb | 16 ++++++++++++++++ app/views/pages/all.html.haml | 2 +- app/views/pages/edit.html.haml | 2 +- app/views/pages/new.html.haml | 2 +- app/views/pages/show.html.haml | 2 +- app/views/pages/version.html.haml | 2 +- 6 files changed, 21 insertions(+), 5 deletions(-) diff --git a/app/helpers/pages_helper.rb b/app/helpers/pages_helper.rb index cce3fea5..e720b9dd 100644 --- a/app/helpers/pages_helper.rb +++ b/app/helpers/pages_helper.rb @@ -20,6 +20,22 @@ module PagesHelper link_to text, "/wiki/#{page.title}" end end + + + def link_to_wikipage_by_permalink(permalink, text = nil) + unless permalink.blank? + page = Page.find_by_permalink(permalink) + if page.nil? + if text.nil? + link_to permalink, new_page_path(:title => permalink) + else + link_to text, new_page_path(:title => permalink) + end + else + link_to_wikipage(page, text) + end + end + end # def generate_toc(body) # toc = "" # body.gsub(/^([=]{1,6})\s*(.*?)\s*(\1)/) do diff --git a/app/views/pages/all.html.haml b/app/views/pages/all.html.haml index b430f6fa..47432e42 100644 --- a/app/views/pages/all.html.haml +++ b/app/views/pages/all.html.haml @@ -2,7 +2,7 @@ .wiki_all #breadcrump - = link_to_wikipage(Page.find_by_permalink("Home"), "Foodcoop-Wiki") + = link_to_wikipage_by_permalink("Home", "Foodcoop-Wiki") %h1 Alle Wikiseite diff --git a/app/views/pages/edit.html.haml b/app/views/pages/edit.html.haml index 9912ad19..d6801c67 100644 --- a/app/views/pages/edit.html.haml +++ b/app/views/pages/edit.html.haml @@ -2,7 +2,7 @@ .wiki_edit #breadcrump - = link_to_wikipage(Page.find_by_permalink("Home"), "Foodcoop-Wiki") + = link_to_wikipage_by_permalink("Home", "Foodcoop-Wiki") - for page in @page.ancestors.reverse %span.wikiSeparator > = link_to_wikipage(page) diff --git a/app/views/pages/new.html.haml b/app/views/pages/new.html.haml index 2c532b9b..c54e4605 100644 --- a/app/views/pages/new.html.haml +++ b/app/views/pages/new.html.haml @@ -2,7 +2,7 @@ .wiki_new #breadcrump - = link_to_wikipage(Page.find_by_permalink("Home"), "Foodcoop-Wiki") + = link_to_wikipage_by_permalink("Home", "Foodcoop-Wiki") - parent_page = Page.find_by_permalink(params[:parent]) - if parent_page != nil - for page in parent_page.ancestors.reverse diff --git a/app/views/pages/show.html.haml b/app/views/pages/show.html.haml index 064f4fd5..55f94eb7 100644 --- a/app/views/pages/show.html.haml +++ b/app/views/pages/show.html.haml @@ -3,7 +3,7 @@ .wiki_show #breadcrump - = link_to_wikipage(Page.find_by_permalink("Home"), "Foodcoop-Wiki") + = link_to_wikipage_by_permalink("Home", "Foodcoop-Wiki") - for page in @page.ancestors.reverse %span.wikiSeparator > = link_to_wikipage(page) diff --git a/app/views/pages/version.html.haml b/app/views/pages/version.html.haml index dcfa477e..f1b6467c 100644 --- a/app/views/pages/version.html.haml +++ b/app/views/pages/version.html.haml @@ -2,7 +2,7 @@ .wiki_version #breadcrump - = link_to_wikipage(Page.find_by_permalink("Home"), "Foodcoop-Wiki") + = link_to_wikipage_by_permalink("Home", "Foodcoop-Wiki") - for page in @page.ancestors.reverse %span.wikiSeparator > = link_to_wikipage(page)