Opened 10 years ago

Closed 7 years ago

#15399 closed enhancement (fixed)

Cannot add a source header (an HTML comment) in a Dijit Template

Reported by: cjolif Owned by:
Priority: high Milestone: 2.0
Component: Dijit Version: 1.7.2
Keywords: Cc: Patrick Ruzand
Blocked By: Blocking:


In the templates of a templated dijit, you can only have a single HTML element, thus you cannot add a comment. Corporations usually have policies that all source files should have a copyright header and thus this is impossible. The request is simply to be able to have additional comments at the top of the template that will just be skipped at runtime if present.

Attachments (1)

comments.patch (3.5 KB) - added by cjolif 10 years ago.
possible patch

Download all attachments as: .zip

Change History (10)

Changed 10 years ago by cjolif

Attachment: comments.patch added

possible patch

comment:1 Changed 10 years ago by ben hockey

curious why you can't just put the comment inside the first node

comment:2 in reply to:  1 Changed 10 years ago by cjolif

Replying to neonstalwart:

curious why you can't just put the comment inside the first node

Obviously there is no real technical problem puting the copyright header inside the node. But then this is not anymore strictly speaking a header and might not strictly speaking comply with some company rules. I'll try to research how problematic this is if needed.

comment:3 Changed 10 years ago by bill

Sounds like a reasonable request, and the patch looks pretty good, although I wish there wasn't quite so much validation code.

But the main issue I see is that the build tool will inline the copyright comments into the source code (since dojo/text! doesn't do any string manipulation). Seems inefficient. Can you patch that too?

PS: I remember previous conversations about removing all comments from templates. That would be a nice feature too. I wonder if a regex to remove comments would be better. This seems to work:

"<!-- hello world -->hi<!-- goodbye\nworld -->".replace(/<!--[\s\S]*?-->/g, "")

(tested on FF and IE7)

Last edited 10 years ago by bill (previous) (diff)

comment:4 Changed 10 years ago by Patrick Ruzand

Cc: Patrick Ruzand added

comment:5 Changed 10 years ago by cjolif

bill, thanks for your feedback, yes, this can probably be achieved by regexp. Also another way to reduce the code size would be to allow only a single header comment and remove just that one (no loop). This would be enough for our use-case but it seems a bit inconsistent to allow one and not several.

I will do more testing along the regexp solution even if maybe if there is a lot of comments in a template (not just as a header but inline) that actually might be slower? (not sure).

pruzand will work on the build side of the patch.

comment:6 Changed 10 years ago by bill

OK, I meant to remove comments everywhere (although probably there wouldn't be more than one in practice).

I'm not worried about the performance, since builtin functions are usually faster than custom javascript, and I think it's just the single line of code listed above. I'm also thinking about adding a regex for trimming whitespace as per #8494.

comment:7 Changed 9 years ago by bill

Priority: undecidedhigh

comment:8 Changed 9 years ago by bill

Milestone: tbdfuture

comment:9 Changed 7 years ago by bill

Milestone: future2.0
Resolution: fixed
Status: newclosed

This is handled in Delite (aka 2.0) by toDom() method.

Note: See TracTickets for help on using tickets.