judofyr / camping

the 4k pocket full-of-gags web microframework

This URL has Read+Write access

camping / README
100644 70 lines (54 sloc) 1.96 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
== Camping, a Microframework
 
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 skeleton might be:
 
  require 'camping'
  
  module Camping::Models
    class Post < Base; belongs_to :user; end
    class Comment < Base; belongs_to :user; end
    class User < Base; end
  end
 
  module Camping::Controllers
    class Index < R '/'
      def get
        @posts = Post.find :all
        render :index
      end
    end
  end
 
  module Camping::Views
    def layout
      html do
        body do
          self << yield
        end
      end
    end
 
    def index
      for post in @posts
        h1 post.title
      end
    end
  end
 
  if __FILE__ == $0
    Camping::Models::Base.establish_connection :adapter => 'sqlite3', :database => 'blog3.db'
    Camping::Models::Base.logger = Logger.new('camping.log')
    Camping.run
  end
 
Some things you might have noticed:
 
* Camping::Models uses ActiveRecord to do its work. We love ActiveRecord!
* Camping::Controllers can be assigned URLs in the class definition. Neat?
* Camping::Views describes HTML using pure Ruby. Markup as Ruby, which we
  call Markaby.
 
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.
 
== Installation
 
* <tt>gem install camping</tt>