The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Open Up Your Wiki and We'll Finish it For You

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Red Handed

Posts: 1158
Nickname: redhanded
Registered: Dec, 2004

Red Handed is a Ruby-focused group blog.
Open Up Your Wiki and We'll Finish it For You Posted: Sep 28, 2006 4:26 PM
Reply to this message Reply

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
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Red Handed
Latest Posts From RedHanded

Advertisement

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.

 %w(sandbox rubygems redcloth 
 camping acts_as_versioned).each { |lib| require lib }
 Camping.goes :Tepee
 Tepee::Box = Sandbox.safe
 Tepee::Box.load "erbl.rb" 

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.

Read: Open Up Your Wiki and We'll Finish it For You

Topic: Intellisense for Ruby - Coming Soon Previous Topic   Next Topic Topic: Rails is not about inventing your own style

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use