PDA

View Full Version : [RedHanded] What's in Camping 1.4?


ruby-lang
March 9th, 2006, 10:45 AM
<p>Okay, you can try out Camping 1.3.69 from gems. Camping is a microframework. Railsish aesthetics for wee CGIs.</p>


<pre>
gem install camping --source code.whytheluckystiff.net
</pre>

<h2>Sessioning</h2>


<p>To get sessions working for your application:</p>


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


<p>More notes about this at <a href="http://code.whytheluckystiff.net/camping/wiki/CampingSessions">CampingSessions</a> on the wiki.</p>


<h2>Helpers#URL</h2>


<p>Builds a complete <span class="caps">URL</span> to a controller route or a path, returning a <span class="caps">URI</span> object.</p>


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


<pre>
>> 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/)
</pre>

<p>Find it also in the <a href="http://camping.rubyforge.org/classes/Camping/Helpers.html#M000014">new docs</a>.</p>


<h2>Service Overrides</h2>


<p>Adding stuff like sessioning and authentication demands hooks on the controller. Rails uses hooks like <code>before_filter</code> 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 <code>service</code> methods which intercept all controller calls.</p>


<pre>
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
</pre>

<p>This <code>service</code> method can be slid into your application’s top module like so:</p>


<pre>
Camping.goes :Blog

module Blog
include ClownsOnly
end
</pre>

<p>Fully explained at <a href="http://code.whytheluckystiff.net/camping/wiki/BeforeAndAfterOverrides">Before and After Overrides</a> on the wiki.</p>

<a href="http://redhanded.hobix.com/inspect/whatSInCamping14.html" target="_blank">http://redhanded.hobix.com/inspect/whatSInCamping14.html</a>