# Text::Format assistance needed

**URL:** <https://www.ruby-forum.com/t/text-format-assistance-needed/143920>\
**Category:** Rails\
**Created:** [July 23, 2008, 9:32pm UTC](https://www.ruby-forum.com/t/text-format-assistance-needed/143920 "2008-07-23T21:32:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tinney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a88e4f/32.png) [@tinney](https://www.ruby-forum.com/u/tinney)\
**Post date:** [July 23, 2008, 9:32pm UTC](https://www.ruby-forum.com/t/text-format-assistance-needed/143920/1 "2008-07-23T21:32:42Z")

</div>

Hello everyone,

I was reading through the Rails API and came across Text::Format. It  
appears as if I can use this to format my text for my users. I’ll be  
launching a creative writing website and if I can allow members text  
formatting to remain the same as it would be in a word processor, that  
would really be beneficial. I’m not looking for a WYSIWYG editor - I  
just want the tabs to be preserved from a cut and paste.

Unfortunately, I cannot find any type of help on this class. I’m  
fairly new with Ruby on Rails, though can follow tutorials like no  
other. If you know of a tutorial that utilizes this class, that would  
be most helpful. Otherwise, some usage examples would be very much  
appreciated.

Thanks for your time and help!

~Dustin T.

---

<div class="post-metadata">

**Author:** ![tinney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a88e4f/32.png) [@tinney](https://www.ruby-forum.com/u/tinney)\
**Post date:** [July 25, 2008, 2:05am UTC](https://www.ruby-forum.com/t/text-format-assistance-needed/143920/2 "2008-07-25T02:05:06Z")

</div>

_Nudge_ Not to be obnoxious, though any help would be appreciated. A  
mere point in the right direction would be appreciated. Thanks!

~Dustin T.

---

<div class="post-metadata">

**Author:** ![tinney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a88e4f/32.png) [@tinney](https://www.ruby-forum.com/u/tinney)\
**Post date:** [July 25, 2008, 2:11am UTC](https://www.ruby-forum.com/t/text-format-assistance-needed/143920/3 "2008-07-25T02:11:54Z")

</div>

Dustin T. wrote:

> if I can allow members text  
> formatting to remain the same as it would be in a word processor, that  
> would really be beneficial. I’m not looking for a WYSIWYG editor - I  
> just want the tabs to be preserved from a cut and paste.

You might want to look into RedCloth and BlueCloth. They are Ruby  
libraries that provide support for Textile and Markdown, markup  
notations that are simpler than HTML. If you’re familiar with editing  
Wikipedia pages, it’s kind of like that.

Preserving tabs might be a bit tricky though. I don’t know how you’d  
render them in HTML – maybe a series of &nbsp; ?

---

<div class="post-metadata">

**Author:** ![tinney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a88e4f/32.png) [@tinney](https://www.ruby-forum.com/u/tinney)\
**Post date:** [July 25, 2008, 8:51pm UTC](https://www.ruby-forum.com/t/text-format-assistance-needed/143920/4 "2008-07-25T20:51:04Z")

</div>

Thanks Jeremy,

I have looked into RedCloth and BlueCloth before. Unfortunately, these  
gems / plugins add ‘too’ much functionality. The Text::Format class  
looks like to does exactly what I want it to do, I just don’t know how  
to use it. Here is a link to the Rails API:  
[http://www.railsbrain.com/api/rails-2.1.0/doc/index.html?a=C00000543&name=Text::Format](http://www.railsbrain.com/api/rails-2.1.0/doc/index.html?a=C00000543&name=Text::Format)

As for tabs, I’m assuming the object adds &nbsp;s, just as you said.

Anyway, thanks for the reply! Any further help would be much  
appreciated. Thanks!

~Dustin T.

On Jul 24, 6:11 pm, Jeremy Weiskotten \<rails-mailing-l…@andreas-

---

<div class="post-metadata">

**Author:** ![tinney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a88e4f/32.png) [@tinney](https://www.ruby-forum.com/u/tinney)\
**Post date:** [July 26, 2008, 5:23pm UTC](https://www.ruby-forum.com/t/text-format-assistance-needed/143920/5 "2008-07-26T17:23:21Z")

</div>

I believe I’ve found a solution to my problem. A PHP programmer  
thought it was odd that RoR didn’t have a \n to   
 converter, such  
as the nl2br method. Thus, he wrote a helper method:

def nl2br(s)  
s.gsub(/\n/, ‘  
’ + “\n”)  
end

I took this code and changed it out with a \t and created:

def tabber(s)  
s.gsub(/\t/, ’&nbsp;&nbsp;&nbsp;&nbsp;')  
end

This, in combination with simple\_format, does everything I want. An  
example of the usage:

\<%= tabber simple\_format “Here is my text” %\>

Hope that helps someone. Thanks for your help!

~Dustin T.
