This post originated from an RSS feed registered with Ruby Buzz
by Red Handed.
Original Post: Open Up Your Wiki and We'll Finish it For You
Feed Title: RedHanded
Feed URL: http://redhanded.hobix.com/index.xml
Feed Description: sneaking Ruby through the system
I’m hoping the Freaky Freaky Sandbox will avail me of having to finish anything ever again. Instead, I can just stop. Whatever it is, leave it unfinished. Gently place a sandboxed wiki on it. And then all of you at home can each add five lines of code and that’s it!
So, let’s get started on this sandboxed scriptable wiki. Step one, get some embedded Ruby in there. Here’s how.
I’m using Tepee as the base. Sandbox gets loaded first because if you load RubyGems first, it goes bonkers. So, we’re going to start up a little barebones sandbox and load the ERbLight library, which is written in pure Ruby. Just to keep it simple.
Now to swap out the markup processor for a sandbox eval.
def markup str
@boxx = nil
begin
str = Tepee::Box.eval("ERbLight.new(#{str.dump}).result")
rescue Sandbox::Exception => @boxx
end
RedCloth.new(str, [ :hard_breaks ]).to_html
end
And that’s it. If the sandbox throws an exception, it’ll go in the @boxx ivar. It might be better to check for an exception when the user saves the page instead.
So, this sandbox does nothing. I mean you can do math and string stuff and hashes and whatever, but it’s not that great. But come back in a few days and I’ll show you some more tricks for the Tippy Tippy Tepee.