Skip to content

Commit

Permalink
Update the README with an example of how to write a method that works…
Browse files Browse the repository at this point in the history
… with capture_end (Fixes #15)
  • Loading branch information
jeremyevans committed Oct 15, 2018
1 parent e98b24c commit db21a52
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,35 @@ To use the capture_end support with tilt:
require 'erubi/capture_end'
Tilt.new("filename.erb", :engine_class=>Erubi::CaptureEndEngine).render

When using the capture_end support, any methods (such as +form+ in the example
above) should return the (potentially modified) buffer. Since the buffer
variable is a local variable and not an instance variable by default, you'll
probably want to set the +:bufvar+ variable when using the capture_end
support to an instance variable, and have any methods used access that
instance variable. Example:

def form
@_buf << "<form>"
yield
@_buf << "</form>"
@_buf
end

puts eval(Erubi::CaptureEndEngine.new(<<-END, :bufvar=>:@_buf).src)
before
<%|= form do %>
inside
<%| end %>
after
END

# Output:
# before
# <form>
# inside
# </form>
# after

= Reporting Bugs

The bug tracker is located at https://github.com/jeremyevans/erubi/issues
Expand Down

0 comments on commit db21a52

Please sign in to comment.