Forked from seanami/sinatra_erb_block_helper_test.rb
Last active
December 22, 2015 00:09
-
-
Save riddla/6387607 to your computer and use it in GitHub Desktop.
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
helpers do | |
def buffer() | |
@_out_buf | |
end | |
def capture(buffer) | |
pos = buffer.size | |
yield | |
buffer.slice!(pos..buffer.size) | |
end | |
def my_helper(&block) | |
buffer << ERB.new(capture(buffer, &block)) | |
end | |
end | |
## Usage | |
# <% my_helper do %> | |
# <p>This is the content in the block.</p> | |
# <% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment