| CODENOTIFIER | HelpYou are not signed inSign in |
Project: Camping
Revision: 234
Author: zimbatm
Date: 01 Oct 2007 01:41:53
Diff at Trac: http://code.whytheluckystiff.net/camping/changeset/234
Changes:ActiveSupport dependency gone ! H is now simply inheriting from Hash.
Files:| ... | ...@@ -1,7 +1,7 @@ | |
| 1 | %w[active_support markaby tempfile uri].map{|l|require l};module Camping;C=self | |
| 2 | S=IO.read(__FILE__)rescue nil;P="Cam\ping Problem!";H=HashWithIndifferentAccess | |
| 3 | class H;def method_missing m,*a;m.to_s=~/=$/?self[$`]=a[0]:a==[]?self[m]:super | |
| 4 | end;alias u regular_update;end;module Helpers def R c,*g;p,h=/\(.+?\)/,g. | |
| 1 | %w[markaby tempfile uri].map{|l|require l};module Camping;C=self | |
| 2 | S=IO.read(__FILE__)rescue nil;P="Cam\ping Problem!";class H<Hash | |
| 3 | def method_missing m,*a;m.to_s=~/=$/?self[$`]=a[0]:a==[]?self[m.to_s]:super | |
| 4 | end;alias u merge!;end;module Helpers def R c,*g;p,h=/\(.+?\)/,g. | |
| 5 | 5 | grep(Hash);(g-=h).inject(c.urls.find{|x|x.scan(p).size==g.size}.dup){|s,a|s. |
| 6 | 6 | sub p,C.escape((a[a.class.primary_key]rescue a))}+(h.any?? "?"+h[0]. |
| 7 | 7 | map{|x|x.map{|z|C.escape z}*"="}*"&": "")end;def /(p);p[/^\//]?@root+p:p |
| ... | ...@@ -19,11 +19,11 @@ | |
| 19 | 19 | b=/(?:\r?\n|\A)#{Regexp::quote"--#$1"}(?:--)?\r$/;until |
| 20 | 20 | @in.eof?;fh=H[];for l in@in;case l;when Z;break;when/^Content-D.+?: form-data;/ |
| 21 | 21 | fh.u H[*$'.scan(/(?:\s(\w+)="([^"]+)")/).flatten];when |
| 22 | /^Content-Type: (.+?)(\r$|\Z)/m;fh[:type]=$1;end;end;fn=fh[:name];o=if fh[ | |
| 23 | :filename];o=fh[:tempfile]=Tempfile.new(:C);o.binmode;else;fh=""end;s=8192;k='' | |
| 22 | /^Content-Type: (.+?)(\r$|\Z)/m;fh.type=$1;end;end;fn=fh.name;o=if fh. | |
| 23 | filename;o=fh.tempfile=Tempfile.new(:C);o.binmode;else;fh=""end;s=8192;k='' | |
| 24 | 24 | l=@in.read(s*2);while l;if(k<<l)=~b;o<<$`.chomp;@in.seek(-$'.size,IO::SEEK_CUR) |
| 25 | break;end;o<<k.slice!(0...s);l=@in.read(s);end;C.qsp(fn,'&;',fh,q)if fn;fh[ | |
| 26 | :tempfile].rewind if fh.is_a?H;end;when "application/x-www-form-urlencoded" | |
| 25 | break;end;o<<k.slice!(0...s);l=@in.read(s);end;C.qsp(fn,'&;',fh,q)if fn;fh. | |
| 26 | tempfile.rewind if fh.is_a?H;end;when "application/x-www-form-urlencoded" | |
| 27 | 27 | q.u C.qsp(@in.read)end;@cookies,@input=@k.dup,q.dup end |
| 28 | 28 | def service*a;@body=send(@method,*a)if respond_to?@method |
| 29 | 29 | headers["Set-Cookie"]=cookies.map{|k,v|"#{k}=#{C.escape v}; path=#{self/'/'}"if |
| ... | ...@@ -28,7 +28,7 @@ | |
| 28 | 28 | # http://rubyforge.org/projects/mongrel Mongrel comes with examples |
| 29 | 29 | # in its <tt>examples/camping</tt> directory. |
| 30 | 30 | # |
| 31 | %w[active_support markaby tempfile uri].map { |l| require l } | |
| 31 | %w[markaby tempfile uri].map { |l| require l } | |
| 32 | 32 | |
| 33 | 33 | # == Camping |
| 34 | 34 | # |
| ... | ...@@ -85,8 +85,7 @@ | |
| 85 | 85 | C = self |
| 86 | 86 | S = IO.read(__FILE__) rescue nil |
| 87 | 87 | P = "Cam\ping Problem!" |
| 88 | H = HashWithIndifferentAccess | |
| 89 | # An object-like Hash, based on ActiveSupport's HashWithIndifferentAccess. | |
| 88 | # An object-like Hash. | |
| 90 | 89 | # All Camping query string and cookie variables are loaded as this. |
| 91 | 90 | # |
| 92 | 91 | # To access the query string, for instance, use the <tt>@input</tt> variable. |
| ... | ...@@ -109,7 +108,7 @@ | |
| 109 | 108 | # |
| 110 | 109 | # Use the <tt>@cookies</tt> variable in the same fashion to access cookie variables. |
| 111 | 110 | # Also, the <tt>@env</tt> variable is an H containing the HTTP headers and server info. |
| 112 | class H | |
| 111 | class H < Hash | |
| 113 | 112 | # Gets or sets keys in the hash. |
| 114 | 113 | # |
| 115 | 114 | # @cookies.my_favorite = :macadamian |
| ... | ...@@ -117,9 +116,9 @@ | |
| 117 | 116 | # => :macadamian |
| 118 | 117 | # |
| 119 | 118 | def method_missing(m,*a) |
| 120 | m.to_s=~/=$/?self[$`]=a[0]:a==[]?self[m]:super | |
| 119 | m.to_s=~/=$/?self[$`]=a[0]:a==[]?self[m.to_s]:super | |
| 121 | 120 | end |
| 122 | alias u regular_update | |
| 121 | alias u merge! | |
| 123 | 122 | end |
| 124 | 123 | |
| 125 | 124 | # Helpers contains methods available in your controllers and views. You may add |
| ... | ...@@ -369,12 +368,12 @@ | |
| 369 | 368 | when /^Content-D.+?: form-data;/ |
| 370 | 369 | fh.u H[*$'.scan(/(?:\s(\w+)="([^"]+)")/).flatten] |
| 371 | 370 | when /^Content-Type: (.+?)(\r$|\Z)/m |
| 372 | fh[:type] = $1 | |
| 371 | fh.type = $1 | |
| 373 | 372 | end |
| 374 | 373 | end |
| 375 | fn=fh[:name] | |
| 376 | o=if fh[:filename] | |
| 377 | o=fh[:tempfile]=Tempfile.new(:C) | |
| 374 | fn=fh.name | |
| 375 | o=if fh.filename | |
| 376 | o=fh.tempfile=Tempfile.new(:C) | |
| 378 | 377 | o.binmode |
| 379 | 378 | else |
| 380 | 379 | fh="" |
| ... | ...@@ -392,7 +391,7 @@ | |
| 392 | 391 | l=@in.read(s) |
| 393 | 392 | end |
| 394 | 393 | C.qsp(fn,'&;',fh,q) if fn |
| 395 | fh[:tempfile].rewind if fh.is_a?H | |
| 394 | fh.tempfile.rewind if fh.is_a?H | |
| 396 | 395 | end |
| 397 | 396 | when "application/x-www-form-urlencoded" |
| 398 | 397 | q.u(C.qsp(@in.read)) |
| ... | ...@@ -674,7 +673,7 @@ | |
| 674 | 673 | # Blog.post(:Login, :input => {'username' => 'admin', 'password' => 'camping'}) |
| 675 | 674 | # #=> #<Blog::Controllers::Login @user=... > |
| 676 | 675 | # |
| 677 | # Blog.get(:Info, :env => {:HTTP_HOST => 'wagon'}) | |
| 676 | # Blog.get(:Info, :env => {'HTTP_HOST' => 'wagon'}) | |
| 678 | 677 | # #=> #<Blog::Controllers::Info @env={'HTTP_HOST'=>'wagon'} ...> |
| 679 | 678 | # |
| 680 | 679 | def method_missing(m, c, *a) |