cv_gen.ex 630 B

1234567891011121314151617181920212223
  1. defmodule CvGen do
  2. @moduledoc """
  3. Documentation for `CvGen`.
  4. """
  5. @template_file "lib/templates/cv.html.heex"
  6. @data_file "priv/data/cv.json"
  7. @output_file "priv/output/cv.html"
  8. def generate do
  9. with raw_data <- File.read!(@data_file),
  10. {:ok, assigns} <-
  11. Jason.decode(raw_data, keys: &(&1 |> Macro.underscore() |> String.to_atom())),
  12. res <- CvGenView.cv(assigns) |> Phoenix.HTML.Safe.to_iodata() |> List.to_string(),
  13. do: File.write!(@output_file, res)
  14. end
  15. def paths(),
  16. do: %{
  17. template: @template_file,
  18. data: @data_file,
  19. output: @output_file
  20. }
  21. end