|
This post originated from an RSS feed registered with Ruby Buzz
by Red Handed.
|
Original Post: What's in Camping 1.4?
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
|
|
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:
require 'camping/session'
- In your application’s create method, add a call to
Camping::Models::Schema.create_schema
- 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.
Read: What's in Camping 1.4?