a html comment with COMMENT

68 views
Skip to first unread message

Robin Manoli

unread,
Sep 18, 2014, 6:45:15 AM9/18/14
to web...@googlegroups.com
Hey,
is there a built-in way to make a html comment with web2py? Although you can do it such as XML( "<!-- %s -->" % text), it still could be intuitive to implement COMMENT(text).

What do you think?

Leonel Câmara

unread,
Sep 18, 2014, 7:00:08 AM9/18/14
to web...@googlegroups.com
There's no built-in way. Why would you want this?


Robin Manoli

unread,
Sep 18, 2014, 8:43:03 AM9/18/14
to
Because html comments are part of the html language so why shouldn't they have a helper? It is particularly useful when writing widgets with html helpers and informing when they end, such as
<DIV class="my-widget">
    ...lots of code
</DIV><!-- /.my-widget-->

which would be written as:
DIV( ..., _class='my-widget' ) + COMMENT('/.my-widget')

because it is much cleaner than
DIV( ..., _class='my-widget' ) + XML('<-!-- /.my-widget -->')

Edit: perhaps since this feature might only be sensible for this case, there could be a new attribute for html helpers called something like end_comment which writes out <!-- /.class --> or <!-- /#id -->

Niphlod

unread,
Sep 18, 2014, 3:08:46 PM9/18/14
to web...@googlegroups.com
I'm so -1 that -NaN doesn't begin to describe the downvote. Why pollute html with something that is marginally useful only in debug ?

Leonel Câmara

unread,
Sep 18, 2014, 3:26:05 PM9/18/14
to web...@googlegroups.com
I guess if we really wanted this, HTML helpers could have a kwarg like comment_close_tag. This wouldn't pollute stuff much.

For instance 
DIV('lala', comment_close_tag=True)

Then the xml would have a closing comment, but seriously I don't think there's a need for this feature and less code is better.

Robin Manoli

unread,
Sep 20, 2014, 6:31:48 AM9/20/14
to web...@googlegroups.com
In my experience debuggning takes a lot of time and energy. Compared to other parts of development, debugging takes a lot more time per completed construction than other tasks.So why to not improve debugging capabilities when you can?

Leonel Câmara

unread,
Sep 20, 2014, 7:33:22 AM9/20/14
to web...@googlegroups.com
Robin but I don't get how that helps debugging, modern browsers have inspect element and automatically show you where a tag opens and closes.

Massimo Di Pierro

unread,
Sep 20, 2014, 2:07:36 PM9/20/14
to web...@googlegroups.com
Good question. The best way is to use <!-- comments //--> in the html or {{# comments}} in pyhton. 

Robin Manoli

unread,
Sep 20, 2014, 7:23:25 PM9/20/14
to web...@googlegroups.com
Yes I just happen to look through the source code sometimes too. Do you never do that?

There are different reasons that I do that:
- I can see the source code, and find out for example missing closing tags. Maybe this is the most likely use of the comments, and doesn't apply with the html helpers.
- To scroll through the source code, to get an overview of something. It is faster and more convenient to press ctrl+u, ctrl+f (find something), ctrl+g, than the lag of right click and inspect element...
- Maybe it makes more sense that I want to produce readable html, which is an example usage: https://groups.google.com/forum/#!topic/web2py/pyOosnV9AuQ

Reasons why I think it could be of use:
- It is common practice that these end closing class/id comments are written all over the web. Even bootstrap does it.
- Another web2py user wrote a tidy html function (as linked above to the readable html), so there might be others than me who care about having a neat and organized html output.

Anyway, if the community isn't interested in this functionality I have solved the issue for myself.

Thanks for your feedback.
Reply all
Reply to author
Forward
0 new messages