Browse Source

fix(layout/view): Update issues with view.

jackyalcine 6 months ago
parent
commit
76d173a139
Signed by: Jacky Alciné <yo@jacky.wtf> GPG Key ID: 537A4F904B15268D

+ 1
- 0
.env.example View File

@@ -17,3 +17,4 @@ SESSION_SIGNING_SALT=ee8f193b0060c10d680a70250f8b5cb2c99af0c40e2503659e2cb7d397a
17 17
 TEST_HOST=koype_test
18 18
 TEST_PORT=5001
19 19
 UID=1000
20
+MIX_ENV=dev

+ 4
- 5
.gitignore View File

@@ -4,11 +4,10 @@
4 4
 .env
5 5
 .envrc
6 6
 .sobelow
7
-/*.ez
8
-/_build
9
-/config/*.secret.exs
10
-/db
11
-/deps
7
+*.ez
8
+config/*.secret.exs
9
+deps/*
10
+_build/*
12 11
 cover/
13 12
 erl_crash.dump
14 13
 node_modules

+ 1
- 0
.lvimrc View File

@@ -10,6 +10,7 @@ endif
10 10
 let s:command_prefix = 'docker-compose run ' .
11 11
       \ '-e CANONICAL_URL="http://koype_vim_test" '.
12 12
       \ '-e MIX_ENV="test" ' .
13
+      \ '-e PORT=50505 ' .
13 14
       \ '-e DOC=1 ' .
14 15
       \ '-e OBJECT_STORAGE_BUCKET="koype-test" '.
15 16
       \ '-e TEST_HOST="http://koype_vim_test" ' .

+ 2
- 2
docker-compose.yml View File

@@ -41,10 +41,10 @@ services:
41 41
         MIX_ENV: dev
42 42
     environment:
43 43
       CANONICAL_URL: ${CANONICAL_URL}
44
-      ENV: dev
44
+      ENV: ${ENV}
45 45
       GUARDIAN_SECRET_KEY: ${GUARDIAN_SECRET_KEY}
46 46
       LOGGER_LEVEL: ${LOGGER_LEVEL}
47
-      MIX_ENV: dev
47
+      MIX_ENV: ${MIX_ENV}
48 48
       OBJECT_STORAGE_ACCESS_KEY: ${OBJECT_STORAGE_ACCESS_KEY}
49 49
       OBJECT_STORAGE_BUCKET: ${OBJECT_STORAGE_BUCKET}
50 50
       OBJECT_STORAGE_HOST: ${OBJECT_STORAGE_HOST}

+ 0
- 1
lib/template/decorator.ex View File

@@ -29,7 +29,6 @@ defmodule Koype.Template.Decorator do
29 29
       "auth" => auth(conn),
30 30
       "koype" => system(theme: theme)
31 31
     })
32
-    |> Map.delete("conn")
33 32
   end
34 33
 
35 34
   defp system(theme: theme) do

+ 6
- 1
lib/template/format.ex View File

@@ -111,7 +111,12 @@ defimpl Koype.Template.Formatter, for: Koype.Repo.Entry do
111 111
       |> Koype.Template.Formatter.format()
112 112
       |> Map.new()
113 113
     else
114
-      {:error, [type: :network_error, code: _]} = error ->
114
+      {:error, [type: :network_error, code: _]} ->
115
+        Logger.warn(
116
+          "Failed to convert entry to template object due to network problems.",
117
+          entry_id: entry.id
118
+        )
119
+
115 120
         nil
116 121
 
117 122
       {:error, _} = error ->

+ 2
- 2
lib/web.ex View File

@@ -37,8 +37,8 @@ defmodule Koype.Web do
37 37
         params =
38 38
           Map.merge(assigns, %{
39 39
             "css_class_names" => class_names,
40
-            "view_template" => page_name,
41
-            "view_module" => conn.private[:phoenix_view],
40
+            "template_name" => page_name,
41
+            "template_view_module" => conn.private[:phoenix_view],
42 42
             "current_path" => Phoenix.Controller.current_path(conn),
43 43
             "conn" => conn,
44 44
             "flash" =>

+ 23
- 0
test/unit/template/render_test.exs View File

@@ -0,0 +1,23 @@
1
+defmodule Koype.Template.RenderTest do
2
+  use Koype.Test.BaseCase, async: false
3
+  use Koype.DataCase
4
+  use Koype.Web.ConnCase
5
+  alias Koype.Template.Renderer, as: Subject
6
+
7
+  describe ".render_page/3" do
8
+    test "renders page cleanly" do
9
+      params = %{
10
+        "conn" => build_conn(),
11
+        "css_class_names" => "",
12
+        "template_name" => "home",
13
+        "template_view_module" => Koype.Web.PageView,
14
+        :view_module => Koype.Web.LayoutView,
15
+        :view_template => "_meta.html",
16
+        "current_path" => "",
17
+        "flash" => %{}
18
+      }
19
+
20
+      assert {:ok, _} = Subject.render_page("default", "home.html", params)
21
+    end
22
+  end
23
+end

+ 2
- 2
web/views/base_view.ex View File

@@ -19,8 +19,8 @@
19 19
 defmodule Koype.Web.BaseView do
20 20
   def get_current_template(assigns)
21 21
   def get_current_template(%{view_template: template}), do: template
22
-  def get_current_template(%{"view_template" => template}), do: template
23
-  def get_current_module(%{"view_module" => module}), do: module
22
+  def get_current_template(%{"template_name" => template}), do: template
23
+  def get_current_module(%{"template_view_module" => module}), do: module
24 24
   def get_current_module(%{view_module: module}), do: module
25 25
 
26 26
   def base_title() do

+ 14
- 2
web/views/layout_view.ex View File

@@ -27,12 +27,24 @@ defmodule Koype.Web.LayoutView do
27 27
     template =
28 28
       case get_current_template(assigns) do
29 29
         "_meta.html" ->
30
-          conn = Map.take(assigns, ["conn", :conn]) |> Map.values() |> List.first()
31
-          conn.private[:phoenix_template]
30
+          conn =
31
+            Map.take(assigns, ["conn", :conn])
32
+            |> Map.values()
33
+            |> Enum.reject(&is_nil/1)
34
+            |> List.first()
35
+
36
+          if is_nil(conn) do
37
+            assigns["view_template"]
38
+          else
39
+            conn.private[:phoenix_template]
40
+          end
32 41
 
33 42
         template_name ->
34 43
           template_name
35 44
       end
45
+      |> Apex.ap()
46
+
47
+    Apex.ap(assigns)
36 48
 
37 49
     module_title = if function_exported?(module, :title, 2), do: module.title(template, assigns)
38 50
 

Loading…
Cancel
Save