2005-03-25 20:32:28 +01:00
|
|
|
$: << File.dirname(__FILE__) + "../../lib"
|
2005-01-24 19:52:04 +01:00
|
|
|
|
|
|
|
require 'redcloth'
|
2005-04-10 19:48:50 +02:00
|
|
|
require 'bluecloth_tweaked'
|
2005-01-24 19:52:04 +01:00
|
|
|
require 'rdocsupport'
|
|
|
|
require 'chunks/chunk'
|
|
|
|
|
2005-03-25 20:11:41 +01:00
|
|
|
# The markup engines are Chunks that call the one of RedCloth
|
2005-01-24 19:52:04 +01:00
|
|
|
# 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)
|
2005-03-27 20:13:43 +02:00
|
|
|
content.replace(new_chunk.mask)
|
2005-02-04 19:57:42 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# Never create engines by constructor - use apply_to instead
|
2005-03-27 20:13:43 +02:00
|
|
|
def initialize(content)
|
|
|
|
@content = content
|
2005-02-04 19:57:42 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
class Textile < AbstractEngine
|
2005-03-27 20:13:43 +02:00
|
|
|
def mask
|
2005-04-10 19:48:50 +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)
|
2005-01-24 19:52:04 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-02-04 19:57:42 +01:00
|
|
|
class Markdown < AbstractEngine
|
2005-04-08 07:02:48 +02:00
|
|
|
def mask
|
2005-04-10 19:10:11 +02:00
|
|
|
BlueCloth.new(@content, @content.options[:engine_opts]).to_html
|
2005-04-08 07:02:48 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Mixed < AbstractEngine
|
2005-03-27 20:13:43 +02:00
|
|
|
def mask
|
2005-05-01 04:47:57 +02:00
|
|
|
redcloth = RedCloth.new(@content, @content.options[:engine_opts])
|
|
|
|
redcloth.filter_html = false
|
|
|
|
redcloth.no_span_caps = false
|
|
|
|
redcloth.to_html
|
2005-01-24 19:52:04 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-02-04 19:57:42 +01:00
|
|
|
class RDoc < AbstractEngine
|
2005-03-27 20:13:43 +02:00
|
|
|
def mask
|
|
|
|
RDocSupport::RDocFormatter.new(@content).to_html
|
2005-01-24 19:52:04 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-04-10 19:57:24 +02:00
|
|
|
MAP = { :textile => Textile, :markdown => Markdown, :mixed => Mixed, :rdoc => RDoc }
|
2005-02-18 15:21:17 +01:00
|
|
|
MAP.default = Textile
|
2005-01-24 19:52:04 +01:00
|
|
|
end
|