Created
September 13, 2010 21:01
-
-
Save robhurring/578046 to your computer and use it in GitHub Desktop.
content_for in sinatra : http://proccli.com/railslike-contentfor-sinatra
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id='sidebar'> | |
<%= section(:sidebar) || partial(:default_sidebar) %> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Sinatra::Helpers | |
def section(key, *args, &block) | |
@sections ||= Hash.new{ |k,v| k[v] = [] } | |
if block_given? | |
@sections[key] << block | |
else | |
@sections[key].inject(''){ |content, block| content << block.call(*args) } if @sections.keys.include?(key) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% section(:sidebar){ partial :custom_sidebar, :local1 => blah, :local2 => blah } %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment