Permalink
Browse files

title/1 even more Django-y

  • Loading branch information...
1 parent f51468d commit fd4619f02967cd875c9f97be81803062adf67dae @runejuhl runejuhl committed Jan 31, 2013
Showing with 13 additions and 3 deletions.
  1. +7 −3 src/erlydtl_filters.erl
  2. +6 −0 tests/src/erlydtl_unittests.erl
View
@@ -797,7 +797,7 @@ timeuntil(Date,Comparison) ->
title(Input) when is_binary(Input) ->
title(binary_to_list(Input));
title(Input) when is_list(Input) ->
- title(Input, []).
+ title(lower(Input), []).
%% @doc Truncates a string after a certain number of characters.
truncatechars(_Input, Max) when Max =< 0 ->
@@ -1029,8 +1029,12 @@ title([], Acc) ->
lists:reverse(Acc);
title([Char | Rest], [] = Acc) when Char >= $a, Char =< $z ->
title(Rest, [Char + ($A - $a) | Acc]);
-title([Char | Rest], [Sep|_] = Acc) when Char >= $a, Char =< $z, not (Sep >= $a andalso Sep =< $z),
- not (Sep >= $A andalso Sep =< $Z) ->
+title([Char | Rest], [Sep|[Sep2|_Other]] = Acc)
+ when Char >= $a, Char =< $z,
+ not (Sep >= $a andalso Sep =< $z),
+ not (Sep >= $A andalso Sep =< $Z),
+ not (Sep >= $0 andalso Sep =< $9),
+ not (Sep =:= $' andalso (Sep2 >= $a andalso Sep2 =< $z)) ->
title(Rest, [Char + ($A - $a) | Acc]);
title([Char | Rest], Acc) ->
title(Rest, [Char | Acc]).
@@ -826,6 +826,12 @@ tests() ->
{"|title (wacky separators)",
<<"{{ \"my-title!case\"|title }}">>, [],
<<"My-Title!Case">>},
+ {"|title (numbers)",
+ <<"{{ \"my-title123CaSe\"|title }}">>, [],
+ <<"My-Title123case">>},
+ {"|title (Irish names)",
+ <<"{{ \"who's o'malley?\"|title }}">>, [],
+ <<"Who's O'Malley?">>},
{"|truncatechars:0",
<<"{{ var1|truncatechars:0 }}">>, [{var1, "Empty Me"}],
<<"">>},

0 comments on commit fd4619f

Please sign in to comment.