string_parse_erb

Say you design a CMS, and you want the ability to replace some place-holders inside an item-content with some external values.

Of course, you can use regular expressions and friends to do the task.

But why not use the power of ERB engine instead ?

Implementing ERB fragments inside your content can open up wide array of possibilities, all of the sudden you get the power of ruby inside you content: not just variables-replacement but conditionals, loops and so on..

The downside of this is security…

The solution taken by this gem is very simple, (and so may not be perfect), and discussed in a couple of posts like: stackoverflow.com/questions/3619516/how-do-you-mark-a-ruby-binding-as-trusted

Installation

Examples

string_parse_erb(
           "Good <%= part_of_day %>, the time is <%= time %>.",
           {:part_of_day => "morning", :time => "six o'clock"}
 )
 # =>  "Good morning, the time is six o'clock."

 string_parse_erb( "<%= abort %>", {})
 # => Raises SecurityError Exception

Copyright © 2011 Nadav Blum. See LICENSE.txt for further details.