root / tags / 1.4.2 / README

Revision 57, 4.2 kB (checked in by why, 3 years ago)
  • README: wrong urls.
  • examples/serve: giving the sample server some style.
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
50  if __FILE__ == $0
51    Blog::Models::Base.establish_connection :adapter => 'sqlite3',
52        :database => 'blog3.db'
53    Blog::Models::Base.logger = Logger.new('camping.log')
54    puts Blog.run
55  end
56
57Some things you might have noticed:
58
59* Camping::Models uses ActiveRecord to do its work.  We love ActiveRecord!
60* Camping::Controllers can be assigned URLs in the class definition.  Neat?
61* Camping::Views describes HTML using pure Ruby.  Markup as Ruby, which we
62  call Markaby.
63* You use Camping::goes to make a copy of the Camping framework under your
64  own module name (in this case: <tt>Blog</tt>.)
65
66<b>NOTE:</b> Camping auto-prefixes table names.  If your class is named
67<tt>Blog::Models::Post</tt>, your table will be called <b>blog_posts</b>.
68Since many Camping apps can be attached to a database at once, this helps
69prevent name clash.
70
71(If you want to see the full blog example, check out <tt>examples/blog/blog.rb</tt>
72for the complete code.)
73
74If you want to write larger applications with Camping, you are encouraged to
75split the application into distinct parts which can be mounted at URLs on your
76web server.  You might have a blog at /blog and a wiki at /wiki.  Each
77self-contained.  But you can certainly share layouts and models by storing them
78in plain Ruby scripts.
79
80Interested yet?  Okay, okay, one step at a time.
81
82== Installation
83
84* <tt>gem install camping</tt>
85
86Or for the bleeding edge:
87
88* <tt>gem install camping --source code.whytheluckystiff.net</tt>
89
90You are encourage to install Camping and SQLite3, since it is a small database
91which fits perfectly with our compact bylaws, works well with the examples.
92
93* See http://code.whytheluckystiff.net/camping/wiki/BeAlertWhenOnSqlite3 for instructions.
94
95== Running Camping Apps
96
97The blog example above and most Camping applications look a lot like CGI scripts.
98If you run them from the commandline, you'll probably just see a pile of HTML.
99
100Camping comes with an tool for launching apps from the commandline:
101
102* Run: <tt>camping blog.rb</tt>
103* Visit http://localhost:3301/ to use the app.
104
105== Debugging Camping Apps
106
107If your application isn't working with the <tt>camping</tt> tool, keep in mind
108that the tool expects the following conventions to be used:
109
1101. You must have SQLite3 and SQLite3-ruby installed.  (Once again, please see
111   http://code.whytheluckystiff.net/camping/wiki/BeAlertWhenOnSqlite3 for instructions.)
1122. If your script is called <tt>test.rb</tt>, Camping expects your application to
113   be stored in a module called <tt>Test</tt>.  Case is not imporant, though.  The
114   module can be called <tt>TeSt</tt> or any other permuation.
1153. Your script's postamble (anything enclosed in <tt>if __FILE__ == $0</tt>) will be
116   ignored by the tool, since the tool will create an SQLite3 database at
117   <tt>~/.camping.db</tt>.  Or, on Windows, <tt>$USER/Application Data/Camping.db</tt>.
1184. If your application's module has a <tt>create</tt> method, it will be executed before
119   the web server starts up.
120
121== The Rules of Thumb
122
123Once you've started writing your own Camping app, I'd highly recommend becoming familiar
124with the Camping Rules of Thumb which are listed on the wiki:
125http://code.whytheluckystiff.net/camping/wiki/CampingRulesOfThumb
126
Note: See TracBrowser for help on using the browser.