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
|
# or RDoc to convert text. This markup occurs when the chunk is required
|
||||||
# to mask itself.
|
# to mask itself.
|
||||||
module Engines
|
module Engines
|
||||||
class Textile < Chunk::Abstract
|
class AbstractEngine < Chunk::Abstract
|
||||||
def self.pattern() /^(.*)$/m end
|
|
||||||
|
# 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)
|
def mask(content)
|
||||||
RedCloth.new(text,content.options[:engine_opts]).to_html
|
RedCloth.new(text,content.options[:engine_opts]).to_html
|
||||||
end
|
end
|
||||||
def unmask(content) self end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class Markdown < Chunk::Abstract
|
class Markdown < AbstractEngine
|
||||||
def self.pattern() /^(.*)$/m end
|
|
||||||
def mask(content)
|
def mask(content)
|
||||||
BlueCloth.new(text,content.options[:engine_opts]).to_html
|
BlueCloth.new(text,content.options[:engine_opts]).to_html
|
||||||
end
|
end
|
||||||
def unmask(content) self end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class RDoc < Chunk::Abstract
|
class RDoc < AbstractEngine
|
||||||
def self.pattern() /^(.*)$/m end
|
|
||||||
def mask(content)
|
def mask(content)
|
||||||
RDocSupport::RDocFormatter.new(text).to_html
|
RDocSupport::RDocFormatter.new(text).to_html
|
||||||
end
|
end
|
||||||
def unmask(content) self end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
MAP = { :textile => Textile, :markdown => Markdown, :rdoc => RDoc }
|
MAP = { :textile => Textile, :markdown => Markdown, :rdoc => RDoc }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue