Changeset 110

Show
Ignore:
Timestamp:
06/08/2006 14:21:32 (2 years ago)
Author:
why
Message:
  • lib/camping.rb: new Camping::Apps stores all app modules.
  • examples/*: updated the postambles per zimbatm's #28.
Location:
trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/examples/blog/blog.rb

    r83 r110  
    272272 
    273273if __FILE__ == $0 
    274   require 'mongrel/camping' 
     274  begin 
     275    require 'mongrel/camping' 
     276  rescue LoadError => e 
     277    abort "** Try running `camping #$0' instead." 
     278  end 
    275279 
    276280  Blog::Models::Base.establish_connection :adapter => 'sqlite3', :database => 'blog.db' 
  • trunk/examples/campsh/campsh.rb

    r103 r110  
    621621 
    622622if __FILE__ == $0 
    623   CampSh::Models::Base.establish_connection :adapter => 'sqlite3', :database => 'campsh.db' 
     623  begin 
     624    require 'mongrel/camping' 
     625  rescue LoadError => e 
     626    abort "** Try running `camping #$0' instead." 
     627  end 
     628 
     629  CampSh::Models::Base.establish_connection :adapter => 'sqlite3', :database => 'blog.db' 
    624630  CampSh::Models::Base.logger = Logger.new('camping.log') 
     631  CampSh::Models::Base.threaded_connections=false 
    625632  CampSh.create 
    626   puts CampSh.run 
     633 
     634  server = Mongrel::Camping::start("0.0.0.0",3002,"/",CampSh) 
     635  puts "** CampSh example is running at http://localhost:3002/" 
     636  server.run.join 
    627637end 
  • trunk/lib/camping-unabridged.rb

    r108 r110  
    8787# For more tips, see http://code.whytheluckystiff.net/camping/wiki/GiveUsTheCreateMethod. 
    8888module Camping 
     89  # Stores an +Array+ of all Camping applications modules.  Modules are added 
     90  # automatically by +Camping.goes+. 
     91  # 
     92  #   Camping.goes :Blog 
     93  #   Camping.goes :Tepee 
     94  #   Camping::Apps # => [Blog, Tepee] 
     95  #  
     96  Apps = [] 
    8997  C = self 
    9098  F = __FILE__ 
     
    548556    def goes(m) 
    549557        eval(S.gsub(/Camping/,m.to_s),TOPLEVEL_BINDING) 
     558        Apps << const_get(m) 
    550559    end 
    551560 
  • trunk/lib/camping.rb

    r108 r110  
    11%w[active_record markaby metaid tempfile uri].each{|l|require l} 
    2 module Camping;C=self;F=__FILE__;S=IO.read(F).gsub(/_+FILE_+/,F.dump) 
     2module Camping;Apps=[];C=self;F=__FILE__;S=IO.read(F).gsub(/_+FILE_+/,F.dump) 
    33module Helpers;def R c,*args;p=/\(.+?\)/;args.inject(c.urls.find{|x|x.scan(p). 
    44size==args.size}.dup){|str,a|str.sub(p,C.escape((a.__send__(a.class.primary_key 
     
    3434k.meta_def(:urls){["/#{c.downcase}"]}if !(k<R);d||([k,$~[1..-1]]if k.urls.find{ 
    3535|x|path=~/^#{x}\/?$/})}||[NotFound,[path]] end end end;class<<self;def goes m 
    36 eval(S.gsub(/Camping/,m.to_s),TOPLEVEL_BINDING)end;def escape s;s.to_s.gsub( 
     36eval(S.gsub(/Camping/,m.to_s),TOPLEVEL_BINDING);Apps<<const_get(m);end;def escape s;s.to_s.gsub( 
    3737/([^ a-zA-Z0-9_.-]+)/n){'%'+$1.unpack('H2'*$1.size).join('%').upcase}.tr ' ','+' 
    3838end;def un s;s.tr('+', ' ').gsub(/((?:%[0-9a-fA-F]{2})+)/n){[$1.delete('%'