[erlang-questions] How do I reformat and output HTML strings as iolists in a convenient way?
Daniel Dormont
dan@REDACTED
Wed Nov 23 19:33:12 CET 2011
I've had decent luck with mochiweb_html so far. It doesn't require the
full mochiweb framework (though it's not totally self contained - some
of the other modules are needed). Check out mochiweb:to_html, which
does require a data structure somewhat different from what you have in
your render function but might work.
dan
2011/11/22 Björn-Egil Dahlberg <wallentin.dahlberg@REDACTED>:
> 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
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
More information about the erlang-questions
mailing list