Changeset 222
- Timestamp:
- 09/24/2007 20:20:22 (14 months ago)
- Location:
- trunk/lib
- Files:
-
- 2 modified
-
camping-unabridged.rb (modified) (1 diff)
-
camping.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/camping-unabridged.rb
r221 r222 200 200 end 201 201 202 # Shows AR validation errors for the object passed.203 # There is no output if there are no errors.204 #205 # An example might look like:206 #207 # errors_for @post208 #209 # Might (depending on actual data) render something like this in Markaby:210 #211 # ul.errors do212 # li "Body can't be empty"213 # li "Title must be unique"214 # end215 #216 # Add a simple ul.errors {color:red; font-weight:bold;} CSS rule and you217 # have built-in, usable error checking in only one line of code. :-)218 #219 # See AR validation documentation for details on validations.220 def errors_for(o); ul.errors { o.errors.each_full { |er| li er } } if o.errors.any?; end221 202 # Simply builds a complete path from a path +p+ within the app. If your application is 222 203 # mounted at <tt>/blog</tt>: -
trunk/lib/camping.rb
r221 r222 1 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;class 3 H;def method_missing m,*a;m.to_s=~/=$/?self[$` 4 ]=a[0]:a==[]?self[m]:super end;alias u regular_update;end;module Helpers 5 def R c,*g;p,h=/\(.+?\)/,g.grep(Hash);(g-=h).inject(c.urls.find{|x|x.scan(p). 6 size==g.size}.dup){|s,a|s.sub p,C.escape((a[a.class.primary_key]rescue a))}+( 7 h.any?? "?"+h[0].map{|x|x.map{|z|C.escape z}*"="}*"&": "")end;def errors_for o 8 ul.errors{o.errors.each_full{|er|li er}}if o.errors.any?end;def /(p);p[/^\//]? 9 @root+p:p end;def URL c='/',*a;c=R(c,*a)if c.respond_to?:urls;c=self/c;c="//"+ 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. 5 grep(Hash);(g-=h).inject(c.urls.find{|x|x.scan(p).size==g.size}.dup){|s,a|s. 6 sub p,C.escape((a[a.class.primary_key]rescue a))}+(h.any?? "?"+h[0]. 7 map{|x|x.map{|z|C.escape z}*"="}*"&": "")end;def /(p);p[/^\//]?@root+p:p 8 end;def URL c='/',*a;c=R(c,*a)if c.respond_to?:urls;c=self/c;c="//"+ 10 9 @env.HTTP_HOST+c if c[/^\//];URI(c) end end;module Base;attr_accessor:input, 11 10 :cookies,:env,:headers,:body,:status,:root;Z="\r\n";def method_missing*a,&b;a.
