From 9ea307b9d27f057da8abcac4e6cf19e755ca52f1 Mon Sep 17 00:00:00 2001 From: Alexey Verkhovsky Date: Fri, 4 Feb 2005 18:57:42 +0000 Subject: [PATCH] cleanup of chunks/engines [Denis] --- app/models/chunks/engines.rb | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/app/models/chunks/engines.rb b/app/models/chunks/engines.rb index f125203c..9d8dd009 100644 --- a/app/models/chunks/engines.rb +++ b/app/models/chunks/engines.rb @@ -9,30 +9,45 @@ require 'chunks/chunk' # or RDoc to convert text. This markup occurs when the chunk is required # to mask itself. module Engines - class Textile < Chunk::Abstract - def self.pattern() /^(.*)$/m end + class AbstractEngine < Chunk::Abstract + + # Create a new chunk for the whole content and replace it with its mask. + def self.apply_to(content) + new_chunk = self.new(content) + content.chunks << new_chunk + content.replace(new_chunk.mask(content)) + end + + def unmask(content) + self + end + + private + + # Never create engines by constructor - use apply_to instead + def initialize(text) + @text = text + end + + end + + class Textile < AbstractEngine def mask(content) RedCloth.new(text,content.options[:engine_opts]).to_html end - def unmask(content) self end end - class Markdown < Chunk::Abstract - def self.pattern() /^(.*)$/m end + class Markdown < AbstractEngine def mask(content) BlueCloth.new(text,content.options[:engine_opts]).to_html end - def unmask(content) self end end - class RDoc < Chunk::Abstract - def self.pattern() /^(.*)$/m end + class RDoc < AbstractEngine def mask(content) RDocSupport::RDocFormatter.new(text).to_html end - def unmask(content) self end end MAP = { :textile => Textile, :markdown => Markdown, :rdoc => RDoc } end -