Using Erubis::EscapedEruby with Tilt

Showing 1-7 of 7 messages
Using Erubis::EscapedEruby with Tilt Geoff Buesing 3/8/10 1:34 PM
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?

Re: Using Erubis::EscapedEruby with Tilt Ryan Tomayko 3/8/10 1:42 PM

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

Re: Using Erubis::EscapedEruby with Tilt Geoff Buesing 3/8/10 2:54 PM

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:

Re: Using Erubis::EscapedEruby with Tilt Ryan Tomayko 3/8/10 3:03 PM
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

Re: Using Erubis::EscapedEruby with Tilt Geoff Buesing 3/8/10 4:08 PM
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:

Re: Using Erubis::EscapedEruby with Tilt Ryan Tomayko 3/9/10 6:56 AM
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

> On Mar 8, 5:03 pm, Ryan Tomayko <rtoma...@gmail.com> wrote:
>> On Mon, Mar 8, 2010 at 2:54 PM, Geoff Buesing <gbues...@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
>

Re: Using Erubis::EscapedEruby with Tilt Geoff Buesing 5/7/10 11:58 AM
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...