Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.hamlc is unexpectedly processed by JstProcessor #189

Closed
voducvu opened this issue Jun 21, 2024 · 3 comments
Closed

.hamlc is unexpectedly processed by JstProcessor #189

voducvu opened this issue Jun 21, 2024 · 3 comments

Comments

@voducvu
Copy link
Contributor

voducvu commented Jun 21, 2024

Problem
The template function is unexpectedly generated into namespace window.JST['templates/<template_name>]. 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
@voducvu voducvu changed the title .hamlc is unexpectedly process by JstProcessor .hamlc is unexpectedly processed by JstProcessor Jun 21, 2024
@mathieujobin
Copy link
Collaborator

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 added a commit to voducvu/haml_coffee_assets that referenced this issue Jun 24, 2024
@voducvu
Copy link
Contributor Author

voducvu commented Jun 24, 2024

hi @mathieujobin, I opened a PR here #190. Please help proceed to merge it when you have time.
Thanks

@mathieujobin
Copy link
Collaborator

Thanks for the fix @voducvu

I merged #191 which appears equivalent, but please do let me know if you find that something is missing.

will release shortly in v1.25.0

voducvu added a commit to voducvu/haml_coffee_assets that referenced this issue Jul 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants