Преглед на файлове

Reorganize elixir internal directory

theenglishway (time) преди 2 години
родител
ревизия
2307585087
променени са 5 файла, в които са добавени 16 реда и са изтрити 8 реда
  1. 0 1
      .gitignore
  2. 2 0
      cv_gen/.gitignore
  3. 10 3
      cv_gen/lib/cv_gen.ex
  4. 4 4
      cv_gen/lib/watchdog.ex
  5. 0 0
      cv_gen/priv/data/cv.json

+ 0 - 1
.gitignore

@@ -1 +0,0 @@
-cv_gen/lib/templates/output.html

+ 2 - 0
cv_gen/.gitignore

@@ -24,3 +24,5 @@ cv_gen-*.tar
 
 # Temporary files, for example, from tests.
 /tmp/
+
+/priv/output/

+ 10 - 3
cv_gen/lib/cv_gen.ex

@@ -2,9 +2,9 @@ defmodule CvGen do
   @moduledoc """
   Documentation for `CvGen`.
   """
-  @template_file "lib/templates/cv.html.eex"
-  @data_file "lib/templates/cv.json"
-  @output_file "lib/templates/output.html"
+  @template_file "lib/templates/cv.html.heex"
+  @data_file "priv/data/cv.json"
+  @output_file "priv/output/cv.html"
 
   def generate do
     with raw_data <- File.read!(@data_file),
@@ -12,4 +12,11 @@ defmodule CvGen do
          res <- CvGenView.cv(assigns) |> Phoenix.HTML.Safe.to_iodata() |> List.to_string(),
          do: File.write!(@output_file, res)
   end
+
+  def paths(),
+    do: %{
+      template: @template_file,
+      data: @data_file,
+      output: @output_file
+    }
 end

+ 4 - 4
cv_gen/lib/watchdog.ex

@@ -3,6 +3,7 @@ defmodule CvGen.Watchdog do
   require Logger
 
   @name __MODULE__
+  @paths CvGen.paths()
 
   def start_link(_), do: GenServer.start(__MODULE__, [], name: @name)
 
@@ -14,8 +15,8 @@ defmodule CvGen.Watchdog do
   @impl true
   def handle_info(:timer_expired, state) do
     state =
-      with tpl_hash <- hash("lib/templates/cv.html.heex"),
-           json_hash <- hash("lib/templates/cv.json") do
+      with tpl_hash <- hash(@paths.template),
+           json_hash <- hash(@paths.data) do
         if tpl_hash != state.tpl_hash or json_hash != state.json_hash do
           Logger.info("Content has changed, reloading")
           CvGen.generate()
@@ -37,8 +38,7 @@ defmodule CvGen.Watchdog do
   def handle_call(:reload, _, _) do
     CvGen.generate()
 
-    {:reply, :ok,
-     %{tpl_hash: hash("lib/templates/cv.html.eex"), json_hash: hash("lib/templates/cv.json")},
+    {:reply, :ok, %{tpl_hash: hash(@paths.template), json_hash: hash(@paths.data)},
      {:continue, :trigger_timer}}
   end
 

cv_gen/lib/templates/cv.json → cv_gen/priv/data/cv.json