public
Description: Represent ActiveRecord Markdown, Textile, Wiki text, or RDoc columns as Markdown, Textile, Wikitext or RDoc objects using various external libraries to convert to HTML.
Homepage: http://vigetlabs.github.com/acts_as_markup/
Clone URL: git://github.com/vigetlabs/acts_as_markup.git
README.rdoc

acts_as_markup

by Brian Landau of Viget Labs <brian.landau@viget.com>

GitHub Project: github.com/vigetlabs/acts_as_markup

RDoc: viget.rubyforge.org/acts_as_markup

DESCRIPTION:

Allows you to specify columns of an ActiveRecord model that contain Markdown, Textile, Wiki text and RDoc. You may then use to_s to get the original markup text or to_html to get the formated HTML.

Additionally you can have a model that contains a column that has a column with markup text, and another that defines what language to process it as. If the field is listed as "markdown" "textile", "wikitext" or "rdoc" (case insensitive) it will treat it as such, any other value for markup language will have the value pass through as a normal string.

This AR extension can use 3 different types of Markdown processing backends: BlueCloth, RDiscount, or Ruby PEG. You specify which one you want to use by setting a config value in your environment.rb file:

    ActsAsMarkup.markdown_library = :bluecloth

By default RDiscount will be used.

EXAMPLES:

Using acts_as_markdown:

    class Post < ActiveRecrod
      acts_as_markdown :body
    end

    @post = Post.find(:first)
    @post.body.to_s     #=> "## Markdown Headline"
    @post.body.to_html  #=> "<h2> Markdown Headline</h2>"

Using acts_as_textile:

    class Post < ActiveRecrod
      acts_as_textile :body
    end

    @post = Post.find(:first)
    @post.body.to_s     #=> "h2. Textile Headline"
    @post.body.to_html  #=> "<h2>Textile Headline</h2>"

Using acts_as_wikitext:

    class Post < ActiveRecrod
      acts_as_wikitext :body
    end

    @post = Post.find(:first)
    @post.body.to_s     #=> "== Wikitext Headline =="
    @post.body.to_html  #=> "<h2>Wikitext Headline</h2>"

Using acts_as_rdoc:

    class Post < ActiveRecrod
      acts_as_rdoc :body
    end

    @post = Post.find(:first)
    @post.body.to_s     #=> "== RDoc Headline"
    @post.body.to_html  #=> "<h2>RDoc Headline</h2>"

Using acts_as_markup:

    class Post < ActiveRecrod
      acts_as_markup :language => :markdown, :columns => [:body]
    end

    @post = Post.find(:first)
    @post.body.to_s     #=> "## Markdown Headline"
    @post.body.to_html  #=> "<h2> Markdown Headline</h2>"

Using acts_as_markup with :variable language:

    class Post < ActiveRecrod
      acts_as_markup :language => :variable, :columns => [:body], :language_column => 'markup_language'
    end

    @post = Post.find(:first)
    @post.markup_language      # => "markdown"
    @post.body.to_s            # => "## Markdown Headline"
    @post.body.to_html         # => "<h2> Markdown Headline</h2>"

REQUIREMENTS:

You will need the RedCloth library for processing the Textile text, and the Wikitext library for processing wikitext.

You will also need to install some type of Markdown processor. The three options currently supported are:

INSTALL:

sudo gem install acts_as_markup

Add "acts_as_markup" to your environment.rb:

    config.gem "acts_as_markup"