Sha256: 7cf24383c4df51b5e811b9f9575b38ca90729fef3f74aec2a4028e85169238c2

Contents?: true

Size: 1.06 KB

Versions: 3

Compression:

Stored size: 1.06 KB

Contents

$:.unshift( "../lib" )
require 'capcode'

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" if you.nil?
      
      session = { :user => you }
      
      "Hello " + bold { you } + " it's '#{Time.now} !"
    end
  end
  
  class Redir < Route '/r'
    def get
      redirect( Hello, "Greg" )
    end
  end
  
  class Glop < Route '/glop/(.*)', '/glop/code/([^\/]*)/(.*)'
    def get( r, v )
      "Glop receive #{r}, type #{r.class} and #{v}, type #{v.class} from #{URL(Glop)}"
    end
  end
  
  class Js < Route '/toto'
    def get
      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" )      
      x
    end
  end
end

Capcode.map( "/file" ) do
  Rack::File.new( "." )
end

Capcode.run( :port => 3001, :host => "localhost" )

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
Capcode-0.1.0 examples/sample.rb
Capcode-0.2.0 examples/sample.rb
Capcode-0.3.0 examples/sample.rb