[erlang-questions] How do I reformat and output HTML strings as iolists in a convenient way?

Björn-Egil Dahlberg wallentin.dahlberg@REDACTED
Tue Nov 22 19:13:26 CET 2011


I am frequently in a position where I render html output from logs or
dynamically render erlang data to html in a server.
Usually I don't use any lib for this but rather do something like,


render({Tag, Data}) ->
    T = atom_to_binary(Tag, utf8),
    [ <<"<",T/binary,">">>, render(Data),<<"</",T/binary,">">>];
render(I) when is_integer(I) -> I;
render(Data) when is_binary(Data) -> quote(Data).
render([I|Is]) -> [render(I) | render(Is)];
render([]) -> [].

and put an io:put_chars([render(Data)]) somewhere.

This is of course simple enough but does not cover all bases nor does it
feel right. =)

In other cases I would like an html file where I can embed tags (like ruby
on rails or yaws) and substitute the tags for my input.

Mind you, I just want my iolist. I do *not* want a framework which sets up
dispatchers, sockets, handlers and what not. I just want an easy way, from
erlang, to describe html strings or rewrite a template file (or string). In
the template some javascripts and headers are usually defined while the
body or some content div should be substituted. Well, I think you get it.

Now which library should I use if I want a lean, clean syntax in my module.
Or, put in another way: "Maximal html expressability with minimal erlang
verbosity."

What should I use?

// Björn-Egil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20111122/d04328a3/attachment.htm>


More information about the erlang-questions mailing list