2015-01-19 01:48:03 +01:00
|
|
|
module FoodsoftWiki
|
|
|
|
class WikiParser < WikiCloth::Parser
|
|
|
|
|
2015-01-19 01:48:42 +01:00
|
|
|
template do |template|
|
|
|
|
Foodsoft::ExpansionVariables.get(template)
|
|
|
|
end
|
|
|
|
|
2015-01-19 01:48:03 +01:00
|
|
|
url_for do |page|
|
|
|
|
url_for page
|
|
|
|
end
|
|
|
|
|
2019-06-13 12:06:55 +02:00
|
|
|
link_attributes_for do |page_anchor|
|
|
|
|
page, anchor = page_anchor.split(/#/, 2)
|
2015-01-19 01:48:03 +01:00
|
|
|
permalink = Page.permalink(page)
|
2019-06-13 12:06:55 +02:00
|
|
|
if page.empty?
|
|
|
|
{ href: '#' + anchor }
|
|
|
|
elsif Page.exists?(:permalink => permalink)
|
|
|
|
{ href: url_for(:wiki_page_path, permalink: permalink, anchor: anchor) }
|
2015-01-19 01:48:03 +01:00
|
|
|
else
|
|
|
|
{ href: url_for(:new_page_path, title: page, parent: params[:referer]), class: 'new_wiki_link' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
section_link do |section|
|
|
|
|
""
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_html(render_options = {})
|
|
|
|
# workaround for wikicloth 0.8.0 https://github.com/nricciar/wikicloth/pull/59
|
|
|
|
render_options[:locale] ||= I18n.locale
|
|
|
|
super(render_options)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def url_for(path_name, options={})
|
|
|
|
Rails.application.routes.url_helpers.send path_name, options.merge({foodcoop: FoodsoftConfig.scope})
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|