bevry/docpad — pull request #454 by rantecki (2013-03-10 09:09:53+00:00)
Title: "if data" checks in FileModel

I have a need for the dynamic creation of 'virtual' documents (that don't correspond to a physical source file). This, thankfully, appears to be supported by the FileModel class, with the document body being set via the 'data' parameter.

However, as a slight twist, my documents also have empty content (i.e. { data: "" }) as they are only used to pass metadata to the layout, which does all the rendering.

This brings me to my problem: I'm not sure if this is by design, but the two "if data" checks in the FileModel class will evaluate to false for an empty string. This results in @buffer remaining as null, which then results in strange behaviour in the parse() function, and the documents refuse to render/cooperate.

This is all fixed if I change the checks to "if data?" instead. I'm not sure if there was a good reason for them not to be this way?

I could of course pass some dummy value as the document content, e.g. { data: "test" } and then just not render the @content in the layout, but it seems a bit silly, no?