2005-08-09 04:07:39 +02:00
|
|
|
$: << File.dirname(__FILE__) + "../../lib"
|
|
|
|
|
2006-03-12 05:57:24 +01:00
|
|
|
require_dependency 'chunks/chunk'
|
2005-08-09 04:07:39 +02:00
|
|
|
|
|
|
|
# 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
|
|
|
|
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)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# Never create engines by constructor - use apply_to instead
|
|
|
|
def initialize(content)
|
|
|
|
@content = content
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
class Textile < AbstractEngine
|
|
|
|
def mask
|
2006-03-12 05:57:24 +01:00
|
|
|
require_dependency 'redcloth'
|
2005-08-09 04:07:39 +02:00
|
|
|
redcloth = RedCloth.new(@content, [:hard_breaks] + @content.options[:engine_opts])
|
|
|
|
redcloth.filter_html = false
|
|
|
|
redcloth.no_span_caps = false
|
|
|
|
redcloth.to_html(:textile)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Markdown < AbstractEngine
|
|
|
|
def mask
|
2006-03-12 05:57:24 +01:00
|
|
|
require_dependency 'bluecloth_tweaked'
|
2005-08-09 04:07:39 +02:00
|
|
|
BlueCloth.new(@content, @content.options[:engine_opts]).to_html
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Mixed < AbstractEngine
|
|
|
|
def mask
|
2006-03-12 05:57:24 +01:00
|
|
|
require_dependency 'redcloth'
|
2005-08-09 04:07:39 +02:00
|
|
|
redcloth = RedCloth.new(@content, @content.options[:engine_opts])
|
|
|
|
redcloth.filter_html = false
|
|
|
|
redcloth.no_span_caps = false
|
|
|
|
redcloth.to_html
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class RDoc < AbstractEngine
|
|
|
|
def mask
|
2006-03-12 05:57:24 +01:00
|
|
|
require_dependency 'rdocsupport'
|
2005-08-09 04:07:39 +02:00
|
|
|
RDocSupport::RDocFormatter.new(@content).to_html
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
MAP = { :textile => Textile, :markdown => Markdown, :mixed => Mixed, :rdoc => RDoc }
|
|
|
|
MAP.default = Textile
|
|
|
|
end
|