Add conversion to Laminar
mattisr opened this issue · 9 comments
Laminar's syntax is very similar to scala tags. It would be great to add support for Laminar.
The source code seems prepared for more translators.
Added initial support for Laminar. Let me know what you think.
Does Laminar allow setting JavaScript as value for event functions?
Eg: the following code
onclick='alert("clicked!");'
Gets converted to this in ScalaTags which is valid code.
onclick := """alert("clicked!");"""
In Laminar this is generated which does not compile.
onClick --> """alert("clicked!");"""
cannot be applied to (String)
onClick --> """alert("clicked!");""",
You should be able to do something like onClick --> (_ => js.eval("""alert("clicked!");"""))
in Laminar.
Yes that works, I also tried onClick --> (_ => js.Dynamic.global.eval("""console.log("Hello World")"""))
, but I do not know the differance.
For a 600 lines long html file I only got these compile errors:
<a tabindex="0"></a>
translates to a(tabIndex := "-1")
// error since tabIndex is an Int
<div targetform="xx"> </div>
translatets to div(targetform := "xx")
// Error because value targetform is missing
Both error types are easy to solve by hand, so a very helpful program, thanks!
You should be able to do something like onClick --> (_ => js.eval("""alert("clicked!");""")) in Laminar.
Done.
translates to a(tabIndex := "-1") // error since tabIndex is an Int
They should get converted to proper types in Scala now other than Boolean
because in the following tests all the checkboxes are rendered as checked. Incase some JavaScript is dependent on the actual value the converter will leave the value as is (checked := "blah!"
) which can be fixed manually at compile time if the actual value is unnecessary.
<input type="checkbox" checked />
<input type="checkbox" checked="true" />
<input type="checkbox" checked="blah!" />
All Boolean
attributes now get converted to true
by default. To disable this there is a checkbox Disable Boolean type conversion
.
Closed as resolved.