diff options
author | rinpatch <rinpatch@sdf.org> | 2019-01-15 23:25:28 +0300 |
---|---|---|
committer | rinpatch <rinpatch@sdf.org> | 2019-01-15 23:25:28 +0300 |
commit | 9aa69e12b87a892d33d1bf4f0d556752391b465a (patch) | |
tree | d81215df097f64c4cd45f4337c955fe9647414f6 /lib/pleroma/formatter.ex | |
parent | 2e630bea0da6452d3342a335da3ca642dc61c1b3 (diff) | |
download | pleroma-9aa69e12b87a892d33d1bf4f0d556752391b465a.tar.gz |
Add behaviours to TwitterCard, remove some dumb stuff in Formatter.truncate
Diffstat (limited to 'lib/pleroma/formatter.ex')
-rw-r--r-- | lib/pleroma/formatter.ex | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index 49f7075e6..63e0acb21 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -184,21 +184,12 @@ defmodule Pleroma.Formatter do end) end - def truncate(text, opts \\ []) do - max_length = opts[:max_length] || 200 - omission = opts[:omission] || "..." - - cond do - not String.valid?(text) -> - text - - String.length(text) < max_length -> - text - - true -> - length_with_omission = max_length - String.length(omission) - - "#{String.slice(text, 0, length_with_omission)}#{omission}" + def truncate(text, max_length \\ 200, omission \\ "...") do + if String.length(text) < max_length do + text + else + length_with_omission = max_length - String.length(omission) + String.slice(text, 0, length_with_omission) <> omission end end end |