I code a custom CMS when I can't find a CMS that does 99% of my required features out of the box. Otherwise it's simply not worth my time.
A CMS is lost if tries to dictate the HTML output, sadly most of them do.
My best bet is to use frameworks/libraries to achieve the needed features. I look at his as a Lego building project.