Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Have truncatewords/2 ignore tuples (e.g. timestamp) and truncatewords…

…/3 ignore atoms (e.g. null or undefined).
  • Loading branch information...
commit 31a5e46548bf72e4a295d84acdf2812b2b1a1dcd 1 parent 8552440
@runejuhl runejuhl authored
Showing with 5 additions and 0 deletions.
  1. +5 −0 src/erlydtl_filters.erl
View
5 src/erlydtl_filters.erl
@@ -808,6 +808,9 @@ truncatechars(Input, Max) ->
truncatechars(Input, Max, []).
%% @doc Truncates a string after a certain number of words.
+%% Do not truncate tuples, e.g. a timestamp ({{Y,M,D},{H,Mm,S}}).
+truncatewords(Input, _) when is_tuple(Input) ->
+ Input;
truncatewords(_Input, Max) when Max =< 0 ->
"";
truncatewords(Input, Max) when is_binary(Input) ->
@@ -1041,6 +1044,8 @@ truncatechars(_Input, 0, Acc) ->
truncatechars([C|Rest], CharsLeft, Acc) ->
truncatechars(Rest, CharsLeft - 1, [C|Acc]).
+truncatewords(Value, _WordsLeft, _Acc) when is_atom(Value) ->
+ Value;
truncatewords([], _WordsLeft, Acc) ->
lists:reverse(Acc);
truncatewords(_Input, 0, Acc) ->
Please sign in to comment.
Something went wrong with that request. Please try again.