Files
phoenix-ausblick/lib/outlook_web/view_helpers.ex
2023-05-03 22:37:43 +02:00

31 lines
732 B
Elixir

defmodule OutlookWeb.ViewHelpers do
import Phoenix.HTML, only: [raw: 1]
@doc "Just sanitize tags"
def tidy_raw(html) when is_binary(html) do
html
|> Floki.parse_fragment!()
|> Floki.raw_html()
|> raw
end
def tidy_raw(whatever) do
whatever
end
# TODO: implement (and use) the following function
@doc "Strip <a> tags to prevent broken html (or 'breaking') from user input."
def strip_links(html) do
raise "Yet to be implemented!"
end
def elipsed_text(text, length) do
if String.length(text) < length do
text
else
part_length = (length - 3) / 2 |> trunc()
"#{String.slice(text, 0..part_length)}#{String.slice(text, -part_length..-1)}"
end
end
end