Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Have truncatewords/2 ignore tuples (e.g. timestamp) and truncatewords/3 ... #40

merged 2 commits into from

2 participants


...ignore atoms (e.g. null or undefined).


Hmm. Why is this necessary? Why are tuples being passed to truncatewords in the first place?


Both tuples and atoms are passed in cb_admin. I figured that people would use truncatewords as you have done yourself, so it'd be better to have truncatewords not choke on them.
The error given was really quite unheplful, which had me baffled for a bit...

From cb_admin/src/view/model/show.html:

        {% for attr_name, attr_val in val.attributes %}
        {% ifequal "id" attr_name %}
        <td><strong><a href="{% url action="show" record_id=attr_val %}">{{ attr_val }}</a></strong></td>
        {% else %}
        {% if "_time" in attr_name %}
        <td id="{{ }}-{{ attr_name }}">{{ attr_val|date:"N j, Y, P" }}</td>
        {% else %}
        <td id="{{ }}-{{ attr_name }}">{{ attr_val|truncatewords:8 }}</td>
        {% endif %}
        {% endifequal %}
        {% endfor %}

Note that the above code handles time, but only when the column is named *_time. I'm using timestamp_*.

One could argue that atoms should be converted to lists and truncated, but my reasoning is that it doesn't make sense to truncate atoms. Consider truncated versions of 'this_is_a_really_important_atom' and 'this_is_totally_nonimportant' :)


Ok. I'll update it accordingly. I'll have a look at cb_admin as well, when I have the time.

@evanmiller evanmiller merged commit 2f8504a into erlydtl:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 20, 2012
  1. @runejuhl

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

    runejuhl authored
    …/3 ignore atoms (e.g. null or undefined).
  2. @runejuhl
This page is out of date. Refresh to see the latest.
Showing with 2 additions and 0 deletions.
  1. +2 −0  src/erlydtl_filters.erl
2  src/erlydtl_filters.erl
@@ -1041,6 +1041,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) ->
truncatewords(_Input, 0, Acc) ->
Something went wrong with that request. Please try again.