%w[rubygems active_record markaby metaid ostruct].each {|lib| require lib} module Camping;module Models;Base = ActiveRecord::Base;end;module Views;end Markaby::Builder.class_eval{include Views};module Controllers;module RM attr_accessor :input,:cookies,:headers,:body,:status;def method_missing(m, *args, &blk);str=eval("markaby.#{m}(*args, &blk)");str=markaview(:layout){ str}rescue nil;r(200,str.to_s,'Content-Type'=>'text/html');end;def render(m) str = markaview(m);str = markaview(:layout){ str }rescue nil;r(200, str, "Content-Type" => 'text/html');end;def redirect(*args);c, *args = args;if \ c.respond_to? :urls;c = c.urls.first;c.gsub!(/\(.+?\)/) do;((a = args. shift).respond_to?(:primary_key) ? a.method(a.primary_key) : a).to_s;end end;r(302,'','Location' => c);end;def r(s, b, h = {});@status = s;@headers. merge!(h);@body = b;end;def service(e, m, a);@status, @headers = 200, {'Content-Type' => 'text/html'};@cookies=Camping.cookie_parse(e['COOKIE']|| e['HTTP_COOKIE']);cook = @cookies.marshal_dump.dup;if (e['REQUEST_METHOD']== 'POST')and %r|\Amultipart/form-data.*boundary=\"?.+?\"?|n=~e['CONTENT_TYPE'] return r(500, "Urgh, multipart/form-data not yet supported.");else;@input = Camping.qs_parse(e['REQUEST_METHOD']!="POST" ? e['QUERY_STRING'] : $stdin. read(e['CONTENT_LENGTH'].to_i));end;@body = method( m.downcase ).call(*a) @headers['Set-Cookie'] = @cookies.marshal_dump.map { |k,v| "#{k}=#{Camping. escape(v)}; path=/"if v != cook[k]}.compact;self;end;def to_s;"Status: #{ @status}\n#{@headers.map{|k,v|v.to_a.map{|v2|"#{k}: #{v2}"}}.flatten.join( "\n")}\n\n#{@body}";end;private;def markaby;Markaby::Builder.new( instance_variables.map{|iv|[iv[1..-1].intern, instance_variable_get(iv)] }, {});end;def markaview(m,*args,&blk);markaby.instance_eval{Views. instance_method(m).bind(self).call(*args, &blk); self }.to_s;end;end;class R include RM end;class NotFound < R;def get;r(404,h1('Camping Problem!')+h2( 'Not Found'))end end;class<e puts Response.new(200){@headers['Content-Type']='text/html';@body=Markaby:: Builder.new({},{}){h1'Camping Problem!';h2"#{k}.#{m}";h3"#{e.class} \ #{e.message}:";ul{e.backtrace.each{|bt|li bt}}}.to_s};end end end end