cleanup of chunks/engines [Denis]
This commit is contained in:
parent
2ca286971c
commit
9ea307b9d2
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue