diff --git a/Rakefile b/Rakefile
index c4247c1..d032ff1 100644
--- a/Rakefile
+++ b/Rakefile
@@ -17,7 +17,7 @@ RDOC_OPTS = ['--quiet', '--title', "Camping, the Documentation",
"--inline-source"]
desc "Packages up Camping."
-task :default => [:size, :package]
+task :default => [:check]
task :package => [:clean]
task :doc => [:before_doc, :rdoc, :after_doc]
@@ -128,15 +128,37 @@ task :diff do
sh "diff -u .camping-unabridged.pt .camping.pt | less"
end
-SIZE_LIMIT = 4096
-desc "Compare camping sizes to unabridged"
-task :size do
- FileList["lib/camping*.rb"].each do |path|
- s = File.size(path)
- puts "%21s : % 6d % 4d%" % [File.basename(path), s, (100 * s / SIZE_LIMIT)]
+task :check => ["check:valid", "check:size", "check:lines"]
+namespace :check do
+
+ desc "Check source code validity"
+ task :valid do
+ ruby "-w", "lib/camping-unabridged.rb"
+ ruby "-w", "lib/camping.rb"
end
- if File.size("lib/camping.rb") > SIZE_LIMIT
- STDERR.puts "ERROR: camping.rb is too big (> #{SIZE_LIMIT})"
- exit 1
+
+ SIZE_LIMIT = 4096
+ desc "Compare camping sizes to unabridged"
+ task :size do
+ FileList["lib/camping*.rb"].each do |path|
+ s = File.size(path)
+ puts "%21s : % 6d % 4d%" % [File.basename(path), s, (100 * s / SIZE_LIMIT)]
+ end
+ if File.size("lib/camping.rb") > SIZE_LIMIT
+ STDERR.puts "lib/camping.rb: file is too big (> #{SIZE_LIMIT})"
+ exit 1
+ end
end
+
+ desc "Verify that line lenght doesn't exceed 80 chars for camping.rb"
+ task :lines do
+ i = 1
+ File.open("lib/camping.rb").each_line do |line|
+ if line.size > 81 # 1 added for \n
+ puts "lib/camping.rb:#{i}: line too long (#{line[-10..-1].inspect})"
+ end
+ i += 1
+ end
+ end
+
end
diff --git a/lib/camping-unabridged.rb b/lib/camping-unabridged.rb
index 0bf5692..86c90a9 100644
--- a/lib/camping-unabridged.rb
+++ b/lib/camping-unabridged.rb
@@ -28,7 +28,7 @@
# http://rubyforge.org/projects/mongrel Mongrel comes with examples
# in its examples/camping directory.
#
-%w[active_support markaby tempfile uri].each { |lib| require lib }
+%w[active_support markaby tempfile uri].map { |l| require l }
# == Camping
#
@@ -91,6 +91,7 @@ module Camping
# Camping::Apps # => [Blog, Tepee]
#
C = self
+ f=__FILE__
S = IO.read(f) unless f =~ /\(/
P="Cam\ping Problem!"
@@ -364,7 +365,7 @@ def redirect(*a)
#
# redirect "/view/12"
#
- def r(s, b, h = {}); @status = s; @headers.merge!(h); @body = b; end
+ def r(s, b, h = {}); @status = s; headers.merge!(h); @body = b; end
# Turn a controller into an array. This is designed to be used to pipe
# controllers into the r method. A great way to forward your
@@ -378,26 +379,25 @@ def r(s, b, h = {}); @status = s; @headers.merge!(h); @body = b; end
# end
# end
#
- def to_a;[@status, @body, @headers] end
+ def to_a;[status, body, headers] end
def initialize(r, e, m) #:nodoc:
e = H[e.to_hash]
@status, @method, @env, @headers, @root = 200, m.downcase, e,
{'Content-Type'=>'text/html'}, e.SCRIPT_NAME.sub(/\/$/,'')
@k = C.kp(e.HTTP_COOKIE)
- qs = C.qsp(e.QUERY_STRING)
+ q = C.qsp(e.QUERY_STRING)
@in = r
- if %r|\Amultipart/form-data.*boundary=\"?([^\";,]+)|n.match(e.CONTENT_TYPE)
+ if %r|\Amultipart/form-.*boundary=\"?([^\";,]+)|n.match(e.CONTENT_TYPE)
b = /(?:\r?\n|\A)#{Regexp::quote("--#$1")}(?:--)?\r$/
until @in.eof?
fh=H[]
for l in @in
case l
when Z: break
- when /^Content-Disposition: form-data;/
+ when /^Content-D.+?: form-data;/
fh.u H[*$'.scan(/(?:\s(\w+)="([^"]+)")/).flatten]
when /^Content-Type: (.+?)(\r$|\Z)/m
- puts "=> fh[type] = #$1"
fh[:type] = $1
end
end
@@ -420,13 +420,13 @@ def initialize(r, e, m) #:nodoc:
o< {'post' => {'id' => '1', 'user' => '_why'}}
#
- def qsp(qs, d='&;', y=nil, z=H[])
+ def qsp(q, d='&;', y=nil, z=H[])
m = proc {|_,o,n|o.u(n,&m)rescue([*o]<layout method defined, it will be called with a block
+ # which will insert content from your view.
+ module Views; include X, Helpers end
+
# Models is an empty Ruby module for housing model classes derived
# from ActiveRecord::Base. As a shortcut, you may derive from Base
# which is an alias for ActiveRecord::Base.
@@ -737,16 +747,7 @@ module Models
autoload :Base,'camping/db'
def Y;self;end
end
-
- # Views is an empty module for storing methods which create HTML. The HTML is described
- # using the Markaby language.
- #
- # == Using the layout method
- #
- # If your Views module has a layout method defined, it will be called with a block
- # which will insert content from your view.
- module Views; include Controllers, Helpers end
-
+
# The Mab class wraps Markaby, allowing it to run methods from Camping::Views
# and also to replace :href, :action and :src attributes in tags by prefixing the root
# path.
@@ -754,7 +755,7 @@ class Mab < Markaby::Builder
include Views
def tag!(*g,&b)
h=g[-1]
- [:href,:action,:src].each{|a|(h[a]=self/h[a])rescue 0}
+ [:href,:action,:src].map{|a|(h[a]=self/h[a])rescue 0}
super
end
end
diff --git a/lib/camping.rb b/lib/camping.rb
index f6374d1..076c5ec 100644
--- a/lib/camping.rb
+++ b/lib/camping.rb
@@ -1,54 +1,53 @@
-%w[active_support markaby tempfile uri].map{|l|require l}
-module Camping;C=self;f=__FILE__;S=IO.read(f)unless f=~/\(/
-P="Cam\ping Problem!";module Helpers;def R(c,*g);p,h=/\(.+?\)/,g.grep(Hash)
-(g-=h).inject(c.urls.find{|x|x.scan(p).size==g.size}.dup){|s,a|s.sub p,C.
-escape((a[a.class.primary_key]rescue a))}+(h.any?? "?"+h[0].map{|x|x.map{|z|C.
-escape z}*"="}*"&": "")end;def URL c='/',*a;c=R(c,*a)if c.respond_to?:urls
-c=self/c;c="//"+@env.HTTP_HOST+c if c[/^\//];URI(c)end;def/p;p[/^\//]?@root+p :
-p end;def errors_for o;ul.errors{o.errors.each_full{|x|li x}}if o.errors.any?end
-end;module Base;attr_accessor:input,:cookies,:env,:headers,:body,
-:status,:root;def method_missing*a,&b;a.shift if a[0]==:render;m=Mab.new({},self)
-s=m.capture{send(*a,&b)};s=m.capture{send(:layout){s}}if /^_/!~a[0].to_s and m.
-respond_to?:layout;s end;def r s,b,h={};@status=s;@headers.merge!h;@body=b end
-def redirect*a;r 302,'','Location'=>URL(*a)end;Z="\r\n";def to_a;[@status,@body,
-@headers]end;def initialize r,e,m;e=H[e.to_hash];@status,@method,@env,@headers,
-@root=200,m.downcase,e,{'Content-Type'=>"text/html"},e.SCRIPT_NAME.sub(/\/$/,'')
-@k=C.kp e.HTTP_COOKIE;q=C.qsp e.QUERY_STRING;@in=r;if%r|\Amultipart/form-.*boun\
-dary=\"?([^\";,]+)|n.match e.CONTENT_TYPE;b=/(?:\r?\n|\A)#{Regexp::quote("--#$1"
-)}(?:--)?\r$/;until@in.eof?;fh=H[];for l in@in;case l;when Z;break
-when/^Content-D.+?: form-data;/;fh.u H[*$'.scan(/(?:\s(\w+)="([^"]+)")/).flatten]
-when/^Content-Type: (.+?)(\r$|\Z)/m;fh[:type]=$1;end;end;fn=fh[:name];o=if
-fh[:filename];o=fh[:tempfile]=Tempfile.new(:C);o.binmode;else;fh=""end;s=8192;k=
-'';l=@in.read(s*2);while l;if(k<x;X::ServerError.new(r,e,'get').service(k,m,x)end
-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;end;module Views;include X,Helpers
-end;module Models;autoload:Base,'camping/db';def Y;self;end;end;class Mab<
-Markaby::Builder;include Views;def tag!*g,&b;h=g[-1];[:href,:action,:src].map{
-|a|(h[a]=self/h[a])rescue 0};super end end;H=HashWithIndifferentAccess;class H
-def method_missing m,*a;m.to_s=~/=$/?self[$`]=a[0]:a==[]?self[m]:super end
-alias u regular_update;end end
+%w[active_support markaby tempfile uri].map{|l|require l};module Camping;C=self
+f=__FILE__;S=IO.read(f)unless f=~/\(/;P="Cam\ping Problem!";H=
+HashWithIndifferentAccess;class H;def method_missing m,*a;m.to_s=~/=$/?self[$`
+]=a[0]:a==[]?self[m]:super end;alias u regular_update;end;module Helpers
+def R c,*g;p,h=/\(.+?\)/,g.grep(Hash);(g-=h).inject(c.urls.find{|x|x.scan(p).
+size==g.size}.dup){|s,a|s.sub p,C.escape((a[a.class.primary_key]rescue a))}+(
+h.any?? "?"+h[0].map{|x|x.map{|z|C.escape z}*"="}*"&": "")end;def errors_for o
+ul.errors{o.errors.each_full{|er|li er}}if o.errors.any?end;def /(p);p[/^\//]?
+@root+p:p end;def URL c='/',*a;c=R(c,*a)if c.respond_to?:urls;c=self/c;c="//"+
+@env.HTTP_HOST+c if c[/^\//];URI(c) end end;module Base;attr_accessor:input,
+:cookies,:env,:headers,:body,:status,:root;Z="\r\n";def method_missing*a,&b;a.
+shift if a[0]==:render;m=Mab.new({},self);s=m.capture{send(*a,&b)};s=m.capture{
+send(:layout){s}}if /^_/!~a[0].to_s and m.respond_to?:layout;s end;def
+redirect*a;r 302,'','Location'=>URL(*a)end;def r s,b,h={};@status=s;headers.
+merge!h;@body=b end;def to_a;[status,body,headers]end;def initialize r,e,m;e=H[
+e.to_hash];@status,@method,@env,@headers,@root=200,m.downcase,e,{
+'Content-Type'=>"text/html"},e.SCRIPT_NAME.sub(/\/$/,'');@k=C.kp e.HTTP_COOKIE
+q=C.qsp e.QUERY_STRING;@in=r;if%r|\Amultipart/form-.*boundary=\"?([^\";,]+)|n.
+match e.CONTENT_TYPE;b=/(?:\r?\n|\A)#{Regexp::quote"--#$1"}(?:--)?\r$/;until
+@in.eof?;fh=H[];for l in@in;case l;when Z;break;when/^Content-D.+?: form-data;/
+fh.u H[*$'.scan(/(?:\s(\w+)="([^"]+)")/).flatten];when
+/^Content-Type: (.+?)(\r$|\Z)/m;fh[:type]=$1;end;end;fn=fh[:name];o=if fh[
+:filename];o=fh[:tempfile]=Tempfile.new(:C);o.binmode;else;fh=""end;s=8192;k=''
+l=@in.read(s*2);while l;if(k<x;X::ServerError.new(
+r,e,'get').service(k,m,x)end;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;end
+module Views;include X,Helpers;end;module Models;autoload:Base,'camping/db';def
+Y;self;end;end;class Mab