Skip to content

Instantly share code, notes, and snippets.

@foca
Created March 13, 2009 20:13
Show Gist options
  • Save foca/78736 to your computer and use it in GitHub Desktop.
Save foca/78736 to your computer and use it in GitHub Desktop.
require "sinatra"
require "sinatra/rendering"
render_with :haml
get "/" do
render :homepage
end
get "/some-ajax-action", :provides => "application/javascript" do
partial :section
end
use_inline_templates!
__END__
@@layout
%body
= yield
@@homepage
#section= partial :section
%a{ :href => "#" } Update via ajax
@@section
hi!
module Sinatra
module Rendering
module Helpers
def render(view, options={})
send self.class.rendering_engine || :erb, view, options
end
def partial(view, options={})
render view, { :layout => false }.merge(options)
end
end
module Extensions
attr_reader :rendering_engine
def render_with(engine)
@rendering_engine=engine
end
end
end
helpers Rendering::Helpers
register Rendering::Extensions
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment