Bladeren bron

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

tags/v0.0.13^2
jackyalcine 9 maanden geleden
bovenliggende
commit
76d173a139
Getekend door: me <yo@jacky.wtf> GPG sleutel-ID: 537A4F904B15268D
10 gewijzigde bestanden met toevoegingen van 55 en 15 verwijderingen
  1. +1
    -0
      .env.example
  2. +4
    -5
      .gitignore
  3. +1
    -0
      .lvimrc
  4. +2
    -2
      docker-compose.yml
  5. +0
    -1
      lib/template/decorator.ex
  6. +6
    -1
      lib/template/format.ex
  7. +2
    -2
      lib/web.ex
  8. +23
    -0
      test/unit/template/render_test.exs
  9. +2
    -2
      web/views/base_view.ex
  10. +14
    -2
      web/views/layout_view.ex

+ 1
- 0
.env.example Bestand weergeven

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

+ 4
- 5
.gitignore Bestand weergeven

@@ -4,11 +4,10 @@
.env
.envrc
.sobelow
/*.ez
/_build
/config/*.secret.exs
/db
/deps
*.ez
config/*.secret.exs
deps/*
_build/*
cover/
erl_crash.dump
node_modules


+ 1
- 0
.lvimrc Bestand weergeven

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


+ 2
- 2
docker-compose.yml Bestand weergeven

@@ -41,10 +41,10 @@ services:
MIX_ENV: dev
environment:
CANONICAL_URL: ${CANONICAL_URL}
ENV: dev
ENV: ${ENV}
GUARDIAN_SECRET_KEY: ${GUARDIAN_SECRET_KEY}
LOGGER_LEVEL: ${LOGGER_LEVEL}
MIX_ENV: dev
MIX_ENV: ${MIX_ENV}
OBJECT_STORAGE_ACCESS_KEY: ${OBJECT_STORAGE_ACCESS_KEY}
OBJECT_STORAGE_BUCKET: ${OBJECT_STORAGE_BUCKET}
OBJECT_STORAGE_HOST: ${OBJECT_STORAGE_HOST}


+ 0
- 1
lib/template/decorator.ex Bestand weergeven

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

defp system(theme: theme) do


+ 6
- 1
lib/template/format.ex Bestand weergeven

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

nil

{:error, _} = error ->


+ 2
- 2
lib/web.ex Bestand weergeven

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


+ 23
- 0
test/unit/template/render_test.exs Bestand weergeven

@@ -0,0 +1,23 @@
defmodule Koype.Template.RenderTest do
use Koype.Test.BaseCase, async: false
use Koype.DataCase
use Koype.Web.ConnCase
alias Koype.Template.Renderer, as: Subject

describe ".render_page/3" do
test "renders page cleanly" do
params = %{
"conn" => build_conn(),
"css_class_names" => "",
"template_name" => "home",
"template_view_module" => Koype.Web.PageView,
:view_module => Koype.Web.LayoutView,
:view_template => "_meta.html",
"current_path" => "",
"flash" => %{}
}

assert {:ok, _} = Subject.render_page("default", "home.html", params)
end
end
end

+ 2
- 2
web/views/base_view.ex Bestand weergeven

@@ -19,8 +19,8 @@
defmodule Koype.Web.BaseView do
def get_current_template(assigns)
def get_current_template(%{view_template: template}), do: template
def get_current_template(%{"view_template" => template}), do: template
def get_current_module(%{"view_module" => module}), do: module
def get_current_template(%{"template_name" => template}), do: template
def get_current_module(%{"template_view_module" => module}), do: module
def get_current_module(%{view_module: module}), do: module

def base_title() do


+ 14
- 2
web/views/layout_view.ex Bestand weergeven

@@ -27,12 +27,24 @@ defmodule Koype.Web.LayoutView do
template =
case get_current_template(assigns) do
"_meta.html" ->
conn = Map.take(assigns, ["conn", :conn]) |> Map.values() |> List.first()
conn.private[:phoenix_template]
conn =
Map.take(assigns, ["conn", :conn])
|> Map.values()
|> Enum.reject(&is_nil/1)
|> List.first()

if is_nil(conn) do
assigns["view_template"]
else
conn.private[:phoenix_template]
end

template_name ->
template_name
end
|> Apex.ap()

Apex.ap(assigns)

module_title = if function_exported?(module, :title, 2), do: module.title(template, assigns)



Laden…
Annuleren
Opslaan