0
-This simple plugin allows you to forget about constantly rendering Textile in
0
-your application. Instead, you can rest easy knowing the Textile fields you
0
-want to display as HTML will always be displayed as HTML (unless you tell your
0
-No database modifications are needed.
0
-You need RedCloth, of course. And Rails.
0
- class Story < ActiveRecord::Base
0
- acts_as_textiled :body_text, :description
0
- >> story = Story.find(3)
0
- => #<Story:0x245fed8 ... >
0
- => "<p>This is <strong>cool</strong>.</p>"
0
- >> story.description(:source)
0
- >> story.description(:plain)
0
- >> story.description = "I _know_!"
0
- => "<p>I <em>know</em>!</p>"
0
- >> story.textiled = false
0
- >> story.textiled = true
0
- => "<p>I <em>know</em>!</p>"
0
-RedCloth supports different modes, such as :lite_mode. To use a mode on
0
-a specific attribute simply pass it in as an options hash after any
0
-attributes you don't want to mode-ify. Like so:
0
- class Story < ActiveRecord::Base
0
- acts_as_textiled :body_text, :description => :lite_mode
0
- class Story < ActiveRecord::Base
0
- acts_as_textiled :body_text => :lite_mode, :description => :lite_mode
0
-You can also pass in multiple modes per attribute:
0
- class Story < ActiveRecord::Base
0
- acts_as_textiled :body_text, :description => [ :lite_mode, :no_span_caps ]
0
-Get it? Now let's say you have an admin tool and you want the text to be displayed
0
-in the text boxes / fields as plaintext. Do you have to change all your views?
0
-Are you using form_for? If you are, you don't have to change any code at all.
0
- <% form_for :story, @story do |f| %>
0
- Description: <br/> <%= f.text_field :description %>
0
-You'll see the Textile plaintext in the text field. It Just Works.
0
-If you're being a bit unconvential, no worries. You can still get at your
0
- Description: <br/> <%= text_field_tag :description, @story.description(:source) %>
0
-And there's always object.textiled = false, as demo'd above.
0
-acts_as_textiled locally caches rendered HTML once the attribute in question has
0
-been requested. Obviously this doesn't bode well for marshalling or caching.
0
-If you need to force your object to build and cache HTML for all textiled attributes,
0
-call the +textilize+ method on your object.
0
-If you're real crazy you can even do something like this:
0
- class Story < ActiveRecord::Base
0
- acts_as_textiled :body_text, :description
0
-All your Textile will now be ready to go in spiffy HTML format. But you probably
0
-* By Chris Wanstrath [ chris[at]ozmm[dot]org ]
Comments
No one has commented yet.