<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Rubynaut: How to textilize on Rails</title>
    <link>http://www.rubynaut.net/articles/2007/04/06/how-textilize-on-rails</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>How to textilize on Rails</title>
      <description>&lt;p&gt;The last few days I found different solutions to use textile in Rails application. Let&amp;#8217;s have a look to the different ways.&lt;/p&gt;


&lt;h3&gt;Requirement: RedCloth installation&lt;/h3&gt;

	&lt;p&gt;First you will need to install RedCloth (generally already needed to install Ruby and Gem)&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;$ sudo gem install redcloth&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3&gt;Solution 1: RedCloth textilizer&lt;/h3&gt;

	&lt;p&gt;The first way to manipulate textile is to use the RedCloth methods.&lt;/p&gt;


	&lt;p&gt;If you have a field in your model you want to textilize, by example &lt;code&gt;page.body&lt;/code&gt;&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;textile_page = RedCloth.new(page.body)&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;and then you get the html from&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;textile_page.to_html&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;for more information you can refer to the &lt;a href="http://redcloth.rubyforge.org/rdoc/"&gt;RedCloth &lt;span class="caps"&gt;API&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h3&gt;Solution 2: textilize() helper&lt;/h3&gt;

	&lt;p&gt;Rails brings an helper to do the previous work, this time in your view, just call for:&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;textilize(page.body)&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3&gt;Solution 3: acts_as_textiled&lt;/h3&gt;

	&lt;p&gt;The last solution provide a useful way to manipulate automatically textiled content and text content.&lt;/p&gt;


	&lt;p&gt;Fist add to your model :&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;Page&lt;/span&gt; &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt; &lt;span class="constant"&gt;ActiveRecord&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Base&lt;/span&gt;
    &lt;span class="ident"&gt;acts_as_textiled&lt;/span&gt; &lt;span class="symbol"&gt;:body&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Then you can use a form to manipulate automatically your content and saving it to the &lt;code&gt;page.body&lt;/code&gt;&lt;/p&gt;


	&lt;p&gt;After that, if you get the content your page by calling the method &lt;code&gt;page.body&lt;/code&gt; you will receive the html. If you want to get the original content just call &lt;code&gt;page.body_source&lt;/code&gt;, this method is automatically generated by acts_as_textiled as the method &lt;code&gt;page.body_text&lt;/code&gt; returning the text without markup.&lt;/p&gt;


&lt;h3&gt;Editor: Textile Editor Helper (TEH)&lt;/h3&gt;

	&lt;p&gt;From the &lt;a href="http://trac.webtest.wvu.edu/webadmin.db"&gt;slate&lt;/a&gt; CMS project, it&amp;#8217;s simply a visual editor providing button to apply style to your text.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;$ script/plugin install http://svn.webtest.wvu.edu/repos/rails/plugins/textile_editor_helper/&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;[update] I didn&amp;#8217;t get before, thanks Dave, you have to load also &lt;code&gt;prototype.js&lt;/code&gt; in your layout.
[update 2] Once you have installed your plugin, don&amp;#8217;t forget to restart your server, thanks John :)&lt;/p&gt;


	&lt;p&gt;Then add to your view in a form:&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;&amp;lt;%= textile_editor 'page', 'body' -%&amp;gt;
