Multiverse-io / eextoheex

Automatic conversion of html.eex templates to heex
MIT License
37 stars 7 forks source link

added handling for new live_component-tags introduced in liveview 0.17 #4

Closed mavuio closed 2 years ago

mavuio commented 2 years ago

hi!

i needed to introduce the new live_component tags introduces in liveview 0.17 in all of my templates (.heex and .leex)

(renaming v16 .heex files to .leex and running eextoheex again on those worked fine for me)

so i decided to update your great tool to handle that as well.

it might break for liveview 0.16 templates, as these don't know about <.live_component yet, so you might want to add a switch for that in your CLI ?

addrummond commented 2 years ago

@mavuio Thanks for doing this! I may not get a chance to check for issues with 0.16 templates until January, but this is very much appreciated.

mavuio commented 2 years ago

thanks.

i pushed my latest changes as i noticed a bit of an inconsistency when using it.

i took your code for converting to the <.form component and left the conversion from snake to dash-case intact.

but when doing that, all params get then passed as dashed atoms (like "first-name": instead of first_name:) which broke all my existing live-components.

the ~H syntax proposes to use dash-case but does not convert from dash-case to snake_case for its parameters

its still the other way round for functions: passing e.g. :phx_event to form, link, or content_tag leads to "phx-event" in the markup but passing phx-event="foo" to a Phoenix.Component in ~H does not lead to the Component receiving phx_event: "foo" in their assigns, rather it gets "phx-event": "foo"

so i removed the snake to dash conversion for live_component tags now.

for form tags its ok, to pass dash-arguments, as this in line with the liveview-docs:

clipping-2021_12_23-10_10_10@2x

passing them as dash_case to <.form would work fine too, they end up dash-cased in the html anyway, and they are only needed in the final markup, not before AFAIK.

i might open an issue in liveview, proposing an auto-conversion from dash-cased arguments to Phoenix.Components to snake_case to be in line with the de-facto other-way-round conversion we always had.

mavuio commented 2 years ago

i posted that issue now:

https://github.com/phoenixframework/phoenix_live_view/issues/1812