root / branches / HamlAndSequelGoCampingTogether / README

Revision 237, 4.1 kB (checked in by zimbatm, 14 months ago)

* Introduced error 501 handling and changed NotFound? and ServerError? controllers to #r404 and #r500 methods. camping.rb is exactly at 4000 octets !
* Some doc fixes in man page, README, CHANGELOG. Unfortunately the rdoc are still badly parsed.

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
11== A Camping Skeleton
12
13A skeletal Camping blog could look like this:
14
15  require 'camping'
16 
17  Camping.goes :Blog
18
19  module Blog::Models
20    class Post < Base; belongs_to :user; end
21    class Comment < Base; belongs_to :user; end
22    class User < Base; end
23  end
24
25  module Blog::Controllers
26    class Index < R '/'
27      def get
28        @posts = Post.find :all
29        render :index
30      end
31    end
32  end
33
34  module Blog::Views
35    def layout
36      html do
37        body do
38          self << yield
39        end
40      end
41    end
42
43    def index
44      for post in @posts
45        h1 post.title
46      end
47    end
48  end
49
50Some things you might have noticed:
51
52* Camping::Models uses ActiveRecord to do its work.  We love ActiveRecord!
53* Camping::Controllers can be assigned URLs in the class definition.  Neat?
54* Camping::Views describes HTML using pure Ruby.  Markup as Ruby, which we
55  call Markaby.
56* You use Camping::goes to make a copy of the Camping framework under your
57  own module name (in this case: <tt>Blog</tt>.)
58
59<b>NOTE:</b> Camping auto-prefixes table names.  If your class is named
60<tt>Blog::Models::Post</tt>, your table will be called <b>blog_posts</b>.
61Since many Camping apps can be attached to a database at once, this helps
62prevent name clash.
63
64(If you want to see the full blog example, check out <tt>examples/blog/blog.rb</tt>
65for the complete code.)
66
67If you want to write larger applications with Camping, you are encouraged to
68split the application into distinct parts which can be mounted at URLs on your
69web server.  You might have a blog at /blog and a wiki at /wiki.  Each
70self-contained.  But you can certainly share layouts and models by storing them
71in plain Ruby scripts.
72
73Interested yet?  Okay, okay, one step at a time.
74
75== Installation
76
77* <tt>gem install camping</tt>
78
79Or for the bleeding edge:
80
81* <tt>gem install camping --source code.whytheluckystiff.net</tt>
82
83You are encourage to install Camping and SQLite3, since it is a small database
84which fits perfectly with our compact bylaws, works well with the examples.
85
86* See http://code.whytheluckystiff.net/camping/wiki/BeAlertWhenOnSqlite3 for instructions.
87
88== Running Camping Apps
89
90The blog example above and most Camping applications look a lot like CGI scripts.
91If you run them from the commandline, you'll probably just see a pile of HTML.
92
93Camping comes with an tool for launching apps from the commandline:
94
95* Run: <tt>camping blog.rb</tt>
96* Visit http://localhost:3301/ to use the app.
97
98== How the Camping Tool Works
99
100If your application isn't working with the <tt>camping</tt> tool, keep in mind
101that the tool expects the following conventions to be used:
102
1031. You must have SQLite3 and SQLite3-ruby installed.  (Once again, please see
104   http://code.whytheluckystiff.net/camping/wiki/BeAlertWhenOnSqlite3 for instructions.)
1052. If your script is called <tt>test.rb</tt>, Camping expects your application to
106   be stored in a module called <tt>Test</tt>.  Case is not imporant, though.  The
107   module can be called <tt>TeSt</tt> or any other permutation.
1083. Your script's postamble (anything enclosed in <tt>if __FILE__ == $0</tt>) will be
109   ignored by the tool, since the tool will create an SQLite3 database at
110   <tt>~/.camping.db</tt>.  Or, on Windows, <tt>$USER/Application Data/Camping.db</tt>.
1114. If your application's module has a <tt>create</tt> method, it will be executed before
112   the web server starts up.
113
114== The Rules of Thumb
115
116Once you've started writing your own Camping app, I'd highly recommend that you become familiar
117with the Camping Rules of Thumb which are listed on the wiki:
118http://code.whytheluckystiff.net/camping/wiki/CampingRulesOfThumb
119
Note: See TracBrowser for help on using the browser.