&amp;lt;%= textile_editor_initialize -%&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;&lt;strong&gt;Links&lt;/strong&gt;&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://hobix.com/textile/"&gt;textile&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://whytheluckystiff.net/ruby/redcloth/"&gt;RedCloth&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://errtheblog.com/post/14"&gt;Acts_as_textiled&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://slateinfo.blogs.wvu.edu/plugins/textile_editor_helper/" title="Textile Editor Helper"&gt;&lt;span class="caps"&gt;TEH&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;</description>
      <pubDate>Fri, 06 Apr 2007 12:00:00 +0200</pubDate>
      <guid isPermaLink="false">urn:uuid:f3e33f91-ee22-45cc-a34a-1af9faf4a84f</guid>
      <author>stephane</author>
      <link>http://www.rubynaut.net/articles/2007/04/06/how-textilize-on-rails</link>
      <trackback:ping>http://www.rubynaut.net/articles/trackback/14171</trackback:ping>
    </item>
    <item>
      <title>"How to textilize on Rails" by S2</title>
      <description>&lt;p&gt;so remember kids! &lt;em&gt;sanitize&lt;/em&gt; your text befor &lt;em&gt;textilitzing&lt;/em&gt;!&lt;/p&gt;</description>
      <pubDate>Tue, 25 Mar 2008 22:25:32 +0100</pubDate>
      <guid isPermaLink="false">urn:uuid:bfe74765-a99f-474b-82e7-691bc68ee9ca</guid>
      <link>http://www.rubynaut.net/articles/2007/04/06/how-textilize-on-rails#comment-2033</link>
    </item>
    <item>
      <title>"How to textilize on Rails" by S2</title>
      <description>hi. I found out that in rails 2.0 (I don&amp;#8217;t know if this happened before), that if you textilize, the script tags are not escaped:
alert(1);
Maybe I got something wrong in my setup. I&amp;#8217;ll test it here to see if you have the same bug.</description>
      <pubDate>Tue, 25 Mar 2008 22:08:20 +0100</pubDate>
      <guid isPermaLink="false">urn:uuid:9808730f-ef6a-48f7-a542-2d8a69ade525</guid>
      <link>http://www.rubynaut.net/articles/2007/04/06/how-textilize-on-rails#comment-2032</link>
    </item>
    <item>
      <title>"How to textilize on Rails" by John D</title>
      <description>&lt;p&gt;For noobs (like me), don&amp;#8217;t forget to restart your web server after installing redcloth :)&lt;/p&gt;</description>
      <pubDate>Mon, 23 Apr 2007 15:28:08 +0200</pubDate>
      <guid isPermaLink="false">urn:uuid:53448254-024b-4658-91c8-5f86c84fac1a</guid>
      <link>http://www.rubynaut.net/articles/2007/04/06/how-textilize-on-rails#comment-1366</link>
    </item>
    <item>
      <title>"How to textilize on Rails" by Martin Kjems</title>
      <description>&lt;p&gt;One benefit of using textilize is that it prevents the content editor from breaking the html markup&amp;#8230;&lt;/p&gt;</description>
      <pubDate>Mon, 16 Apr 2007 11:22:19 +0200</pubDate>
      <guid isPermaLink="false">urn:uuid:f6012d64-cd92-4cca-8266-8f9a454b486b</guid>
      <link>http://www.rubynaut.net/articles/2007/04/06/how-textilize-on-rails#comment-1359</link>
    </item>
    <item>
      <title>"How to textilize on Rails" by Dave</title>
      <description>&lt;p&gt;Just a note on the textile editor, prototype is required so that the toolbar properly loads.&lt;/p&gt;</description>
      <pubDate>Sun, 08 Apr 2007 01:52:12 +0200</pubDate>
      <guid isPermaLink="false">urn:uuid:8f443557-8b98-42fe-9917-ea22e62d0b72</guid>
      <link>http://www.rubynaut.net/articles/2007/04/06/how-textilize-on-rails#comment-1264</link>
    </item>
    <item>
      <title>"How to textilize on Rails" by Mike</title>
      <description>&lt;p&gt;Is HTML that hard that we need yet another markup language?&lt;/p&gt;</description>
      <pubDate>Sat, 07 Apr 2007 00:58:14 +0200</pubDate>
      <guid isPermaLink="false">urn:uuid:e3e5f208-c8eb-47b8-8f28-8873205980df</guid>
      <link>http://www.rubynaut.net/articles/2007/04/06/how-textilize-on-rails#comment-1253</link>
    </item>
  </channel>
</rss>
