Hello,
I am using Mustache as a mini-template library in a code generation
application that is not related to HTML. As stated in the docs, my
operators are getting escaped (" >" becomes ">")
I am able to prevent this as described using extra curly braces, but as
I *never* want escaping performed, and I would prefer to avoid having to
instruct my users on when to use triple braces, is it possible to turn
off escaping at a more global level, or via an option to
Mustache.render, or something similar?
Thanks,
Nathan
On Fri, Apr 16, 2010 at 6:01 PM, Nathan Stults <Nathan_Stults@hsihealth.com> wrote: > I am using Mustache as a mini-template library in a code generation > application that is not related to HTML. As stated in the docs, my operators > are getting escaped (“ >” becomes “>”) > > I am able to prevent this as described using extra curly braces, but as I > *never* want escaping performed, and I would prefer to avoid having to > instruct my users on when to use triple braces, is it possible to turn off > escaping at a more global level, or via an option to Mustache.render, or > something similar? The idea is that we use a PRAGMA directive to turn this on. Like this: {{% UNESCAPED}} * {{not_escaped}} * {{{escaped}}} Unfortunately this isn't ready for prime time. Making a PRAGMAS feature that matches mustache.js's is a bit difficult and I'm going to need to take another stab (or two) at it before we include it in Mustache. In the meantime here's a hack that is guaranteed to work until Mustache 1.0 (it'll probably still work then, too): class Mustache class Generator alias_method :off_utag, :on_utag alias_method :off_etag, :on_etag alias_method :on_utag, :off_etag alias_method :on_etag, :off_utag end end That is, swap the `on_utag` and `on_etag` method definitions. -- Chris Wanstrath http://github.com/defunkt
Excellent - that is perfect, thank you. -----Original Message----- From: mustache@librelist.com [mailto:mustache@librelist.com] On Behalf Of Chris Wanstrath Sent: Sunday, April 18, 2010 12:06 PM To: mustache@librelist.com Subject: Re: [mustache] Globally prevent escaping? On Fri, Apr 16, 2010 at 6:01 PM, Nathan Stults <Nathan_Stults@hsihealth.com> wrote: > I am using Mustache as a mini-template library in a code generation > application that is not related to HTML. As stated in the docs, my > operators are getting escaped (“ >” becomes “>”) > > I am able to prevent this as described using extra curly braces, but > as I > *never* want escaping performed, and I would prefer to avoid having to > instruct my users on when to use triple braces, is it possible to turn > off escaping at a more global level, or via an option to > Mustache.render, or something similar? The idea is that we use a PRAGMA directive to turn this on. Like this: {{% UNESCAPED}} * {{not_escaped}} * {{{escaped}}} Unfortunately this isn't ready for prime time. Making a PRAGMAS feature that matches mustache.js's is a bit difficult and I'm going to need to take another stab (or two) at it before we include it in Mustache. In the meantime here's a hack that is guaranteed to work until Mustache 1.0 (it'll probably still work then, too): class Mustache class Generator alias_method :off_utag, :on_utag alias_method :off_etag, :on_etag alias_method :on_utag, :off_etag alias_method :on_etag, :off_utag end end That is, swap the `on_utag` and `on_etag` method definitions. -- Chris Wanstrath http://github.com/defunkt
It doesn't look like there is a way, currently. Looking at the parser, you can probably add a default parser tag type (see http://github.com/defunkt/mustache/blob/master/lib/mustache/parser.rb#L158-160). Set it to :utag instead of :etag, and you're good to go. This will probably bite me in the near future too, I'm using Mustache with plain text email templates. On Fri, Apr 16, 2010 at 3:01 PM, Nathan Stults <Nathan_Stults@hsihealth.com> wrote: > Hello, > > > > I am using Mustache as a mini-template library in a code generation > application that is not related to HTML. As stated in the docs, my operators > are getting escaped (“ >” becomes “>”) > > I am able to prevent this as described using extra curly braces, but as I > *never* want escaping performed, and I would prefer to avoid having to > instruct my users on when to use triple braces, is it possible to turn off > escaping at a more global level, or via an option to Mustache.render, or > something similar? > > > > Thanks, > > > > Nathan -- Rick Olson