Matthew Bass

Musings on software and life…

October 29th, 2008

Textile toolbar plugin for Rails

Have you ever wanted a WYSIWYG-style toolbar that generates Textile markup? textile_toolbar is a Rails plugin that does just that. Extracted from a recent Terralien project, it’s a great way get your users used to the power and simplicity of Textile without frightening them away with long markup guides. Check out the announcement on the Terralien blog for more information.

To install from the command line:

script/plugin install git://github.com/pelargir/textile_toolbar.git

Update: A live example of a Textile-enabled text area can now be found here.

October 29th, 2008

Surrounding text with a tag using Ruby’s gsub

Here’s how to identify a keyword in a block of text using a case-insensitive regular expression, and surround that keyword with an HTML tag:

text = "hello world, this is a test"
text.gsub!(/(WORLD)/i, "\\1")

The following string is produced:

hello world, this is a test

Note that \\1 references the group in the regex (surrounded by parens). This results in the original value being placed within the HTML tags, instead of the uppercased WORLD in the regex.

|