Skip to content

Commit

Permalink
HEEx Decoder - handle attr values with nil values
Browse files Browse the repository at this point in the history
This should close the issue BeaconCMS/beacon_live_admin#226
  • Loading branch information
leandrocp committed Sep 10, 2024
1 parent 7a57d44 commit d310076
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* [Media Library] Guard against invalid values for `:sort` option in `MediaLibrary.list_assets/2`
* [Content] Guard against invalid values for `:sort` option in `Content.list_layouts/2`
* [Content] Guard against invalid values for `:sort` option in `Content.list_pages/2`
* [HEEx Decoder] Handle attr values with `nil` values, for example the `defer` in script tags

## 0.1.0-rc.1 (2024-08-27)

Expand Down
4 changes: 4 additions & 0 deletions lib/beacon/template/heex/heex_decoder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ defmodule Beacon.Template.HEEx.HEExDecoder do
[name, "=", ?{, content, ?}]
end

defp reconstruct_attr({name, _, _}) do
[name]
end

defp decode_eex_block(ast) do
%{"type" => "eex_block", "content" => content, "children" => children} = Jason.decode!(ast)

Expand Down
7 changes: 7 additions & 0 deletions test/beacon/template/heex/heex_decoder_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,11 @@ defmodule Beacon.Template.HEEx.HEExDecoderTest do
test "live data assigns" do
assert_equal(~S|<%= @name %>|, %{name: "Beacon"})
end

test "script tag" do
assert_equal(~S"""
<script data-domain={MyAppWeb.Endpoint.config(:url)[:host]} defer src="/js/script.js">
</script>
""")
end
end

0 comments on commit d310076

Please sign in to comment.