Avoid duplicate work
This commit is contained in:
@ -5,6 +5,15 @@ defmodule Heroicons.Generator do
|
|||||||
|> Path.join("*.svg")
|
|> Path.join("*.svg")
|
||||||
|> Path.wildcard()
|
|> Path.wildcard()
|
||||||
|
|
||||||
|
require Phoenix.Component
|
||||||
|
if function_exported?(Phoenix.Component, :assigns_to_attributes, 2) do
|
||||||
|
Module.put_attribute(__CALLER__.module, :assign_mod, Phoenix.Component)
|
||||||
|
Module.put_attribute(__CALLER__.module, :assigns_to_attrs_mod, Phoenix.Component)
|
||||||
|
else
|
||||||
|
Module.put_attribute(__CALLER__.module, :assign_mod, Phoenix.LiveView)
|
||||||
|
Module.put_attribute(__CALLER__.module, :assigns_to_attrs_mod, Phoenix.LiveView.Helpers)
|
||||||
|
end
|
||||||
|
|
||||||
for path <- icon_paths do
|
for path <- icon_paths do
|
||||||
generate(path)
|
generate(path)
|
||||||
end
|
end
|
||||||
@ -43,16 +52,9 @@ defmodule Heroicons.Generator do
|
|||||||
@doc unquote(doc)
|
@doc unquote(doc)
|
||||||
def unquote(name)(assigns_or_opts \\ [])
|
def unquote(name)(assigns_or_opts \\ [])
|
||||||
|
|
||||||
|
|
||||||
if function_exported?(Phoenix.Component, :assigns_to_attributes, 2) do
|
|
||||||
@assigns_to_attrs_mod Phoenix.Component
|
|
||||||
else
|
|
||||||
@assigns_to_attrs_mod Phoenix.LiveView.Helpers
|
|
||||||
end
|
|
||||||
|
|
||||||
def unquote(name)(var!(assigns)) when is_map(var!(assigns)) do
|
def unquote(name)(var!(assigns)) when is_map(var!(assigns)) do
|
||||||
var!(attrs) = @assigns_to_attrs_mod.assigns_to_attributes(var!(assigns))
|
var!(attrs) = @assigns_to_attrs_mod.assigns_to_attributes(var!(assigns))
|
||||||
var!(assigns) = Phoenix.LiveView.assign(var!(assigns), :attrs, var!(attrs))
|
var!(assigns) = @assign_mod.assign(var!(assigns), :attrs, var!(attrs))
|
||||||
|
|
||||||
unquote(
|
unquote(
|
||||||
EEx.compile_string(head <> "{@attrs}" <> body,
|
EEx.compile_string(head <> "{@attrs}" <> body,
|
||||||
|
Reference in New Issue
Block a user