Acts as textiled plugin
Plugin details
Documentation
ruby script/plugin install svn://errtheblog.com/svn/plugins/acts_as_textiled
You will need to install the RedCloth gem
gem install redcloth
Add to required model
class Story < ActiveRecord::Base acts_as_textiled :body_text, :description end
View Helpers:
>> story = Story.find(3) => # >> story.description => "This is cool." >> story.description(:source) => "This is *cool*." >> story.description(:plain) => "This is cool." >> story.description = "I _know_!" => "I _know_!" >> story.save => true >> story.description => "I know!" >> story.textiled = false => false >> story.description => "I _know_!" >> story.textiled = true => true >> story.description => "I know!"
== Different Modes
RedCloth supports different modes, such as :lite_mode. To use a mode on a specific attribute simply pass it in as an options hash after any attributes you don't want to mode-ify. Like so:
class Story < ActiveRecord::Base acts_as_textiled :body_text, :description => :lite_mode end
Or:
class Story < ActiveRecord::Base acts_as_textiled :body_text => :lite_mode, :description => :lite_mode end
You can also pass in multiple modes per attribute:
class Story < ActiveRecord::Base acts_as_textiled :body_text, :description => [ :lite_mode, :no_span_caps ] end
== form_for
Are you using form_for? If you are, you don't have to change any code at all.
<% form_for :story, @story do |f| %> Description: <%= f.text_field :description %> <% end %>
You'll see the Textile plaintext in the text field. It Just Works.
== form tags
If you're being a bit unconvential, no worries. You can still get at your raw Textile like so:
Description: <%= text_field_tag :description, @story.description(:source) %>
And there's always object.textiled = false, as demo'd above.
== Pre-fetching
acts_as_textiled locally caches rendered HTML once the attribute in question has been requested. Obviously this doesn't bode well for marshalling or caching.
If you need to force your object to build and cache HTML for all textiled attributes, call the +textilize+ method on your object.
If you're real crazy you can even do something like this:
class Story < ActiveRecord::Base acts_as_textiled :body_text, :description def after_find textilize end end
All your Textile will now be ready to go in spiffy HTML format. But you probably won't need to do this.
Further Documentation
There is currently no advanced documentation for this plugin.
New documentationEdit plugin | Back in time (1 older version) | Last edited by: scott, 9 months ago

