diff --git a/lib/mix/tasks/shadix.gen.registry.ex b/lib/mix/tasks/shadix.gen.registry.ex index 7bc1b8a..0c6bb25 100644 --- a/lib/mix/tasks/shadix.gen.registry.ex +++ b/lib/mix/tasks/shadix.gen.registry.ex @@ -88,15 +88,28 @@ defmodule Mix.Tasks.Shadix.Gen.Registry do "hooks" => hooks } - if String.contains?(content, @marker) do - base - |> Map.put("default_style", "nova") - |> Map.put("styles", styles_for(name)) - else - base + case marker_count(content) do + 0 -> + base + + 1 -> + base + |> Map.put("default_style", "nova") + |> Map.put("styles", styles_for(name)) + + n -> + Mix.raise( + "Component #{name} contains the colocated-css marker #{n} times; it must appear " <> + "exactly once (the first node of the template). Remove other occurrences " <> + "(e.g. from the @moduledoc)." + ) end end + defp marker_count(content) do + content |> String.split(@marker) |> length() |> Kernel.-(1) + end + # Reads `priv/styles/