emilioforrer / haml_coffee_assets

Haml Coffee templates in the Rails asset pipeline or as Sprockets engine.
https://rubygems.org/gems/haml_coffee_assets
MIT License
439 stars 142 forks source link

.hamlc is unexpectedly processed by JstProcessor #189

Open voducvu opened 2 weeks ago

voducvu commented 2 weeks ago

Problem The template function is unexpectedly generated into namespace window.JST['templates/]. When we access this template, it returns undefined.

(function() { this.JST || (this.JST = {}); this.JST["templates/activities/default_content"] = (function() { //unexpected wrapper
  if (window.JST == null) {
    window.JST = {};
  }

  window.JST['activities/default_content'] = function(context) {
    return (function() {
      var $o;
      $o = [];
      $o.push("<div class='video-outer'>\n  <div class='videoSmall'>\n    <div class='js-video-player'></div>\n  </div>\n</div>");
      return $o.join("\n").replace(/\s(?:id|class)=(['"])(\1)/mg, "");
    }).call(window.HAML.context(context));
  };
}).call(this);;}).call(this);

Findings The .hamlc is processed by JstProcessor unexpectedly. It should be handled by HamlCoffeeAssets::Transformer only.

    config.assets.configure do |env|
      if env.respond_to?(:register_transformer)
        env.register_mime_type 'text/hamlc', extensions: ['.hamlc', '.jst.hamlc']
        env.register_transformer 'text/hamlc', 'application/javascript', ::HamlCoffeeAssets::Transformer
        env.register_transformer 'text/hamlc', 'application/javascript+function', ::HamlCoffeeAssets::Transformer
      end

Suggestion We should separate the mimetype for .hamlc and .jst.haml

    config.assets.configure do |env|
      if env.respond_to?(:register_transformer)
        env.register_mime_type 'text/hamlc', extensions: ['.hamlc']
        env.register_mime_type 'text/jst+hamlc', extensions: ['.jst.hamlc']
        env.register_transformer 'text/hamlc', 'application/javascript', ::HamlCoffeeAssets::Transformer
        env.register_transformer 'text/jst+hamlc', 'application/javascript+function', ::HamlCoffeeAssets::Transformer
      end
mathieujobin commented 2 weeks ago

I'm sorry, I'm not sure anyone will have time to be looking at this problem in depth. if you do find a solution, please open a pull request.

thanks

voducvu commented 1 week ago

hi @mathieujobin, I opened a PR here https://github.com/emilioforrer/haml_coffee_assets/pull/190. Please help proceed to merge it when you have time. Thanks