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
|
|
|
|
2014-01-04 20:12:01 +01:00
|
|
|
def rss_meta_tag
|
|
|
|
tag('link', :rel => "alternate", :type => "application/rss+xml", :title => "RSS", :href => all_pages_rss_url).html_safe
|
|
|
|
end
|
|
|
|
|
2009-08-12 19:00:45 +02:00
|
|
|
def wikified_body(body, title = nil)
|
2021-03-01 15:27:26 +01:00
|
|
|
FoodsoftWiki::WikiParser.new(data: body + "\n", params: { referer: title }).to_html(noedit: true).html_safe
|
2013-12-22 23:34:54 +01:00
|
|
|
rescue => e
|
2015-01-19 01:48:03 +01:00
|
|
|
# try the following with line breaks: === one === == two == = three =
|
|
|
|
content_tag :span, class: 'alert alert-error' do
|
|
|
|
I18n.t '.wikicloth_exception', :msg => e
|
|
|
|
end.html_safe
|
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
|
2011-05-18 15:25:05 +02:00
|
|
|
link_to page.title, wiki_page_path(:permalink => page.permalink)
|
2009-08-16 01:09:11 +02:00
|
|
|
else
|
2011-05-18 15:25:05 +02:00
|
|
|
link_to text, wiki_page_path(:permalink => page.permalink)
|
2009-08-16 01:09:11 +02:00
|
|
|
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?
|
2021-03-01 15:27:26 +01:00
|
|
|
link_to permalink, new_page_path(:title => permalink)
|
2009-08-19 22:59:53 +02:00
|
|
|
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
|
|
|
|
|
2014-09-23 19:04:23 +02:00
|
|
|
unless toc.blank?
|
2015-01-19 01:48:03 +01:00
|
|
|
FoodsoftWiki::WikiParser.new(data: toc).to_html.gsub(/<li>([^<>\n]*)/) do
|
2012-10-09 02:31:10 +02:00
|
|
|
name = $1
|
|
|
|
anchor = name.gsub(/\s/, '_').gsub(/[^a-zA-Z_]/, '')
|
|
|
|
"<li><a href='##{anchor}'>#{name.truncate(20)}</a>"
|
2011-05-18 15:25:05 +02:00
|
|
|
end.html_safe
|
2009-09-28 14:57:11 +02:00
|
|
|
end
|
|
|
|
end
|
2010-07-08 10:57:42 +02:00
|
|
|
|
|
|
|
def parent_pages_to_select(current_page)
|
2011-03-09 13:36:02 +01:00
|
|
|
unless current_page.homepage? # Homepage is the page trees root!
|
2015-01-14 21:15:08 +01:00
|
|
|
Page.non_redirected.reject { |p| p == current_page || p.ancestors.include?(current_page) }
|
2011-03-09 13:36:02 +01:00
|
|
|
else
|
|
|
|
Array.new
|
|
|
|
end
|
2010-07-08 10:57:42 +02:00
|
|
|
end
|
2014-01-04 20:12:01 +01:00
|
|
|
|
|
|
|
# return url for all_pages rss feed
|
2021-03-01 15:27:26 +01:00
|
|
|
def all_pages_rss_url(options = {})
|
2014-01-04 20:12:01 +01:00
|
|
|
token = TokenVerifier.new(['wiki', 'all']).generate
|
2021-03-01 15:27:26 +01:00
|
|
|
all_pages_url({ :format => 'rss', :token => token }.merge(options))
|
2014-01-04 20:12:01 +01:00
|
|
|
end
|
2009-03-25 19:54:04 +01:00
|
|
|
end
|