The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Catapult Wiki Exoskeleton

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.
Catapult Wiki Exoskeleton Posted: Feb 5, 2005 8:28 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Red Handed.
Original Post: Catapult Wiki Exoskeleton
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

Here’s a fun library that’s gone under the radar. Catapult lets you serve objects over HTTP using over-the-counter WEBrick. Your object simply needs two methods:

 run( path_info_string ) -> response string
 content_type() -> HTTP content type string

For example, here’s a Wiki which uses Catapult and stores its pages in a single Textile+YAML document. It’s all gluey! If you’re hankering for a custom Wiki, it’s a good start.

 require 'cgi'
 require 'redcloth'
 require 'yaml/store'
 class Wiki

   def initialize
     @hp = "HomePage" 
     @c = CGI.new('html4')
     @wiki = YAML::Store.new('wiki.yml')
   end

   def content_type; "text/html"; end

   def run( path_info )
     @v = path_info.gsub!( /\?(.+)\Z/m, '' ) ? CGI::parse( $1 ) : {}
     action, path = path_info.split( '/', 2 )
     @wiki.transaction do
       title, body = method( action ).call( path.to_s )
       @c.html { @c.head { @c.title { title } } + @c.body { body } }
     end
   end

   # Wiki actions: 'show' and 'edit'
   def show( p )
     p = @hp if p.empty?
     body = @c.h1 { p }
     body += @c.a(@hp) { @hp } unless p == @hp
     body +=
       if @wiki[p]
         RedCloth.new( @wiki[p] ).to_html.
           gsub(/([A-Z]\w+){2}/){ @c.a($&){$&} } +
           @c.a("../edit/#{p}") { "Edit" }
       else
         @c.p { "No page #{ p }. " +
           @c.a("../edit/#{p}") { "Create?" } }
       end
     [p, body]
   end

   def edit( p )
     @wiki[p] = @v['c'].to_s if @v['c']
     title = "Editing " + p
     body = @c.h1 { title } + 
       @c.a("../show/#{ p }" ) { "Show" } +
       @c.form("post") { 
         @c.textarea('c') { @wiki[p] } + @c.submit 
       }
     [title, body]
   end
 end

To run the Wiki, put it in a directory with catapult.rb. Then, run: ruby -rwiki catapult.rb 2005.

Access the wiki at http://host:2005/wiki/show.

Read: Catapult Wiki Exoskeleton

Topic: On Learning Japanese... Previous Topic   Next Topic Topic: Address book tutorial in Portuguese

Sponsored Links



Google
  Web Artima.com   

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