jmckible / rad_cloth

Gem for textiling strings with RedCloth

This URL has Read+Write access

name age message
file MIT-LICENSE Loading commit data...
file README.rdoc
file init.rb
directory lib/
file rad_cloth.gemspec
README.rdoc

rad_cloth

rad_cloth is pretty much a clone of Chris Wanstrath’s acts_as_textiled. I was having problems with its design of passing parameters so I switched it up a bit.

Installation

You’ll need to have RedCloth as a textile engine.

Assuming you want to use this as a Rails plugin:

  ./script/plugin install git://github.com/jmckible/rad_cloth.git

Usage

Let’s say you’ve got a post model with a body:

  class Post < ActiveRecord::Base
    # attributes: body
  end

You can treat this like a normal attribute when editing via a form:

  <% form_for @post do |f| %>
    <%= f.text_area :body %>
    <%= submit_tag 'Save' %>
  <% end %>

Now if you want to textile the attribute for display just add:

  class Post < ActiveRecord::Base
    textile :body
  end

This will define two new methods: @body_html@ and @body_plain@

If you want to output the body converted to html, just do:

  <%= @post.body_html %>

Or if you’re sending in an email and want to strip out all the textile markdown:

  <%= @post.body_plain %>

And that’s pretty much it. Keep in mind you aren’t just restricted to ActiveRecord attributes, it’ll work on any method which outputs a string.

Author