leshill / handlebars_assets

Use handlebars.js templates with the Rails asset pipeline.
MIT License
647 stars 159 forks source link

Template returns SafeString and not String since 0.17 #106

Closed romanbsd closed 9 years ago

romanbsd commented 10 years ago

I'm using handlebars with Marionette/Backbone. Since the version 0.17 the template returns a Handlebars' SafeString rather than JS String, which is quite unfortunate, as jQuery chokes on it. Locked the version to 0.16 for now.

AlexRiedler commented 10 years ago

@romanbsd I don't think this behaviour should have changed... Can you give me a better idea of your setup?

romanbsd commented 10 years ago

This is the template that stopped working:

{{#link class="push-right"}}
  {{name}}
{{/link}}

This is the link helper:

(function(hbs) {

  hbs.registerHelper('link', function(options) {
    var attrs = [], opts = options.hash || {};
    opts.href = this.url;
    for (var prop in opts) {
      attrs.push(prop + '="' + opts[prop] + '"');
    }

    return new hbs.SafeString('<a ' + attrs.join(' ') + '>' + options.fn(this) + '</a>');
  });

})(Handlebars);
AlexRiedler commented 10 years ago

@romanbsd had some time and looked into this a little more; this is a bug in handlebars itself cause if the template is more than just the return of the safe string; it will return a regular JS string...

See http://jsfiddle.net/9D88g/28/ ; and check your JS console and you will see how it is just handlebars...

romanbsd commented 10 years ago

Are you going to open a ticket on the handlebars bug tracker or you want me to? btw, what did change in handlebars_assets that caused this bug to appear?

AlexRiedler commented 9 years ago

@romanbsd I updated the handlebars version which caused the error, this is a regression bug. I thought I told you to post on Handlebars (but maybe I did? I don't remember).