Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
##### BOOTLOADER EXAMPLE
MyStack::BootLoader.add(:some_bootloader, :before => :mount_applications) do
def run!
# stuff to do to prepare the app before mounting applications
end
end
##### Configuration Example
MyStack.configuration do
default :page_title, "Awesome!"
default :home_url, :home
default :use_live_resource lambda{ _use_live_resource? }
def _use_live_resource?
Pancake.env != "development"
end
end
MyStack.configuration.page_title #=> "Awesome!"
MyStack.configuration.page_title = "Cool!"
MyStack.configuration.page_title #=> "Cool!"
MyStack.configuration.some_unkown_value #=> nil
MyStack.configuraiton.some_unknown_value = "foo"
MyStack.configuration.some_unknown_value #=> "foo"
class ChildStack < MyStack; end
ChildStack.configuration.page_title #=> "Awesome!"
##### ContentType negotiation
# Add a mime type
Pancake::MimeTypes::Type.new("foo", "text/foo")
Pancake::MimeTypes::Type.new("special", "text/plain")
# Group mime types together to simplify responding
Pancake::MimeTypes.group_as(:html, "xhtml", "foo")
Pancake::MimeTypes.group_as(:special, "special", "log")
# Low level usage
Pancake::MimeType.negotiate_accept_type(accept_type, :html, :special)
# Use in a short stack
class MyShortStack < Pancake::Stacks::Short
provides :html, :special
get "/foo(.:format)" do
case content_type
when :html
# respond with html
when :special
# respond with special
end
end
end
##### Stack Inheritance example
class OurBaseStack < Pancake::Stacks::Short
router do |r|
r.mount(UserStack, "/users")
r.mount(AdminStack, "/admin")
r.mount(AssetStack, "/assets")
r.add("/heartbeat"){ |env| Rack::Response.new("alive!").finish }
end
stack(:uploader).use(Rack::Upload)
get "(/)" do
render :welcome
end
end
class ClientApplication < OurBaseStack
get "/specific/functionality" do
# stuff
end
end
##### Middleware example
Pancake.stack(:session).use(Rack::Session::Cookie)
Pancake.stack(:auth).use(Warden::Manager) do |manager|
manager.failure_app = FailStack
manager.default_strategies = :password
end
class MyStack < Pancake::Stack
stack(:soap).use(SoapMunger)
stack(:soap_validator, :before => :soap).use(SoapValidator)
end
##### PATH MANAGEMENT
MyStack.push_paths :my_file_group, ["relative/path1", "relative/path2"], "**/*.rb"
MyStack.push_paths :my_file_group, "relative/path3"
MyStack.dirs_for :my_file_group #=> MyStack.roots * [relative/path1, relative/path2, relative/path3]
MyStack.dirs_and_glob_for :my_file_group #=> MyStack.roots * [relative/path1, **/*.rb]
#=> MyStack.roots * [relative/path2, **/*.rb]
#=> MyStack.roots * [relative/path3, nil]
MyStack.paths_for(:my_file_group) # list of all files that match all roots * relative_paths * globs
MyStack.unique_paths_for(:my_file_group) # like paths_for but will unique the files taking the last declared
MyStack.unique_paths_for(:my_file_group, :invert => true)
##### ROUTER EXAMPLE
MyStack.router do |r|
r.mount(AnotherStack, "/mount/point")
r.add("/foo") do |env|
Rack::Response.new("OK")
end
r.add("/:some/:variable(.:format)").to(MySinatraApp)
end
class MyStack < Pancake::Stack; end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.