2005-01-24 19:52:04 +01:00
|
|
|
$: << File.dirname(__FILE__) + "../../libraries"
|
|
|
|
|
|
|
|
require 'redcloth'
|
|
|
|
require 'bluecloth'
|
|
|
|
require 'rdocsupport'
|
|
|
|
require 'chunks/chunk'
|
|
|
|
|
|
|
|
# The markup engines are Chunks that call the one of RedCloth, BlueCloth
|
|
|
|
# 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.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
|
2005-01-24 19:52:04 +01:00
|
|
|
def mask(content)
|
|
|
|
RedCloth.new(text,content.options[:engine_opts]).to_html
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-02-04 19:57:42 +01:00
|
|
|
class Markdown < AbstractEngine
|
2005-01-24 19:52:04 +01:00
|
|
|
def mask(content)
|
|
|
|
BlueCloth.new(text,content.options[:engine_opts]).to_html
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-02-04 19:57:42 +01:00
|
|
|
class RDoc < AbstractEngine
|
2005-01-24 19:52:04 +01:00
|
|
|
def mask(content)
|
|
|
|
RDocSupport::RDocFormatter.new(text).to_html
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
MAP = { :textile => Textile, :markdown => Markdown, :rdoc => RDoc }
|
2005-02-18 15:21:17 +01:00
|
|
|
MAP.default = Textile
|
2005-01-24 19:52:04 +01:00
|
|
|
end
|