Skip to content

Instantly share code, notes, and snippets.

@tomdalling
Last active April 11, 2016 07:28
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 tomdalling/e172740f4f18c0f53d036bb0f8b775a7 to your computer and use it in GitHub Desktop.
Save tomdalling/e172740f4f18c0f53d036bb0f8b775a7 to your computer and use it in GitHub Desktop.
Cells Erbse automatic escaping
require 'cell'
class AppCell < Cell::ViewModel
include ::Cell::Erb
def show
render
end
def template_options_for(*args)
super.merge(escape: true)
end
end
class Cell::ViewModel::OutputBuffer
def safe_expr_append=(value)
self.safe_append = CGI.escape_html(value.to_s)
end
end
# Makes this ERB code work:
#
# Escape this: <%= "<b>should not be bold</b>" %>
# Don't escape this: <%== '<a href="#">muh link</a>' %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment