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

View File

@ -447,9 +447,7 @@ ul.autocomplete .informal {
.wiki_show, .wiki_version, .wiki_new, .wiki_edit, .wiki_all {
margin-top: 30px;
padding: 10px;
border: 1px solid #78b74e;
background-color: #F5FFFA; }
padding: 10px; }
.wiki_show h1, .wiki_version h1, .wiki_new h1, .wiki_edit h1, .wiki_all h1 {
padding-left: 0;
padding-top: 10px;
@ -493,8 +491,18 @@ a.new_wiki_link {
border: 1px dotted grey;
padding: 0 1em; }
#toc {
float: right; }
#wikitoc {
padding: 5px;
margin-bottom: 2em;
width: 25em;
border: 1px solid grey;
background-color: #efefef; }
#wikitoc h2 {
font-size: 1em;
color: black; }
#wikitoc h2 span a {
font-size: 0.5em;
color: grey; }
#breadcrump {
font-size: 0.5em;

View File

@ -447,9 +447,7 @@ ul.autocomplete .informal {
.wiki_show, .wiki_version, .wiki_new, .wiki_edit, .wiki_all {
margin-top: 30px;
padding: 10px;
border: 1px solid #78b74e;
background-color: #F5FFFA; }
padding: 10px; }
.wiki_show h1, .wiki_version h1, .wiki_new h1, .wiki_edit h1, .wiki_all h1 {
padding-left: 0;
padding-top: 10px;
@ -493,8 +491,18 @@ a.new_wiki_link {
border: 1px dotted grey;
padding: 0 1em; }
#toc {
float: right; }
#wikitoc {
padding: 5px;
margin-bottom: 2em;
width: 25em;
border: 1px solid grey;
background-color: #efefef; }
#wikitoc h2 {
font-size: 1em;
color: black; }
#wikitoc h2 span a {
font-size: 0.5em;
color: grey; }
#breadcrump {
font-size: 0.5em;

View File

@ -496,8 +496,6 @@ ul.autocomplete
.wiki_show, .wiki_version, .wiki_new, .wiki_edit, .wiki_all
margin-top: 30px
padding: 10px
border: 1px solid #78b74e
background-color: #F5FFFA
h1
padding-left: 0
padding-top: 10px
@ -541,8 +539,19 @@ a.new_wiki_link
#preview
border: 1px dotted grey
padding: 0 1em
#toc
float: right
#wikitoc
padding: 5px
margin-bottom: 2em
width: 25em
border: 1px solid grey
:background-color= !lightGrey
h2
font-size: 1em
color: black
span a
font-size: 0.5em
color: grey
#breadcrump
font-size: 0.5em
margin-bottom: 5px

View File

@ -127,7 +127,7 @@ class WikiBuffer
self.data.gsub!(/^([-]{4,})/) { |r| "<hr />" }
self.data.gsub!(/^([=]{1,6})\s*(.*?)\s*(\1)/) { |r|
@section_count += 1
"<h#{$1.length}>" + (@noeditsection == true ? "" :
"<a name='section-#{@section_count}' /><h#{$1.length}>" + (@noeditsection == true ? "" :
"<span class=\"editsection\">[<a href=\"" + @options[:link_handler].section_link(@section_count) +
"\" title=\"Edit section: #{$2}\">edit</a>]</span>") +
" <span class=\"mw-headline\">#{$2}</span></h#{$1.length}>"