From a9304d35fb013943277d2d04661c148fcb0571f6 Mon Sep 17 00:00:00 2001 From: Alexey Verkhovsky Date: Fri, 18 Feb 2005 14:21:17 +0000 Subject: [PATCH] Simplified some code in wiki_content.rb --- app/models/chunks/engines.rb | 1 + app/models/wiki_content.rb | 28 +++++++++++----------------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/app/models/chunks/engines.rb b/app/models/chunks/engines.rb index 9d8dd009..1d7eff70 100644 --- a/app/models/chunks/engines.rb +++ b/app/models/chunks/engines.rb @@ -50,4 +50,5 @@ module Engines end MAP = { :textile => Textile, :markdown => Markdown, :rdoc => RDoc } + MAP.default = Textile end diff --git a/app/models/wiki_content.rb b/app/models/wiki_content.rb index 1b2cfe81..b1bbb030 100644 --- a/app/models/wiki_content.rb +++ b/app/models/wiki_content.rb @@ -39,16 +39,17 @@ require 'chunks/nowiki' # UPDATED: 22nd May 2004 class WikiContent < String - PRE_ENGINE_ACTIONS = [ NoWiki, Category, Include, WikiChunk::Link, URIChunk, LocalURIChunk, - WikiChunk::Word ] - POST_ENGINE_ACTIONS = [ Literal::Pre, Literal::Tags ] + PRE_ENGINE_ACTIONS = [ NoWiki, Category, Include, WikiChunk::Link, URIChunk, + LocalURIChunk, WikiChunk::Word ].freeze + POST_ENGINE_ACTIONS = [ Literal::Pre, Literal::Tags ].freeze + DEFAULT_OPTS = { :pre_engine_actions => PRE_ENGINE_ACTIONS, :post_engine_actions => POST_ENGINE_ACTIONS, :engine => Engines::Textile, :engine_opts => [], :mode => :show - } + }.freeze attr_reader :web, :options, :rendered, :chunks @@ -58,26 +59,19 @@ class WikiContent < String @revision = revision @web = @revision.page.web - # Deep copy of DEFAULT_OPTS to ensure that changes to PRE/POST_ENGINE_ACTIONS stay local - @options = Marshal.load(Marshal.dump(DEFAULT_OPTS)).update(options) - @options[:engine] = Engines::MAP[@web.markup] || Engines::Textile - @options[:engine_opts] = (@web.safe_mode ? [:filter_html, :filter_styles] : []) - - @options[:pre_engine_actions].delete(WikiChunk::Word) if @web.brackets_only + @options = DEFAULT_OPTS.dup.merge(options) + @options[:engine] = Engines::MAP[@web.markup] + @options[:engine_opts] = [:filter_html, :filter_styles] if @web.safe_mode + @options[:pre_engine_actions] = (PRE_ENGINE_ACTIONS - [WikiChunk::Word]) if @web.brackets_only super(@revision.content) - begin - 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 + render!(@options[:pre_engine_actions] + [@options[:engine]] + @options[:post_engine_actions]) end # Call @web.page_link using current options. 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) end