From c201f7ebe9c1840ba85f6d87f13d35fcb47ab2b8 Mon Sep 17 00:00:00 2001 From: Sloane Perrault Date: Wed, 21 Sep 2022 09:19:53 -0400 Subject: [PATCH] fix: no nested modules, keep import --- .../mix/tasks/advent_of_code.gen.solution.ex | 46 +++++++++++++------ 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/2021/lib/mix/tasks/advent_of_code.gen.solution.ex b/2021/lib/mix/tasks/advent_of_code.gen.solution.ex index d61cb68..8b9151a 100644 --- a/2021/lib/mix/tasks/advent_of_code.gen.solution.ex +++ b/2021/lib/mix/tasks/advent_of_code.gen.solution.ex @@ -23,25 +23,19 @@ defmodule Mix.Tasks.AdventOfCode.Gen.Solution do case OptionParser.parse!(args, switches: @switches) do {_, [day]} -> day_module = day_module(day) - day_contents = day_template(mod: day_module) |> Code.format_string!() + day_contents = day_template(mod: day_module, day: day) |> Code.format_string!() day_path = Path.join("lib", Macro.underscore(day_module)) day_tests_path = Path.join("test", Macro.underscore(day_module)) day_file = "#{day_path}.ex" - create_directory(day_path) - create_directory(day_tests_path) create_file(day_file, day_contents) + create_directory(day_tests_path) + for part <- 1..2 do part = to_string(part) part_module = part_module(day, part) - part_contents = - part_template(mod: part_module, day_mod: day_module) |> Code.format_string!() - - part_file = Path.join("lib", "#{Macro.underscore(part_module)}.ex") - create_file(part_file, part_contents) - part_test_module = Module.concat(day_module, Macro.camelize("Part#{part}Test")) part_test_contents = @@ -59,25 +53,47 @@ defmodule Mix.Tasks.AdventOfCode.Gen.Solution do end end - embed_template(:day, ~S""" + embed_template(:day, ~S[ defmodule <%= inspect(@mod) %> do + @moduledoc """ + Day <%= @day %> + """ + end - """) - embed_template(:part, ~S""" - defmodule <%= inspect(@mod) %> do + defmodule <%= inspect(@mod) %>.Part1 do + @moduledoc """ + Day <%= @day %>, Part 1 + """ + alias AdventOfCode.PuzzleSolver use PuzzleSolver - import <%= inspect(@day_mod) %>, warn: false + import <%= inspect(@mod) %>, warn: false @impl PuzzleSolver def solve(_input_stream) do :ok |> to_string() end end - """) + + defmodule <%= inspect(@mod) %>.Part2 do + @moduledoc """ + Day <%= @day %>, Part 2 + """ + + alias AdventOfCode.PuzzleSolver + use PuzzleSolver + + import <%= inspect(@mod) %>, warn: false + + @impl PuzzleSolver + def solve(_input_stream) do + :ok |> to_string() + end + end + ]) embed_template(:part_test, ~S[ defmodule <%= inspect(@test_mod) %> do