diff --git a/lib/mix/tasks/lvn.gen.ex b/lib/mix/tasks/lvn.gen.ex index c8311b9..a065fcf 100644 --- a/lib/mix/tasks/lvn.gen.ex +++ b/lib/mix/tasks/lvn.gen.ex @@ -20,6 +20,7 @@ defmodule Mix.Tasks.Lvn.Gen do ## Options * `--no-live-form` - don't include `LiveViewNative.LiveForm` content in the `Native` module + * `--no-gettext` - don't include Gettext support """ @impl true @@ -46,7 +47,8 @@ defmodule Mix.Tasks.Lvn.Gen do def switches, do: [ context_app: :string, web: :string, - live_form: :boolean + live_form: :boolean, + gettext: :boolean ] @doc false @@ -57,6 +59,7 @@ defmodule Mix.Tasks.Lvn.Gen do --no-live-form --context-app + --no-gettext --web """) end @@ -82,6 +85,9 @@ defmodule Mix.Tasks.Lvn.Gen do live_form? = Keyword.get(context.opts, :live_form, true) && Enum.member?(apps, :live_view_native_live_form) + gettext? = + Keyword.get(context.opts, :gettext, true) && Enum.member?(apps, :gettext) + binding = [ context: context, plugins: plugins, @@ -89,7 +95,7 @@ defmodule Mix.Tasks.Lvn.Gen do last?: &last?/2, assigns: %{ live_form?: live_form?, - gettext: true, + gettext: gettext?, formats: formats(), layouts: layouts(context.web_module) } diff --git a/lib/mix/tasks/lvn.setup.gen.ex b/lib/mix/tasks/lvn.setup.gen.ex index e8b528e..280138d 100644 --- a/lib/mix/tasks/lvn.setup.gen.ex +++ b/lib/mix/tasks/lvn.setup.gen.ex @@ -3,7 +3,7 @@ defmodule Mix.Tasks.Lvn.Setup.Gen do alias Mix.LiveViewNative.Context - @shortdoc "Configure LiveView Native within a Phoenix LiveView application" + @shortdoc "Run LiveView Native setup generators within a Phoenix LiveView application" @moduledoc """ #{@shortdoc} @@ -12,6 +12,10 @@ defmodule Mix.Tasks.Lvn.Setup.Gen do $ mix lvn.setup.config + ## Options + + * `--no-gettext` - don't include Gettext support + """ @impl true @@ -56,20 +60,29 @@ defmodule Mix.Tasks.Lvn.Setup.Gen do end) end - def generators(_context) do + def generators(context) do plugins = Mix.LiveViewNative.plugins() |> Map.keys() + apps = Mix.Project.deps_apps() + + gen_args = + (Keyword.get(context.opts, :gettext, true) && Enum.member?(apps, :gettext)) + |> if do + [] + else + ["--no-gettext"] + end + layout_tasks = Enum.map(plugins, &({"lvn.gen.layout", [&1]})) - [{"lvn.gen", []}] ++ layout_tasks + [{"lvn.gen", gen_args}] ++ layout_tasks end @doc false def switches, do: [ context_app: :string, web: :string, - stylesheet: :boolean, - live_form: :boolean + gettext: :boolean ] @doc false @@ -80,8 +93,7 @@ defmodule Mix.Tasks.Lvn.Setup.Gen do --context-app --web - --no-stylesheet - --no-live-form + --no-gettext """) end end diff --git a/mix.exs b/mix.exs index 61e7124..fe6cf4c 100644 --- a/mix.exs +++ b/mix.exs @@ -36,6 +36,7 @@ defmodule LiveViewNative.MixProject do {:phoenix_template, "~> 1.0.4"}, {:phoenix_html, "~> 3.3 or ~> 4.0 or ~> 4.1"}, {:floki, ">= 0.30.0", only: :test}, + {:gettext, "~> 0.24", only: :test}, {:plug, "~> 1.15"}, {:jason, "~> 1.2"}, {:plug_cowboy, "~> 2.5"}, diff --git a/mix.lock b/mix.lock index 2f99ff9..9412406 100644 --- a/mix.lock +++ b/mix.lock @@ -5,8 +5,10 @@ "cowlib": {:hex, :cowlib, "2.13.0", "db8f7505d8332d98ef50a3ef34b34c1afddec7506e4ee4dd4a3a266285d282ca", [:make, :rebar3], [], "hexpm", "e1e1284dc3fc030a64b1ad0d8382ae7e99da46c3246b815318a4b848873800a4"}, "earmark_parser": {:hex, :earmark_parser, "1.4.40", "f3534689f6b58f48aa3a9ac850d4f05832654fe257bf0549c08cc290035f70d5", [:mix], [], "hexpm", "cdb34f35892a45325bad21735fadb88033bcb7c4c296a999bde769783f53e46a"}, "ex_doc": {:hex, :ex_doc, "0.34.2", "13eedf3844ccdce25cfd837b99bea9ad92c4e511233199440488d217c92571e8", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "5ce5f16b41208a50106afed3de6a2ed34f4acfd65715b82a0b84b49d995f95c1"}, + "expo": {:hex, :expo, "0.5.2", "beba786aab8e3c5431813d7a44b828e7b922bfa431d6bfbada0904535342efe2", [:mix], [], "hexpm", "8c9bfa06ca017c9cb4020fabe980bc7fdb1aaec059fd004c2ab3bff03b1c599c"}, "file_system": {:hex, :file_system, "1.0.0", "b689cc7dcee665f774de94b5a832e578bd7963c8e637ef940cd44327db7de2cd", [:mix], [], "hexpm", "6752092d66aec5a10e662aefeed8ddb9531d79db0bc145bb8c40325ca1d8536d"}, "floki": {:hex, :floki, "0.36.2", "a7da0193538c93f937714a6704369711998a51a6164a222d710ebd54020aa7a3", [:mix], [], "hexpm", "a8766c0bc92f074e5cb36c4f9961982eda84c5d2b8e979ca67f5c268ec8ed580"}, + "gettext": {:hex, :gettext, "0.24.0", "6f4d90ac5f3111673cbefc4ebee96fe5f37a114861ab8c7b7d5b30a1108ce6d8", [:mix], [{:expo, "~> 0.5.1", [hex: :expo, repo: "hexpm", optional: false]}], "hexpm", "bdf75cdfcbe9e4622dd18e034b227d77dd17f0f133853a1c73b97b3d6c770e8b"}, "glob_ex": {:hex, :glob_ex, "0.1.7", "eae6b6377147fb712ac45b360e6dbba00346689a87f996672fe07e97d70597b1", [:mix], [], "hexpm", "decc1c21c0c73df3c9c994412716345c1692477b9470e337f628a7e08da0da6a"}, "jason": {:hex, :jason, "1.4.3", "d3f984eeb96fe53b85d20e0b049f03e57d075b5acda3ac8d465c969a2536c17b", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "9a90e868927f7c777689baa16d86f4d0e086d968db5c05d917ccff6d443e58a3"}, "live_view_native_test": {:git, "https://github.com/liveview-native/live_view_native_test.git", "539ae931fa3936f3ee2f73ffa11f7100fe6554db", [branch: "main"]}, diff --git a/test/mix/tasks/lvn.gen_test.exs b/test/mix/tasks/lvn.gen_test.exs index e8885fe..b12b193 100644 --- a/test/mix/tasks/lvn.gen_test.exs +++ b/test/mix/tasks/lvn.gen_test.exs @@ -53,4 +53,26 @@ defmodule Mix.Tasks.Lvn.GenTest do end end end + + describe "Gettext support" do + test "is available by default", config do + in_tmp_live_project config.test, fn -> + Gen.run([]) + + assert_file "lib/live_view_native_native.ex", fn file -> + assert file =~ "Gettext" + end + end + end + + test "can be turned off via a switch", config do + in_tmp_live_project config.test, fn -> + Gen.run(["--no-gettext"]) + + assert_file "lib/live_view_native_native.ex", fn file -> + refute file =~ "Gettext" + end + end + end + end end diff --git a/test/mix/tasks/lvn.setup_test.exs b/test/mix/tasks/lvn.setup_test.exs index 4148def..c66df7e 100644 --- a/test/mix/tasks/lvn.setup_test.exs +++ b/test/mix/tasks/lvn.setup_test.exs @@ -403,4 +403,26 @@ defmodule Mix.Tasks.Lvn.SetupTest do """ end end + + describe "Gettext support" do + test "is available by default", config do + in_tmp_live_project config.test, fn -> + Gen.run([]) + + assert_file "lib/live_view_native_native.ex", fn file -> + assert file =~ "Gettext" + end + end + end + + test "can be turned off via a switch", config do + in_tmp_live_project config.test, fn -> + Gen.run(["--no-gettext"]) + + assert_file "lib/live_view_native_native.ex", fn file -> + refute file =~ "Gettext" + end + end + end + end end