Friday, December 2, 2011

Re: HTML Tidy Component



On Friday, 2 December 2011 06:19:22 UTC+1, Thiago Belem wrote:
Folks,

I've just finished the HTML Tidy Component, it helps you to sanitize, clean and solve several HTML markup issues automatically.

Just include it in your list of components you'll get a clean and valid output.

First point that jumps up is: What is a class that is 100% focussed on the V of MVC doing in the C? 

I would like to hear from everyone, including suggestions for improvement in the component and unit tests.

Positive: generally it's useful

Neutral: Googling you'll find that you are not the only person to have written something to automatically call tidy for you (there's at least one helper already out there on the bakery) 

Suggestions:

Should be a helper, or a lib (so that you can, if you really want, call it from anywhere in your app, e.g. before save in a model,  from a helper when rendering) and a helper. The helper is just an after layout callback to auto call repairString if _configured_ to do so.

Throwing exceptions (again, in the constructor) means it doesn't degrade gracefully. It works as designed or if flat out kills your application - that's not good. What happens to your application when you deploy or upgrade to your production server and tidy isn't/is-no-longer available?
 
Instanciating Tidy in the constructor means you're loading a class on all requests which potentially you're not going to use just by including the component. However implemented it should lazy-load wherever possible (that means new Tidy() is called the first time you actually try to use the class - not optimistically loading it early). In practical terms that means only check settings in constructor/setup functions - do as little as possible. 

Using shutdown means if you wanted to use the class to repair some random string that you aren't sending to the browser - you get as a 'bonus' whatever html you render being corrected - with no obvious configurable way to turn that off (except removing the component or disabling the component before the request finishes)

Throw exceptions when you try to use code and it won't work without addressing "the problem". Trigger errors when you try to use code and some recoverable problem occurs - That doesn't break your app but it does put "Tidy is configured to clean up your shitty html - but the extension isn't available" into the error log which devs (should) read.

hth,

AD

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: