Bug 158 - [Chameleon 1.1] Enable Commenting out cwc2 tags in template
: [Chameleon 1.1] Enable Commenting out cwc2 tags in template
Status: RESOLVED FIXED
: Chameleon
Core
: 1.99
: PC Windows NT
: P3 normal
: 1.99 beta 4
Assigned To:
:
:
:
:
:
  Show dependency treegraph
 
Reported: 2003-12-09 10:12 by
Modified: 2004-12-02 21:27 (History)


Attachments


Note

You need to log in before you can comment on or make changes to this bug.


Description From 2003-12-09 10:12:04
This bug replicates bug 2238 from the deprecated Chameleon bugzilla.

This is not a major problem or anything but I find that during template create
one goes through alot of widget placement and testing.  Currently, you have to
rip out the entire cwc2 tag if you don't want it to render on the page.  Would
it be possible to reserve a comment for it so that you can leave it in the
template and the parser will just ignore it?  Or better yet ... if it encounters
a widget commented out then it replaces the whole widget with &nbsp or
something.  I would think a commnet like::

<!cwc2 type="...."/>

parsed as

&nbsp;

would be nice.

Just a thought

Jay
------- Comment #1 From 2003-12-09 13:44:33 -------
this is possible.  I would prefer to use something like <!--<cwc2 .... />-->
though.  In this case, we can use the existing template parser with a second
regex for detecting this case and emitting the whole commented tag back into the
output.

It may even allow for whitespace between the <!-- and the <cwc2.

------- Comment #2 From 2003-12-09 16:00:11 -------
Not to invalidate what Paul suggested, but I would be confused if 

<!--<cwc2..></cwc2>--> 

successfully commented out the tag, but 

<!-- <td>etc</td> 
     <td>more tags</td>
     <td><cwc2...></cwc2></td>-->

didn't.  Make sense?
  
------- Comment #3 From 2003-12-09 16:47:23 -------
I don't know in depth details about the actual cwc2 tag parser, however, if the
parser inherits a generic XML parser, then shouldn't this be a non-issue?  If
not, why are we using a hand-made parser to parse the cwc2 tags?
------- Comment #4 From 2003-12-09 18:07:40 -------
> If not, why are we using a hand-made parser to parse the cwc2 tags?

Because we don't need a real parser. The current method is not a parser: it only
looks for the CWC2 tags using regular expressions and only does textual
replacements... it's as optimal as it gets while remaining very flexible and
easy to maintain.

A real parser would add tons of unnecessary overhead and probably wouldn't work
on HTML documents anyway: most of the time HTML doesn't validate as XML (I know
it could in theory, but people are lazy), and just an unclosed XML tag (such as
<p> or <br> which are extremely common) is enough to confuse any XML parser. 
------- Comment #5 From 2003-12-09 19:05:26 -------
we are not for (at least) these reasons:

1. HTML is not valid XML
2. speed.  it it not necessary to parse the rest of the contents of the page,
just the cwc2 tags
3. replacement.  The parser not only identifies tags, but also replaces them
with the widget output as well, this would involve more steps using a regular
XML parser.

we may be able to set up the regex to ignore cwc2 tags that appear inside <!--
--> comment tags.  Or we may not ... to be determined.
------- Comment #6 From 2003-12-09 19:07:24 -------
opps, didn't see Daniel's comments :)  At least we are consistent.
------- Comment #7 From 2003-12-09 20:08:38 -------
That's a good sign!  :)
------- Comment #8 From 2004-04-05 15:31:33 -------
any solution is going to make chameleon slower.  Should we actually support
this?  If yes, then I propose to run two parser passes on the template, one to
extract comments and a second to extract widgets.   This would remove commented
out widgets from the template, but would require two passes.  Not sure what the
performance implications of this would be.

Note to implementor:

build regex to extract <!-- up to -->, create new instance of TemplateParser
with this regex, process template, insert empty string ("") as replacement for
all comments, run replacements, and then pass resulting page to the regular parser.
------- Comment #9 From 2004-04-05 15:47:26 -------
If we are going for a standarized approach to commenting then <!-- --> would be
the path to take as we are dealing with HTML as well.  Note that simply removing
cwc2 from the tag itself seems to do the trick with no (noticeable)
implications.  Is this sufficient as a solution?  The end result is not valid
HTML - this is a definite drawback, however, the use of a commented widget in
production *should* be rare.  The original intent of this post was to assist
with application development (so that the parser would not choke).
------- Comment #10 From 2004-04-05 18:32:26 -------
My 0.02$ on this: If you do this then go with <!cwc2...> as was initially
suggested since this makes it very quick to comment a tag and will have the
least performance impact. The <!cwc2> tags would simply be replaced with an
empty string using preg_replace. Processing all HTML comments would have a
bigger impact on performance, plus you would lose all the legitimate HTML
comments unless you support some king of nested parsing as suggested above
(complexity == bugs).

Also, the day there is a user-friendly template editor for Chameleon, it will be
much easier for that editor to catch <!cwc2...> than <!-- ... blah <cwc2...> ...
-->.

Finally, the docs should state clearly (in bold-italic-red-underlined) that
commented widgets should be taken out of a template on production servers for
performance reasons.
------- Comment #11 From 2004-04-08 08:35:50 -------
updated version to 1.99
------- Comment #12 From 2004-04-14 10:36:59 -------
I like daniel's suggestion the best.

<!cwc makes total sense to me, and I also like the suggestion of it returning
nothing as opposed to a space or an &nbsp;

btw, I think this will be great for debugging templates!
------- Comment #13 From 2004-07-08 10:45:21 -------
Changed target to 1.99 RC1.
------- Comment #14 From 2004-08-10 20:24:37 -------
Changed Severity to normal.
------- Comment #15 From 2004-11-04 18:18:37 -------
This can be accomplished by setting enabled="FALSE" in the widget.  This will
result in the widget being completely deactivated and removed from the
interface, but will leave the tag in the page as an HTML comment <!-- <cwc2
....></cwc2> -->