Skip to content

Instantly share code, notes, and snippets.

@riddla
Forked from seanami/sinatra_erb_block_helper_test.rb
Last active December 22, 2015 00:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save riddla/6387607 to your computer and use it in GitHub Desktop.
Save riddla/6387607 to your computer and use it in GitHub Desktop.
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