Sha256: 2a64a674b21a4aef66bedd9633928f55d19a42fa31adcabf82c14046c791b7aa

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

$: << File.dirname(__FILE__) + "../../lib"

require 'redcloth'
require 'rdocsupport'
require 'chunks/chunk'

# 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
      RedCloth.new(@content, @content.options[:engine_opts]).to_html(:textile)
    end
  end

  class Markdown < AbstractEngine
    def mask
      RedCloth.new(@content, @content.options[:engine_opts]).to_html(:markdown)
    end
  end

  class Mixed < AbstractEngine
    def mask
      RedCloth.new(@content, @content.options[:engine_opts]).to_html
    end
  end

  class RDoc < AbstractEngine
    def mask
      RDocSupport::RDocFormatter.new(@content).to_html
    end
  end

  MAP = { :textile => Textile, :markdown => Markdown, :mixed => Mixed, :rdoc => RDoc,  }
  MAP.default = Textile
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
instiki-0.10.0 app/models/chunks/engines.rb