root / tags / 1.2 / README

Revision 28, 1.9 kB (checked in by why, 3 years ago)

lib/camping.rb: have Helpers./ throw an error on nil. shorten Mab.tag! slightly.

always define the urls method, restructure Controllers::D to loop through all.

lib/camping-unabridged.rb: ditto.
README: let's say the limit is 4k (shrug!)
examples/serve: error on Cookie constant.

Line 
1== Camping, a Microframework
2
3Camping is a web framework which consistently stays at less than 4kb of code.
4You can probably view the complete source code on a single page.  But, you know,
5it's so small that, if you think about it, what can it really do?
6
7The idea here is to store a complete fledgling web application in a single file
8like many small CGIs.  But to organize it as a Model-View-Controller application
9like Rails does.  You can then easily move it to Rails once you've got it going.
10
11A skeleton might be:
12
13  require 'camping'
14 
15  module Camping::Models
16    class Post < Base; belongs_to :user; end
17    class Comment < Base; belongs_to :user; end
18    class User < Base; end
19  end
20
21  module Camping::Controllers
22    class Index < R '/'
23      def get
24        @posts = Post.find :all
25        render :index
26      end
27    end
28  end
29
30  module Camping::Views
31    def layout
32      html do
33        body do
34          self << yield
35        end
36      end
37    end
38
39    def index
40      for post in @posts
41        h1 post.title
42      end
43    end
44  end
45
46  if __FILE__ == $0
47    Camping::Models::Base.establish_connection :adapter => 'sqlite3', :database => 'blog3.db'
48    Camping::Models::Base.logger = Logger.new('camping.log')
49    Camping.run
50  end
51
52Some things you might have noticed:
53
54* Camping::Models uses ActiveRecord to do its work.  We love ActiveRecord!
55* Camping::Controllers can be assigned URLs in the class definition.  Neat?
56* Camping::Views describes HTML using pure Ruby.  Markup as Ruby, which we
57  call Markaby.
58
59If you want to write larger applications with Camping, you are encouraged to
60split the application into distinct parts which can be mounted at URLs on your
61web server.  You might have a blog at /blog and a wiki at /wiki.  Each
62self-contained.  But you can certainly share layouts and models by storing them
63in plain Ruby scripts.
64
65Interested yet?  Okay, okay, one step at a time.
66
67== Installation
68
69* <tt>gem install camping</tt>
Note: See TracBrowser for help on using the browser.