Skip to content

Commit

Permalink
Merge pull request #96 from liveview-native/bc-fix-class-name-map-tru…
Browse files Browse the repository at this point in the history
…ncation

Fixes class map truncation
  • Loading branch information
bcardarella authored Dec 12, 2023
2 parents bf5d66d + e7dbf42 commit da58c7d
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions lib/live_view_native/templates.ex
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,30 @@ defmodule LiveViewNative.Templates do
module_name = generate_class_tree_module_name(template_module)
branches = get_class_tree_branches(requires)

try do
:ets.new(:live_view_native_class_maps, [:public, :named_table])
rescue
_ -> :already_defined
end

:ets.insert(:live_view_native_class_maps, {module_name, class_tree_map})

Macro.to_string(
quote location: :keep do
defmodule unquote(module_name) do
def class_tree(stylesheet_key),
do:
def class_tree(stylesheet_key) do
[_key, class_tree_map] = :ets.lookup(:live_view_native_class_maps, unquote(module_name))
%{
branches: unquote(branches),
contents: class_tree_map[stylesheet_key],
expanded_branches: [unquote(module_name)]
} ||
%{
branches: unquote(branches),
contents: unquote(class_tree_map)[stylesheet_key],
branches: [],
contents: %{},
expanded_branches: [unquote(module_name)]
} ||
%{
branches: [],
contents: %{},
expanded_branches: [unquote(module_name)]
}
}
end
end
end
)
Expand Down Expand Up @@ -160,7 +169,7 @@ defmodule LiveViewNative.Templates do

defp split_class_names([]), do: []
defp split_class_names([class_names | _tail]) do
String.split(class_names, " ")
String.split(class_names, " ", trim: true)
end

defp module_has_stylesheet?(module) do
Expand Down

0 comments on commit da58c7d

Please sign in to comment.