Sha256: 730007fb872cabd172c6d5c92e4bc44ac2d0f4b14cce3daff2650267b627037a
Contents?: true
Size: 1.94 KB
Versions: 9
Compression:
Stored size: 1.94 KB
Contents
$:.unshift( "../lib" ) require 'rubygems' require 'capcode' require 'capcode/render/markaby' require 'capcode/render/haml' Capcode::Helpers.haml_path = "haml" require 'capcode/render/json' require 'capcode/render/erb' Capcode::Helpers.erb_path = "erb" module Capcode module Helpers def bold( &b ) "<b>"+yield+"</b>" end end end module Capcode class HTTPError def r404(f) "Pas glop !!! #{f} est inconnu !!!" end end class Hello < Route '/hello/(.*)' def get( you ) @you = you @you = "you" if you.nil? session = { :user => @you } render( :haml => :m_hello ) end end class Redir < Route '/r' def get redirect( Hello, "Greg" ) end end class Glop < Route '/glop/(.*)', '/glop/code/([^\/]*)/(.*)' def get( r, v ) render( :text => "Glop receive #{r}, type #{r.class} and #{v}, type #{v.class} from #{URL(Glop)}" ) end end class Js < Route '/toto' def get render( :json => { :some => 'json', :stuff => ['here'] } ) end end class Env < Route '/env' def get x = env.map do |k,v| "#{k} => #{v}" end.join( "<br />\n" ) render( :text => x ) end end class ContentFor < Route '/cf' def get render( :erb => :cf, :layout => :cf_layout ) end end end module Capcode::Views def cf_layout html do head do yield :header end body do yield :content end end end def cf content_for :header do title "This is the title!" end content_for :content do p "this is the content!" end end def layout html do head do title "Use a layout ;)" end body do yield end end end def m_hello p do text "Hello " b @you text " it's '#{Time.now} !" end end end Capcode.run( :port => 3001, :host => "localhost", :static => "static" )
Version data entries
9 entries across 9 versions & 1 rubygems