freedive/lib/liliform/bulma_helper.ex

35 lines
820 B
Elixir

defmodule Liliform.BulmaHelper do
def set_bulma_classes(assigns) do
rest_classes =
assigns.rest
|> Map.keys()
|> Enum.map(&to_string/1)
is_bulma_classes =
rest_classes
|> Enum.filter(&String.starts_with?(&1, "is-"))
has_bulma_classes =
rest_classes
|> Enum.filter(&String.starts_with?(&1, "has-"))
bulma_classes =
is_bulma_classes ++ has_bulma_classes
rest =
assigns.rest
|> Map.reject(fn {k, _} -> String.starts_with?(to_string(k), "is-") end)
|> Map.reject(fn {k, _} -> String.starts_with?(to_string(k), "has-") end)
assigns = Map.put(assigns, :rest, rest)
assigns =
Map.put(
assigns,
:class,
Map.get(assigns, :class, "") <> Enum.join(bulma_classes, " ")
)
assigns
end
end