hoodwink.d enhanced
RSS
2.0
XHTML
1.0

RedHanded

What's in Camping 1.4? #

by why in inspect

Okay, you can try out Camping 1.3.69 from gems. Camping is a microframework. Railsish aesthetics for wee CGIs.

 gem install camping --source code.whytheluckystiff.net

Sessioning

To get sessions working for your application:

  1. require 'camping/session'
  2. In your application’s create method, add a call to Camping::Models::Schema.create_schema
  3. Throughout your application, use the @state var like a hash to store your application’s data.

More notes about this at CampingSessions on the wiki.

Helpers#URL

Builds a complete URL to a controller route or a path, returning a URI object.

Assuming the Hoodwink.d app is mounted at http://localhost:3301/hoodwinkd/, in a controller or view you’ll see the following results:

  >> URL()
  => (URI:http://localhost:3301/hoodwinkd/)
  >> self.URL
  => (URI:http://localhost:3301/hoodwinkd/)
  >> URL(Static, 'js/prototype.js')
  => (URI:http://localhost:3301/hoodwinkd/static/js/prototype.js)
  >> URL("/boingboing.net/setup")
  => (URI:http://localhost:3301/hoodwinkd/boingboing.net/setup)
  >> URL("http://google.com")
  => (URI:http://google.com/)

Find it also in the new docs.

Service Overrides

Adding stuff like sessioning and authentication demands hooks on the controller. Rails uses hooks like before_filter to do this. Camping doesn’t have bytes to spare to make this happen, but things have been re-stacked to let you slide in new service methods which intercept all controller calls.

 class LoginError < Exception; end
 module ClownsOnly
   def service(*a)
     unless @state.occupation == :clown
       raise LoginError, "For clown's eyes only." 
     end
     super(*a)
   end
 end

This service method can be slid into your application’s top module like so:

 Camping.goes :Blog

 module Blog
   include ClownsOnly
 end

Fully explained at Before and After Overrides on the wiki.

said on 23 Feb 2006 at 17:49

_Why – you rock! I’ve already spent a couple days savoring camping unabridged… You do some awful clever stuff packed into a small space—koan like. Learn something new with each iteration. Sign me up as a Camper. Nice work ;-)

said on 23 Feb 2006 at 18:30

_why, what’s your strategy for keeping Camping under 4k?

It’s like a miracle of Zen Bhuddist engineering as it is, I want to believe you can keep it up, but it’s a doubt-laden road.

said on 23 Feb 2006 at 20:06

Oh, come on. Breaking stuff up and cutting corners starts to become natural. 4k still gives plenty of room to sift things around. I don’t think there’s been any size increase for this release.

Plus, since the sessioning stuff is optional, it’s in a separate library. I don’t want any extensions that are over a couple k, but I’ll allow a few.

said on 23 Feb 2006 at 20:35

It’s just… so beautiful… brings a tear to my eye.

You know, maybe you should call up the ThinkGeek guys and get them to put Camping on a shirt.

The Perl guys have their Camel shaped Camel making code, we could have a T-Shirt with a freaking FRAMEWORK on it.

said on 24 Feb 2006 at 05:56

...or stitch-on tent-patches.

said on 24 Feb 2006 at 15:32

Camping t-shirts NOW !!

said on 24 Feb 2006 at 15:35

If you handcoded it in YARV bytecodes, it would like totally bring it under 2k !! :D

Comments are closed for this entry.