You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As a long time haml user i really like how haml makes the html very precise
Now javascript modules are supported by browsers, and rails 7 has the importmap support.
So we can drop packers, web or otherwise.
But JS module code and non module code don't mix well, and currently there is no support for writing module js in haml.
I read the issues and it seems a similar request was made 5 years ago, but i think things have changed to revisit the topic.
Then it was said modules is a fringe thing, that's not true anymore
And it was said that one can just use a script tag And while this is true, we would not need a the whole javascript filter if it were the whole story.
So, reading the code, i don't really see a way to get options into a filter on a case by case basis. In a way i think this would be nicest, if one could do :javascript{module: true}
But if that is too disruptive, i would suggest a :module filter, that is very similar to javascript filter, just adds the module
I can make a pr if the feature would be accepted. Probably will write the filter just for myself anyway.
The text was updated successfully, but these errors were encountered:
Need this myself and ended up quickly write up an initializer for it. Wasn't sure how to handle xhtml and didn't need it so left it as it was in the code. I was able to find the logic for adding filters in the codebase and just used that. I ended up just being a bit lazy and used javascriptm as the name. Not sure if :module would cause conflicts or something. Especially if I used "Module" as the actual filename, but seems that wasn't actually an issue once I saw how it was registered, but left it as is for now.
If someone wants to add tests and do a PR for this, go ahead.
# config/initializers/haml_js_modules.rb
# Add support for <script type="module"></script>
module Haml
class Filters
class JavascriptModule < Javascript
def compile(node)
case @format
when :xhtml
compile_xhtml(node)
else
compile_html(node)
end
end
private
def compile_html(node)
temple = [:multi]
temple << [:static, "<script type='module'>\n"]
compile_text!(temple, node, ' ')
temple << [:static, "\n</script>"]
temple
end
def compile_xhtml(node)
temple = [:multi]
temple << [:static, "<script type='text/javascript'>\n //<![CDATA[\n"]
compile_text!(temple, node, ' ')
temple << [:static, "\n //]]>\n</script>"]
temple
end
end
end
end
module Haml
class Filters
register :javascriptm, JavascriptModule
end
end
As a long time haml user i really like how haml makes the html very precise
Now javascript modules are supported by browsers, and rails 7 has the importmap support.
So we can drop packers, web or otherwise.
But JS module code and non module code don't mix well, and currently there is no support for writing module js in haml.
I read the issues and it seems a similar request was made 5 years ago, but i think things have changed to revisit the topic.
Then it was said modules is a fringe thing, that's not true anymore
And it was said that one can just use a script tag And while this is true, we would not need a the whole javascript filter if it were the whole story.
So, reading the code, i don't really see a way to get options into a filter on a case by case basis. In a way i think this would be nicest, if one could do
:javascript{module: true}
But if that is too disruptive, i would suggest a
:module
filter, that is very similar to javascript filter, just adds themodule
I can make a pr if the feature would be accepted. Probably will write the filter just for myself anyway.
The text was updated successfully, but these errors were encountered: