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 -