instiki/app/models/chunks/engines.rb

55 lines
1.3 KiB
Ruby
Raw Normal View History

$: << File.dirname(__FILE__) + "../../lib"
require 'redcloth'
require 'rdocsupport'
require 'chunks/chunk'
# The markup engines are Chunks that call the one of RedCloth
# or RDoc to convert text. This markup occurs when the chunk is required
# to mask itself.
module Engines
2005-02-04 19:57:42 +01:00
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.replace(new_chunk.mask)
2005-02-04 19:57:42 +01:00
end
private
# Never create engines by constructor - use apply_to instead
def initialize(content)
@content = content
2005-02-04 19:57:42 +01:00
end
end
class Textile < AbstractEngine
def mask
RedCloth.new(@content, [:hard_breaks] + @content.options[:engine_opts]).to_html(:textile)
end
end
2005-02-04 19:57:42 +01:00
class Markdown < AbstractEngine
def mask
RedCloth.new(@content, @content.options[:engine_opts]).to_html(:markdown)
end
end
class Mixed < AbstractEngine
def mask
RedCloth.new(@content, [:hard_breaks] + @content.options[:engine_opts]).to_html
end
end
2005-02-04 19:57:42 +01:00
class RDoc < AbstractEngine
def mask
RDocSupport::RDocFormatter.new(@content).to_html
end
end
MAP = { :textile => Textile, :markdown => Markdown, :mixed => Mixed, :rdoc => RDoc, }
MAP.default = Textile
end