secret
Created

  • Download Gist
my_stack_bootstrap_example.rb
Ruby
1 2 3 4 5 6 7
##### 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
my_stack_configuration_example.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
##### 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!"
my_stack_content_type_negotiation_example.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
##### 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
my_stack_inheritance_example.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
##### 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
my_stack_middleware_example.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12
##### 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
my_stack_paths_example.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14
##### 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)
my_stack_router_example.rb
Ruby
1 2 3 4 5 6 7 8 9
##### 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
stack_definition_example.rb
Ruby
1
class MyStack < Pancake::Stack; end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.