
Camping is a web framework which consistently stays at less than 4kb of code. You can probably view the complete source code on a single page. But, you know, it‘s so small that, if you think about it, what can it really do?
The idea here is to store a complete fledgling web application in a single file like many small CGIs. But to organize it as a Model-View-Controller application like Rails does. You can then easily move it to Rails once you‘ve got it going.
A skeletal Camping blog could look like this:
require 'camping'
Camping.goes :Blog
module Blog::Models
class Post < Base; belongs_to :user; end
class Comment < Base; belongs_to :user; end
class User < Base; end
end
module Blog::Controllers
class Index < R '/'
def get
@posts = Post.find :all
render :index
end
end
end
module Blog::Views
def layout
html do
body do
self << yield
end
end
end
def index
for post in @posts
h1 post.title
end
end
end
Some things you might have noticed:
NOTE: Camping auto-prefixes table names. If your class is named Blog::Models::Post, your table will be called blog_posts. Since many Camping apps can be attached to a database at once, this helps prevent name clash.
(If you want to see the full blog example, check out examples/blog/blog.rb for the complete code.)
If you want to write larger applications with Camping, you are encouraged to split the application into distinct parts which can be mounted at URLs on your web server. You might have a blog at /blog and a wiki at /wiki. Each self-contained. But you can certainly share layouts and models by storing them in plain Ruby scripts.
Interested yet? Okay, okay, one step at a time.
Or for the bleeding edge:
You are encourage to install Camping and SQLite3, since it is a small database which fits perfectly with our compact bylaws, works well with the examples.
The blog example above and most Camping applications look a lot like CGI scripts. If you run them from the commandline, you‘ll probably just see a pile of HTML.
Camping comes with an tool for launching apps from the commandline:
If your application isn‘t working with the camping tool, keep in mind that the tool expects the following conventions to be used:
Once you‘ve started writing your own Camping app, I‘d highly recommend that you become familiar with the Camping Rules of Thumb which are listed on the wiki: code.whytheluckystiff.net/camping/wiki/CampingRulesOfThumb