Simplified some code in wiki_content.rb
This commit is contained in:
parent
aa95acb4f7
commit
a9304d35fb
|
@ -50,4 +50,5 @@ module Engines
|
||||||
end
|
end
|
||||||
|
|
||||||
MAP = { :textile => Textile, :markdown => Markdown, :rdoc => RDoc }
|
MAP = { :textile => Textile, :markdown => Markdown, :rdoc => RDoc }
|
||||||
|
MAP.default = Textile
|
||||||
end
|
end
|
||||||
|
|
|
@ -39,16 +39,17 @@ require 'chunks/nowiki'
|
||||||
# UPDATED: 22nd May 2004
|
# UPDATED: 22nd May 2004
|
||||||
class WikiContent < String
|
class WikiContent < String
|
||||||
|
|
||||||
PRE_ENGINE_ACTIONS = [ NoWiki, Category, Include, WikiChunk::Link, URIChunk, LocalURIChunk,
|
PRE_ENGINE_ACTIONS = [ NoWiki, Category, Include, WikiChunk::Link, URIChunk,
|
||||||
WikiChunk::Word ]
|
LocalURIChunk, WikiChunk::Word ].freeze
|
||||||
POST_ENGINE_ACTIONS = [ Literal::Pre, Literal::Tags ]
|
POST_ENGINE_ACTIONS = [ Literal::Pre, Literal::Tags ].freeze
|
||||||
|
|
||||||
DEFAULT_OPTS = {
|
DEFAULT_OPTS = {
|
||||||
:pre_engine_actions => PRE_ENGINE_ACTIONS,
|
:pre_engine_actions => PRE_ENGINE_ACTIONS,
|
||||||
:post_engine_actions => POST_ENGINE_ACTIONS,
|
:post_engine_actions => POST_ENGINE_ACTIONS,
|
||||||
:engine => Engines::Textile,
|
:engine => Engines::Textile,
|
||||||
:engine_opts => [],
|
:engine_opts => [],
|
||||||
:mode => :show
|
:mode => :show
|
||||||
}
|
}.freeze
|
||||||
|
|
||||||
attr_reader :web, :options, :rendered, :chunks
|
attr_reader :web, :options, :rendered, :chunks
|
||||||
|
|
||||||
|
@ -58,26 +59,19 @@ class WikiContent < String
|
||||||
@revision = revision
|
@revision = revision
|
||||||
@web = @revision.page.web
|
@web = @revision.page.web
|
||||||
|
|
||||||
# Deep copy of DEFAULT_OPTS to ensure that changes to PRE/POST_ENGINE_ACTIONS stay local
|
@options = DEFAULT_OPTS.dup.merge(options)
|
||||||
@options = Marshal.load(Marshal.dump(DEFAULT_OPTS)).update(options)
|
@options[:engine] = Engines::MAP[@web.markup]
|
||||||
@options[:engine] = Engines::MAP[@web.markup] || Engines::Textile
|
@options[:engine_opts] = [:filter_html, :filter_styles] if @web.safe_mode
|
||||||
@options[:engine_opts] = (@web.safe_mode ? [:filter_html, :filter_styles] : [])
|
@options[:pre_engine_actions] = (PRE_ENGINE_ACTIONS - [WikiChunk::Word]) if @web.brackets_only
|
||||||
|
|
||||||
@options[:pre_engine_actions].delete(WikiChunk::Word) if @web.brackets_only
|
|
||||||
|
|
||||||
super(@revision.content)
|
super(@revision.content)
|
||||||
|
|
||||||
begin
|
|
||||||
render!(@options[:pre_engine_actions] + [@options[:engine]] + @options[:post_engine_actions])
|
render!(@options[:pre_engine_actions] + [@options[:engine]] + @options[:post_engine_actions])
|
||||||
# FIXME this is where all the parsing problems were shoved under the carpet
|
|
||||||
# rescue => e
|
|
||||||
# @rendered = e.message
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Call @web.page_link using current options.
|
# Call @web.page_link using current options.
|
||||||
def page_link(name, text, link_type)
|
def page_link(name, text, link_type)
|
||||||
@options[:link_type] = link_type || :show
|
@options[:link_type] = (link_type || :show)
|
||||||
@web.make_link(name, text, @options)
|
@web.make_link(name, text, @options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue