Using Erubis::EscapedEruby with Tilt

731 views
Skip to first unread message

Geoff Buesing

unread,
Mar 8, 2010, 4:34:32 PM3/8/10
to Tilt
I'm looking into using Tilt to render Erubis templates with Erubis'
auto-escaping feature (i.e., content within <%= %> is automatically
html-escaped.)

Unfortunately, you can't turn this on with an option to
Erubis::Eruby.new -- you need to use the Erubis::EscapedEruby
subclass.

One could always create a Tilt::EscapedErubisTemplate to achieve this,
but might be nicer if we could pass in an option to
Tilt::ErubisTemplate which would allow you to specify the engine class
to use, something like:

Tilt::ErubisTemplate.new 'foo.erb', 1, :engine_class =>
"::Erubis::EscapedEruby"

Any interest in a patch for this?

Ryan Tomayko

unread,
Mar 8, 2010, 4:42:00 PM3/8/10
to til...@googlegroups.com

Definitely.

I like reserving the options Hash for the underlying engine but this
seems like a reasonable place to break that rule.

:engine_class would work and allow people to write custom subclasses,
which would be another Erubis feature we can't use today. It might be
nice to also have a simpler :escaping => true option too.

Thanks,
Ryan

Geoff Buesing

unread,
Mar 8, 2010, 5:54:39 PM3/8/10
to Tilt

Indeed, handy to have :engine_class as a hook point for custom Erubis
subclasses. One potentially interesting possibility with this would be
to set :engine_class to the Erubis subclass in ActionPack, for
compatibility with code that uses Rails' new html_safe method.

Re: :escaping => true, this would be a nice convenience for the most
common case. Haml calls this option :escape_html; probably makes sense
to use this as the convention and have it work for both Haml and
Erubis?


On Mar 8, 3:42 pm, Ryan Tomayko <rtoma...@gmail.com> wrote:

Ryan Tomayko

unread,
Mar 8, 2010, 6:03:08 PM3/8/10
to til...@googlegroups.com
On Mon, Mar 8, 2010 at 2:54 PM, Geoff Buesing <gbue...@gmail.com> wrote:
> Indeed, handy to have :engine_class as a hook point for custom Erubis
> subclasses. One potentially interesting possibility with this would be
> to set :engine_class to the Erubis subclass in ActionPack, for
> compatibility with code that uses Rails' new html_safe method.
>
> Re: :escaping => true, this would be a nice convenience for the most
> common case. Haml calls this option :escape_html; probably makes sense
> to use this as the convention and have it work for both Haml and
> Erubis?

Yep. That's perfect.

Thanks,
Ryan

Geoff Buesing

unread,
Mar 8, 2010, 7:08:26 PM3/8/10
to Tilt
Code is here:

http://github.com/gbuesing/tilt/commit/c9bc18ad52a7ba280acaed343647147806fc3e7b

(I just sent a pull request as well.)

On Mar 8, 5:03 pm, Ryan Tomayko <rtoma...@gmail.com> wrote:

Ryan Tomayko

unread,
Mar 9, 2010, 9:56:49 AM3/9/10
to til...@googlegroups.com
On Mon, Mar 8, 2010 at 4:08 PM, Geoff Buesing <gbue...@gmail.com> wrote:
> Code is here:
>
> http://github.com/gbuesing/tilt/commit/c9bc18ad52a7ba280acaed343647147806fc3e7b
>
> (I just sent a pull request as well.)

Looks great. Applied.

Thanks,
Ryan

Geoff Buesing

unread,
May 7, 2010, 2:58:21 PM5/7/10
to Tilt
Just a follow-up on this feature: Erubis :escape_html => true option
works great with Sinatra 1.0 and the latest Tilt 0.9 gem, here's an
example:

http://flowcoder.com/177

On Mar 9, 9:56 am, Ryan Tomayko <rtoma...@gmail.com> wrote:
> On Mon, Mar 8, 2010 at 4:08 PM, Geoff Buesing <gbues...@gmail.com> wrote:
> > Code is here:
>
> >http://github.com/gbuesing/tilt/commit/c9bc18ad52a7ba280acaed34364714...
Reply all
Reply to author
Forward
0 new messages