app/helpers/base.rb
# The heart of the path / verb / any condition matching.
#
# @example
#
#   on get do
#     res.write "GET"
#   end
#
#   on get, "signup" do
#     res.write "Signup"
#   end
#
#   on "user/:id" do |uid|
#     res.write "User: #{uid}"
#   end
#
#   on "styles", extension("css") do |file|
#     res.write render("styles/#{file}.sass")
#   end
#
The heart of the path / verb / any condition matching.
The heart of the path / verb / any condition matching .
def on(*args, &block)
    try do
      @captures = []
       Short circuit examples:
          on true, false do
           PATH_INFO=/user
          on true, "signup"
      return unless args.all? { |arg| match(arg) }
       The captures we yield here were generated and assembled
       by evaluating each of the `arg`s above. Most of these
       are carried out by consume.
      yield(*captures)
      if res.status.nil?
        if res.body.empty?
          res.status = 404
        else
          res.headers["Content-Type"] ||= "text/html; charset=utf-8"
          res.status = 200
        end
      end
      halt(res.finish)
    end
  end
def on ( * args , & block ) try do @captures = [ ] return unless args . all? { | arg | match ( arg ) } yield ( * captures ) if res . status . nil? if res . body . empty? res . status = 404 else res . headers [ "Content-Type" ] ||= "text/html; charset=utf-8" res . status = 200 end end halt ( res . finish ) end end
The heart of the path / verb / any condition matching.
The heart of the path / verb / any condition matching .
# For every block, we make sure to reset captures so that # nesting matchers won't mess with each other's captures. # We stop evaluation of this entire matcher unless # each and every `arg` defined for this matcher evaluates # to a non-false value. # # Short circuit examples: #    on true, false do # #    # PATH_INFO=/user #    on true, "signup" # The captures we yield here were generated and assembled # by evaluating each of the `arg`s above. Most of these # are carried out by #consume.
args
<not_specific>
block
<not_specific>
example
on get do res.write "GET" end on get, "signup" do res.write "Signup" end on "user/:id" do |uid| res.write "User: #{uid}" end on "styles", extension("css") do |file| res.write render("styles/#{file}.sass") end
on get do res . write " GET " end on get " signup " do res . write " Signup " end on " user / : id " do |uid| res . write " User : # { uid } " end on " styles " extension ( " css " ) do |file| res . write render ( " styles / # { file } . sass " ) end