Module: Camping

Defined in:
lib/camping.rb,
lib/camping/db.rb,
lib/camping/fastcgi.rb,
lib/camping/session.rb,
lib/camping/reloader.rb

Defined Under Namespace

Modules: Base, Helpers, Models, Session, Views Classes: FastCGI, H, Mab, Reloader

Constant Summary collapse

Apps =
[]
C =
self
S =
IO.read(__FILE__).sub(/S=I.+$/,'')
P =
"Cam\ping Problem!"
X =
module Controllers;@r=[];class<<self;def r;@r;end;def R*u;r=@r;Class.new{
meta_def(:urls){u};meta_def(:inherited){|x|r<<x}}end;def M;def M;end;constants.map{|c|
k=const_get(c);k.send:include,C,Base,Models;r[0,0]=k if !r.include?k;k.meta_def(
:urls){["/#{c.downcase}"]}if !k.respond_to?:urls}end;def D p;r.map{|k|k.urls.
map{|x|return k,$~[1..-1]if p=~/^#{x}\/?$/}};[NotFound,[p]]end end;class 
NotFound<R();def get p;r(404,Mab.new{h1 P;h2 p+" not found"})end end;class 
ServerError<R();def get k,m,e;r(500,Mab.new{h1 P;h2"#{k}.#{m}";h3"#{e.class
} #{e.message}:";ul{e.backtrace.each{|bt|li(bt)}}}.to_s)end end;self;end

Class Method Summary collapse

Class Method Details

.escape(s) ⇒ Object



37
38
# File 'lib/camping.rb', line 37

def escape s;s.to_s.gsub(/[^ \w.-]+/n){'%'+($&.
unpack('H2'*$&.size)*'%').upcase}.tr(' ','+')end

.goes(m) ⇒ Object



36
37
# File 'lib/camping.rb', line 36

def goes m;eval S.gsub(/Camping/,m.to_s).gsub("A\pps=[]","Cam\ping::Apps<<\
self"),TOPLEVEL_BINDING;end

.kp(s) ⇒ Object



41
42
# File 'lib/camping.rb', line 41

def
kp s;c=qs_parse(s,';,')end

.method_missing(m, c, *a) ⇒ Object



45
46
47
# File 'lib/camping.rb', line 45

def method_missing m,c,*a;X.M;k=X.const_get(c).new(StringIO.new,H['HTTP_HOST',
'','SCRIPT_NAME','','HTTP_COOKIE',''],m.to_s);H.new(a.pop).each{|e,f|k.send(
"#{e}=",f)}if Hash===a[-1];k.service *a;end

.qs_parse(q, d = '&;') ⇒ Object



39
40
41
# File 'lib/camping.rb', line 39

def qs_parse q,d='&;';m=proc{|_,o,n|o.u(
n,&m)rescue([*o]<<n)};q.to_s.split(/[#{d}] */n).inject(H[]){|h,p|k,v=un(p).
split('=',2);h.u k.split(/[\]\[]+/).reverse.inject(v){|x,i|H[i,x]},&m}end

.run(r = $stdin, e = ENV) ⇒ Object



42
43
44
# File 'lib/camping.rb', line 42

def run r=$stdin,e=ENV;X.M;k,a=X.D un("/#{e[
'PATH_INFO']}".gsub(/\/+/,'/'));k.new(r,e,(m=e['REQUEST_METHOD']||"GET")).Y.
service *a;rescue Exception=>x;X::ServerError.new(r,e,'get').service(k,m,x)end

.un(s) ⇒ Object



38
39
# File 'lib/camping.rb', line 38

def un s;s.tr('+',' ').gsub(
/%([\da-f]{2})/in){[$1].pack('H*')}end