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:
parent
741815e24e
commit
67661cb716
9 changed files with 72 additions and 40 deletions
|
@ -85,7 +85,7 @@ class PagesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def all
|
def all
|
||||||
@pages = Page.all :order => 'created_at', :conditions => {:redirect => nil}
|
@pages = Page.all :order => 'updated_at DESC', :conditions => {:redirect => nil}
|
||||||
end
|
end
|
||||||
|
|
||||||
def version
|
def version
|
||||||
|
|
|
@ -2,7 +2,7 @@ module PagesHelper
|
||||||
include WikiCloth
|
include WikiCloth
|
||||||
|
|
||||||
# def build_anchors(body)
|
# 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
|
# header = $1
|
||||||
# token = $2.downcase.gsub(' ', '-')
|
# token = $2.downcase.gsub(' ', '-')
|
||||||
# "<a name='#{token}'> </a>#{header}"
|
# "<a name='#{token}'> </a>#{header}"
|
||||||
|
@ -36,22 +36,25 @@ module PagesHelper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
# def generate_toc(body)
|
|
||||||
# toc = ""
|
def generate_toc(body)
|
||||||
# body.gsub(/^([=]{1,6})\s*(.*?)\s*(\1)/) do
|
toc = String.new
|
||||||
# number = $1.length - 1
|
body.gsub(/^([=]{1,6})\s*(.*?)\s*(\1)/) do
|
||||||
# name = $2
|
number = $1.length - 1
|
||||||
#
|
name = $2
|
||||||
# toc << "#" * number + " #{name}\n"
|
|
||||||
# end
|
toc << "*" * number + " #{name}\n"
|
||||||
# toc = WikiCloth.new({:data => toc, :link_handler => Wikilink.new}).to_html
|
end
|
||||||
#
|
logger.debug toc.inspect
|
||||||
# toc.gsub(/<li>([^<>\n]*)/) do
|
unless toc.blank?
|
||||||
# name = $1
|
toc = WikiCloth.new({:data => toc, :link_handler => Wikilink.new}).to_html
|
||||||
# token = name.downcase.gsub(' ', '-')
|
|
||||||
#
|
section_count = 0
|
||||||
# "<li><a href='##{token}'>#{name}</a>"
|
toc.gsub(/<li>([^<>\n]*)/) do
|
||||||
# end
|
section_count += 1
|
||||||
# end
|
"<li><a href='#section-#{section_count}'>#{$1}</a>"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
- content = wikified_body @page.body, @page.title
|
- content = wikified_body @page.body, @page.title
|
||||||
//#toc
|
- toc = generate_toc @page.body
|
||||||
//%h2 Inhaltsverzeichnis
|
- unless toc.blank?
|
||||||
//= generate_toc @page.body
|
#wikitoc
|
||||||
|
%h2
|
||||||
|
Inhaltsverzeichnis
|
||||||
|
%span= link_to_function "[verstecken]", "Element.toggle('wikitoc-content')"
|
||||||
|
#wikitoc-content= toc
|
||||||
#wiki_content= content
|
#wiki_content= content
|
|
@ -4,7 +4,7 @@
|
||||||
#breadcrump
|
#breadcrump
|
||||||
= link_to_wikipage_by_permalink("Home", "Foodcoop-Wiki")
|
= link_to_wikipage_by_permalink("Home", "Foodcoop-Wiki")
|
||||||
|
|
||||||
%h1 Alle Wikiseite
|
%h1 Alle Wikiseiten
|
||||||
|
|
||||||
%p= link_to "Neue Seite anlegen", new_page_path
|
%p= link_to "Neue Seite anlegen", new_page_path
|
||||||
|
|
||||||
|
@ -15,4 +15,4 @@
|
||||||
- for page in @pages
|
- for page in @pages
|
||||||
%tr
|
%tr
|
||||||
%td= link_to page.title, wiki_page_path(page.permalink)
|
%td= link_to page.title, wiki_page_path(page.permalink)
|
||||||
%td= format_date page.updated_at
|
%td= format_datetime page.updated_at
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
= "(#{User.find(version.updated_by).nick})"
|
= "(#{User.find(version.updated_by).nick})"
|
||||||
|
|
||||||
- unless @page.children.empty?
|
- unless @page.children.empty?
|
||||||
#subpages
|
#subpages{:style => "display:none"}
|
||||||
.box_title
|
.box_title
|
||||||
%h2 Unterseiten
|
%h2 Unterseiten
|
||||||
.column_content
|
.column_content
|
||||||
|
|
|
@ -447,9 +447,7 @@ ul.autocomplete .informal {
|
||||||
|
|
||||||
.wiki_show, .wiki_version, .wiki_new, .wiki_edit, .wiki_all {
|
.wiki_show, .wiki_version, .wiki_new, .wiki_edit, .wiki_all {
|
||||||
margin-top: 30px;
|
margin-top: 30px;
|
||||||
padding: 10px;
|
padding: 10px; }
|
||||||
border: 1px solid #78b74e;
|
|
||||||
background-color: #F5FFFA; }
|
|
||||||
.wiki_show h1, .wiki_version h1, .wiki_new h1, .wiki_edit h1, .wiki_all h1 {
|
.wiki_show h1, .wiki_version h1, .wiki_new h1, .wiki_edit h1, .wiki_all h1 {
|
||||||
padding-left: 0;
|
padding-left: 0;
|
||||||
padding-top: 10px;
|
padding-top: 10px;
|
||||||
|
@ -493,8 +491,18 @@ a.new_wiki_link {
|
||||||
border: 1px dotted grey;
|
border: 1px dotted grey;
|
||||||
padding: 0 1em; }
|
padding: 0 1em; }
|
||||||
|
|
||||||
#toc {
|
#wikitoc {
|
||||||
float: right; }
|
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 {
|
#breadcrump {
|
||||||
font-size: 0.5em;
|
font-size: 0.5em;
|
||||||
|
|
|
@ -447,9 +447,7 @@ ul.autocomplete .informal {
|
||||||
|
|
||||||
.wiki_show, .wiki_version, .wiki_new, .wiki_edit, .wiki_all {
|
.wiki_show, .wiki_version, .wiki_new, .wiki_edit, .wiki_all {
|
||||||
margin-top: 30px;
|
margin-top: 30px;
|
||||||
padding: 10px;
|
padding: 10px; }
|
||||||
border: 1px solid #78b74e;
|
|
||||||
background-color: #F5FFFA; }
|
|
||||||
.wiki_show h1, .wiki_version h1, .wiki_new h1, .wiki_edit h1, .wiki_all h1 {
|
.wiki_show h1, .wiki_version h1, .wiki_new h1, .wiki_edit h1, .wiki_all h1 {
|
||||||
padding-left: 0;
|
padding-left: 0;
|
||||||
padding-top: 10px;
|
padding-top: 10px;
|
||||||
|
@ -493,8 +491,18 @@ a.new_wiki_link {
|
||||||
border: 1px dotted grey;
|
border: 1px dotted grey;
|
||||||
padding: 0 1em; }
|
padding: 0 1em; }
|
||||||
|
|
||||||
#toc {
|
#wikitoc {
|
||||||
float: right; }
|
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 {
|
#breadcrump {
|
||||||
font-size: 0.5em;
|
font-size: 0.5em;
|
||||||
|
|
|
@ -496,8 +496,6 @@ ul.autocomplete
|
||||||
.wiki_show, .wiki_version, .wiki_new, .wiki_edit, .wiki_all
|
.wiki_show, .wiki_version, .wiki_new, .wiki_edit, .wiki_all
|
||||||
margin-top: 30px
|
margin-top: 30px
|
||||||
padding: 10px
|
padding: 10px
|
||||||
border: 1px solid #78b74e
|
|
||||||
background-color: #F5FFFA
|
|
||||||
h1
|
h1
|
||||||
padding-left: 0
|
padding-left: 0
|
||||||
padding-top: 10px
|
padding-top: 10px
|
||||||
|
@ -541,8 +539,19 @@ a.new_wiki_link
|
||||||
#preview
|
#preview
|
||||||
border: 1px dotted grey
|
border: 1px dotted grey
|
||||||
padding: 0 1em
|
padding: 0 1em
|
||||||
#toc
|
#wikitoc
|
||||||
float: right
|
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
|
#breadcrump
|
||||||
font-size: 0.5em
|
font-size: 0.5em
|
||||||
margin-bottom: 5px
|
margin-bottom: 5px
|
||||||
|
|
2
vendor/plugins/wikicloth/lib/wiki_buffer.rb
vendored
2
vendor/plugins/wikicloth/lib/wiki_buffer.rb
vendored
|
@ -127,7 +127,7 @@ class WikiBuffer
|
||||||
self.data.gsub!(/^([-]{4,})/) { |r| "<hr />" }
|
self.data.gsub!(/^([-]{4,})/) { |r| "<hr />" }
|
||||||
self.data.gsub!(/^([=]{1,6})\s*(.*?)\s*(\1)/) { |r|
|
self.data.gsub!(/^([=]{1,6})\s*(.*?)\s*(\1)/) { |r|
|
||||||
@section_count += 1
|
@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) +
|
"<span class=\"editsection\">[<a href=\"" + @options[:link_handler].section_link(@section_count) +
|
||||||
"\" title=\"Edit section: #{$2}\">edit</a>]</span>") +
|
"\" title=\"Edit section: #{$2}\">edit</a>]</span>") +
|
||||||
" <span class=\"mw-headline\">#{$2}</span></h#{$1.length}>"
|
" <span class=\"mw-headline\">#{$2}</span></h#{$1.length}>"
|
||||||
|
|
Loading…
Reference in a new issue