Added toc to wikipages. Patched wikicloth.

* patched wikicloth to serve anchor links for sections
* added table of contents
* subpages list doesn't show up per default
This commit is contained in:
Benjamin Meichsner 2009-09-28 14:57:11 +02:00
parent 741815e24e
commit 67661cb716
9 changed files with 72 additions and 40 deletions

View file

@ -85,7 +85,7 @@ class PagesController < ApplicationController
end
def all
@pages = Page.all :order => 'created_at', :conditions => {:redirect => nil}
@pages = Page.all :order => 'updated_at DESC', :conditions => {:redirect => nil}
end
def version

View file

@ -2,7 +2,7 @@ module PagesHelper
include WikiCloth
# def build_anchors(body)
# body.gsub(/(<h\d{1}>(.+)<\/h\d{1}>)/) do
# body.gsub(/(<h\d{1}><span class=\"mw-headline\">(.+)</span><\/h\d{1}>)/) do
# header = $1
# token = $2.downcase.gsub(' ', '-')
# "<a name='#{token}'> </a>#{header}"
@ -36,22 +36,25 @@ module PagesHelper
end
end
end
# def generate_toc(body)
# toc = ""
# body.gsub(/^([=]{1,6})\s*(.*?)\s*(\1)/) do
# number = $1.length - 1
# name = $2
#
# toc << "#" * number + " #{name}\n"
# end
# toc = WikiCloth.new({:data => toc, :link_handler => Wikilink.new}).to_html
#
# toc.gsub(/<li>([^<>\n]*)/) do
# name = $1
# token = name.downcase.gsub(' ', '-')
#
# "<li><a href='##{token}'>#{name}</a>"
# end
# end
def generate_toc(body)
toc = String.new
body.gsub(/^([=]{1,6})\s*(.*?)\s*(\1)/) do
number = $1.length - 1
name = $2
toc << "*" * number + " #{name}\n"
end
logger.debug toc.inspect
unless toc.blank?
toc = WikiCloth.new({:data => toc, :link_handler => Wikilink.new}).to_html
section_count = 0
toc.gsub(/<li>([^<>\n]*)/) do
section_count += 1
"<li><a href='#section-#{section_count}'>#{$1}</a>"
end
end
end
end

View file

@ -1,5 +1,9 @@
- content = wikified_body @page.body, @page.title
//#toc
//%h2 Inhaltsverzeichnis
//= generate_toc @page.body
- toc = generate_toc @page.body
- unless toc.blank?
#wikitoc
%h2
Inhaltsverzeichnis
%span= link_to_function "[verstecken]", "Element.toggle('wikitoc-content')"
#wikitoc-content= toc
#wiki_content= content

View file

@ -4,7 +4,7 @@
#breadcrump
= link_to_wikipage_by_permalink("Home", "Foodcoop-Wiki")
%h1 Alle Wikiseite
%h1 Alle Wikiseiten
%p= link_to "Neue Seite anlegen", new_page_path
@ -15,4 +15,4 @@
- for page in @pages
%tr
%td= link_to page.title, wiki_page_path(page.permalink)
%td= format_date page.updated_at
%td= format_datetime page.updated_at

View file

@ -30,7 +30,7 @@
= "(#{User.find(version.updated_by).nick})"
- unless @page.children.empty?
#subpages
#subpages{:style => "display:none"}
.box_title
%h2 Unterseiten
.column_content