Переглянути джерело

fix(page): More visible output about parsing.

* Fix up template for photo rendering
* Show  more info on failures in rendering.
tags/v0.0.16^2
jackyalcine 6 місяці тому
джерело
коміт
b39a651d7e
Підписано: me <yo@jacky.wtf> Ідентифікатор GPG ключа: 537A4F904B15268D
8 змінених файлів з 93 додано та 11 видалено
  1. +1
    -1
      .lvimrc
  2. +11
    -4
      lib/page/parser.ex
  3. +8
    -1
      lib/post.ex
  4. +3
    -0
      lib/template/render.ex
  5. +1
    -0
      priv/themes/default/tmpl/entry/type/media/photo.html.liquid
  6. +59
    -0
      test/integration/controllers/indie/micropub_controller_test.exs
  7. +1
    -1
      test/integration/template_test.exs
  8. +9
    -4
      web/controllers/indie/micropub_controller.ex

+ 1
- 1
.lvimrc Переглянути файл

@@ -8,7 +8,7 @@ if exists(':DirenvExport')
endif

let s:command_prefix = 'docker-compose run ' .
\ '-e CANONICAL_URL="http://koype_vim_test" '.
\ '-e CANONICAL_URL="http://koype_vim_test:50505" '.
\ '-e MIX_ENV="test" ' .
\ '-e PORT=50505 ' .
\ '-e DOC=1 ' .


+ 11
- 4
lib/page/parser.ex Переглянути файл

@@ -88,15 +88,22 @@ defmodule Koype.Page.Parser do
@doc "Walk through all available parsers."
def resolve(url) do
case do_utilize_preferred_parser(url) do
{:ok, _} = result -> result
_ -> do_run_gambit_of_parsers(url)
{:ok, _} = result ->
result

_ ->
do_run_gambit_of_parsers(url)
end
end

def do_utilize_preferred_parser(url) do
case preferred_parser_for_url(url) do
{:ok, nil} -> {:error, :no_preferred_parser}
{:ok, parser} -> do_run_parser(parser, url)
{:ok, nil} ->
{:error, :no_preferred_parser}

{:ok, parser} ->
Logger.info("Using preferred parser.", url: url, parser: parser)
do_run_parser(parser, url)
end
end



+ 8
- 1
lib/post.ex Переглянути файл

@@ -148,7 +148,14 @@ defmodule Koype.Post do
cond do
Map.has_key?(response_props, "name") ->
name = Map.get(response_props, "name") |> List.wrap() |> List.first()
exact_name = if is_binary(name) do name else name[:text] end

exact_name =
if is_binary(name) do
name
else
name[:text]
end

"'" <> String.trim(exact_name) <> "'"

Map.has_key?(response_props, "author") ->


+ 3
- 0
lib/template/render.ex Переглянути файл

@@ -118,6 +118,9 @@ defmodule Koype.Template.Renderer do
rescue
e in Liquid.SyntaxError ->
{:error, error: :fetch_template_failed, reason: e, path: theme_file_path}

e ->
{:error, :error, :unexpected_error, reason: e, path: theme_file_path}
end

{:error, err} ->


+ 1
- 0
priv/themes/default/tmpl/entry/type/media/photo.html.liquid Переглянути файл

@@ -3,6 +3,7 @@
{% unless photo_count == 1 and video_count == 1 %}
<div class="flex flex-row flex-wrap justify-between items-center mv2 w-auto mw7 center">
{% for photo in entry.json.photo %}
{% if forloop.first == true %}
{% assign img_class = "w-100 self-top" %}
{% else %}
{% assign img_class = "w-30" %}


+ 59
- 0
test/integration/controllers/indie/micropub_controller_test.exs Переглянути файл

@@ -2,6 +2,7 @@ defmodule Koype.Web.Indie.MicropubControllerTest do
use Koype.Test.BaseCase, async: false
use Koype.Web.ConnCase
use Koype.DataCase
alias Koype.Repo.Entry, as: Model
import Koype.Factory
import Mock
import Double
@@ -106,6 +107,64 @@ defmodule Koype.Web.Indie.MicropubControllerTest do
assert conn |> get_resp_header("location") |> List.first() =~ "/post/"
end

test "201 creates a new reply using JSON" do
entry = insert(:entry, visibility: "public")
entry_json = build(:entry_json)
Model.json_persist(entry, entry_json)
entry_uri = Model.get_uri(entry)

conn =
build_conn()
|> indie_sign_in_conn(@client_id, ~w(create))
|> put_req_header("content-type", "application/json")
|> post(@route, %{
"type" => "entry",
"properties" => %{
"in-reply-to" => [entry_uri],
"content" => Faker.Lorem.paragraph()
}
})
|> doc(
description: "Creates a new entry with JSON that replies to a post",
operation_id: "micropub_json_reply"
)

assert text_response(conn, :created)
assert conn |> get_resp_header("location") |> List.first() =~ "/post/"
end

test "201 creates a new reply to a phtoo post using JSON" do
entry = insert(:entry, visibility: "public", type: "photo")

{:ok, entry_json} =
build(:entry_json)
|> with_html_content
|> with_post_type(:single_photo)
|> IndieWeb.Micropub.Entry.process_properties()

{:ok, _} = Koype.Repo.Entry.json_persist(entry, entry_json)
entry_url = Koype.Repo.Entry.get_uri(entry)

conn =
build_conn()
|> indie_sign_in_conn(@client_id, ~w(create))
|> put_req_header("content-type", "application/json")
|> post(@route, %{
"type" => "entry",
"properties" => %{
"in-reply-to" => [entry_url],
"content" => Faker.Lorem.paragraph()
}
})
|> doc(
description: "Creates a new entry with JSON that replies to a post",
operation_id: "micropub_json_reply"
)

assert text_response(conn, :created)
assert conn |> get_resp_header("location") |> List.first() =~ "/post/"
end

test "201 creates a new entry json with emoji" do
conn =
build_conn()


+ 1
- 1
test/integration/template_test.exs Переглянути файл

@@ -194,7 +194,7 @@ defmodule Koype.Integration.TemplateTest do
:ok
)

Apex.ap [:html, html]
Apex.ap([:html, html])

assert {"x-koype-theme", unquote(template_name)} in resp.resp_headers
assert mf2 = Microformats2.parse(html, entry_url)


+ 9
- 4
web/controllers/indie/micropub_controller.ex Переглянути файл

@@ -78,13 +78,20 @@ defmodule Koype.Web.Indie.MicropubController do
|> text("")

[{:error, error}, module] ->
Logger.error("Failed to upload file.", filename: file.filename, error: inspect(error), module: module)
Logger.error("Failed to upload file.",
filename: file.filename,
error: inspect(error),
module: module
)

conn
|> Explode.bad_request("Could not upload provided file.")

{:error, :invalid_file_type} ->
Logger.error("Failed to handle file upload.", filename: file.filename, content_type: content_type)
Logger.error("Failed to handle file upload.",
filename: file.filename,
content_type: content_type
)

conn
|> Explode.bad_request("Could not upload invalid file of #{content_type}.")
@@ -156,5 +163,3 @@ defmodule Koype.Web.Indie.MicropubController do
end)
end
end



Завантаження…
Відмінити
Зберегти