2009-03-25 19:54:04 +01:00
|
|
|
module PagesHelper
|
2009-08-11 14:30:35 +02:00
|
|
|
include WikiCloth
|
2009-03-25 19:54:04 +01:00
|
|
|
|
2009-08-12 19:00:45 +02:00
|
|
|
def wikified_body(body, title = nil)
|
|
|
|
WikiCloth.new({:data => body+"\n", :link_handler => Wikilink.new, :params => {:referer => title}}).to_html
|
2009-06-11 22:40:56 +02:00
|
|
|
end
|
2009-05-20 14:06:40 +02:00
|
|
|
|
2009-08-16 01:09:11 +02:00
|
|
|
def link_to_wikipage(page, text = nil)
|
|
|
|
if text == nil
|
|
|
|
link_to page.title, "/wiki/#{page.title}"
|
|
|
|
else
|
|
|
|
link_to text, "/wiki/#{page.title}"
|
|
|
|
end
|
2009-08-12 18:41:25 +02:00
|
|
|
end
|
2009-08-19 22:59:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
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
|
2009-05-20 14:06:40 +02:00
|
|
|
|
2009-09-28 14:57:11 +02:00
|
|
|
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
|
2009-03-25 19:54:04 +01:00
|
|
|
end
|