Skip to content

Commit

Permalink
Even more API docs
Browse files Browse the repository at this point in the history
  • Loading branch information
rtomayko committed Mar 24, 2009
1 parent d92d07b commit 9dec74e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/sinatra/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ def send_file(path, opts={})
not_found
end

# Rack response body used to deliver static files. The file contents are
# generated iteratively in 8K chunks.
class StaticFile < ::File #:nodoc:
alias_method :to_path, :path
def each
Expand Down Expand Up @@ -620,14 +622,18 @@ def not_found(&block)
error 404, &block
end

# Define a named template. The block must return the template source.
def template(name, &block)
templates[name] = block
end

# Define the layout template. The block must return the template source.
def layout(name=:layout, &block)
template name, &block
end

# Load embeded templates from the file; uses the caller's __FILE__
# when no file is specified.
def use_in_file_templates!(file=nil)
file ||= caller_files.first
if data = ::IO.read(file).split('__END__')[1]
Expand All @@ -650,10 +656,15 @@ def media_type(type)
Rack::Mime.mime_type(type, nil)
end

# Define a before filter. Filters are run before all requests
# within the same context as route handlers and may access/modify the
# request and response.
def before(&block)
@filters << block
end

# Add a route condition. The route is considered non-matching when the
# block returns false.
def condition(&block)
@conditions << block
end
Expand Down Expand Up @@ -1038,6 +1049,9 @@ def self.register(*extensions, &block) #:nodoc:
class Application < Default
end

# Sinatra delegation mixin. Mixing this module into an object causes all
# methods to be delegated to the Sinatra::Application class. Used primarily
# at the top-level.
module Delegator #:nodoc:
def self.delegate(*methods)
methods.each do |method_name|
Expand All @@ -1056,6 +1070,8 @@ def #{method_name}(*args, &b)
:production?, :use_in_file_templates!, :helpers
end

# Create a new Sinatra application. The block is evaluated in the new app's
# class scope.
def self.new(base=Base, options={}, &block)
base = Class.new(base)
base.send :class_eval, &block if block_given?
Expand Down

0 comments on commit 9dec74e

Please sign in to comment.