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

Bob Ippolito <>
Wed Nov 23 19:42:02 CET 2011


I wouldn't say that mochiweb_html has good support for transforms, but it's
easy enough to build that stuff.

mochiweb isn't a framework, it's just a collection of libraries that we
use. mochiweb_html is mostly self-contained although it depends on another
module or two full of relevant constants.

-bob

On Wednesday, November 23, 2011, Daniel Dormont <>
wrote:
> 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 <>:
>> 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
>> 
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20111123/5ebc445a/attachment.html>


More information about the erlang-questions mailing list