ERB support for Cells using Erbse.
Add this line to your application's Gemfile:
This will register
Erbse::Engine with Tilt for
And that's all you need to do.
Erbse is the next-generation implementation of ERB that comes with some nice new semantics and explicit code. It does not use instance variables for output buffering.
You should read its docs to learn what you can and can't do with Erbse.
#concat helper is not supported in Cells-ERB. Erbse uses local variables as output buffers, hence this global state helper does not work. Please use explicit string concatenation instead.
concat content_tag(:p, "Good") concat "Morning!"
you can do
content_tag(:p, "Good") + "Morning!"
With Erbse, you can actually capture blocks, pass them to other cells and
yield them. This will simply return whatever the block returns, no weird buffer magic will be happening in the background.
capture implementation in Cells-ERB is literally a
def capture(&block) yield end
If you want to capture a block of code without outputting it, you need to use Erbse's
<%@ %> tag.
<%@ content = capture do %> <h1>Hi!</h1> It's <%= Time.new %>'o clock. <% end %>
content variable will now contain the string
<h1>Hi!</h1>\nIt's 23:37'o clock..
[email protected] as a mnemonic for the correct tag, should you need this mechanic.
capture is usually a smell of bad view design and should be avoided.
Cells doesn't escape except when you tell it to do. However, you may run into problems when using Rails helpers. Internally, those helpers often blindly escape. This is not Cells' fault but a design flaw in Rails.
As a first step, try this and see if it helps.
class SongCell < ::ViewModel include ActionView::Helpers::FormHelper include :: # include Erb _after_ AV helpers. # .. end
If that doesn't work, read the docs.
This gem works with Tilt 1.4 and 2.0, and hence allows you to use it from Rails 3.2 upwards.