GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: the 4k pocket full-of-gags web microframework
Homepage: http://code.whytheluckystiff.net/camping/
Clone URL: git://github.com/why/camping.git
 * lib/camping.rb: controller class names influence their urls.  
 Controllers::Index becomes '/'. Controllers::UserN becomes '/user/(\d+)'. 
 Controllers::BlogXN becomes '/blog/(\w+)/(\d+)'.
why (author)
Tue Jun 24 00:12:45 -0700 2008
commit  3c19581c376d696c1db695ef60894a0bb8a3e6b2
tree    172fb892c021b02c8b04fc734eee94322583b403
parent  729e97721fa494c8d3608249ff563e5eed7df44c
...
524
525
526
 
527
528
529
...
531
532
533
534
 
535
536
537
...
524
525
526
527
528
529
530
...
532
533
534
 
535
536
537
538
0
@@ -524,6 +524,7 @@ module Camping
0
       #
0
       # Anyway, if you are calling the URI dispatcher from outside of a Camping server, you'll
0
       # definitely need to call this at least once to set things up.
0
+ N = H.new { |_,x| x.downcase }.merge! "N" => '(\d+)', "X" => '(\w+)', "Index" => ''
0
       def M
0
         def M #:nodoc:
0
         end
0
@@ -531,7 +532,7 @@ module Camping
0
           k=const_get(c)
0
           k.send :include,C,Base,Helpers,Models
0
           @r=[k]+r if r-[k]==r
0
- k.meta_def(:urls){["/#{c.downcase}"]}if !k.respond_to?:urls
1
+ k.meta_def(:urls){["/#{c.scan(/.[^A-Z]*/).map(&N.method(:[]))*'/'}"]}if !k.respond_to?:urls
0
         }
0
       end
0
     end
...
37
38
39
40
41
 
 
 
42
43
 
 
44
45
46
...
50
51
52
53
54
 
...
37
38
39
 
 
40
41
42
43
 
44
45
46
47
48
...
52
53
54
 
55
56
0
@@ -37,10 +37,12 @@ self;end;end;X=module Controllers;@r=[];class<<self;def r;@r end;def R *u;r=@r
0
 Class.new{meta_def(:urls){u};meta_def(:inherited){|x|r<<x}}end
0
 def D p,m;p='/'if !p||!p[0]
0
 r.map{|k|k.urls.map{|x|return(k.instance_method(m)rescue nil)?
0
-[k,m,*$~[1..-1]]:[I,'r501',m]if p=~/^#{x}\/?$/}};[I,'r404',p]
0
-end;def M;def M;end;constants.map{|c|k=const_get(c)
0
+[k,m,*$~[1..-1]]:[I,'r501',m]if p=~/^#{x}\/?$/}};[I,'r404',p] end
0
+N=H.new{|_,x|x.downcase}.merge! "N"=>'(\d+)',"X"=>'(\w+)',"Index"=>''
0
+def M;def M;end;constants.map{|c|k=const_get(c)
0
 k.send:include,C,Base,Helpers,Models;@r=[k]+r if r-[k]==r
0
-k.meta_def(:urls){["/#{c.downcase}"]}if !k.respond_to?:urls}end end;class I<R()
0
+k.meta_def(:urls){["/#{c.scan(/.[^A-Z]*/).map(&N.method(:[]))*'/'}"]
0
+}if !k.respond_to?:urls}end end;class I<R()
0
 end;self end;class<<self;def goes m
0
 eval S.gsub(/Camping/,m.to_s),TOPLEVEL_BINDING end;def call e
0
 X.M;e=H[e.to_hash];k,m,*a=X.D e.PATH_INFO,(e.REQUEST_METHOD||'get').downcase
0
@@ -50,4 +52,4 @@ def method_missing m,c,*a;X.M;h=Hash===a[-1]?H[a.pop]:{};e=
0
 H[h[:env]||{}].merge!({'rack.input'=>StringIO.new,'REQUEST_METHOD'=>m.to_s})
0
 k=X.const_get(c).new(H[e]);k.send("input=",h[:input])if h[:input]
0
 k.service(*a);end;end;module Views;include X,Helpers end;module Models
0
-autoload:Base,'camping/ar';def Y;self;end end;autoload:Mab,'camping/mab'end
0
\ No newline at end of file
0
+autoload:Base,'camping/ar';def Y;self;end end;autoload:Mab,'camping/mab'end

Comments

  • That’s absolutely awesome!

  • I am not sure I see the point… Controllers::BlogXN becomes ’/blog/(\w+)/(\d+)’?

    does that mean we can code controllers like so?

    class BlogXN < R ’/blog/(\w+)/(\d+)’
    def get(x, n)
    #x is a word
    #n is a number
    end
    end

    Or, is there implied arguments based on these new capitol letters in the controller name

    class BlogXXNN < R
    def get(wordone, wordtwo, numberone, numbertwo)
    end
    end

    Or what?

  • You can now code like this:

    class BlogXN # no R
    end

    If you use the R-method, you’ll have to define your own Regex, if not Camping will create one for you :-)