Reputation: 311
I'm currently working on a Symphony project with Twig templates. In order to know what each template does I'm adding extensive comments on the files with descriptions, parameters, returns, etc...
I was hopping to be able to run phpDocumentator (or any other suitable tool) on these files and have an easily accessible documentation for all our developers, however every time I run the following command:
php phpDocumentor.phar -d src/dir1/dir2/CoreBundle/Resources/views/ -t docs/api/ -v
I get a nice Exception as result:
[Exception]
No parsable files were found, did you specify any using the -f or -d parameter?
I know the docBlock should looks like /** comment */
but comments on Twig looks like {# comment #}
.
Is there a way/tool to be able to produce these documentation? If so, how do I do it?
Thanks
Upvotes: 2
Views: 1465
Reputation: 13107
There is no “proper” way, but you could apply a pretty rotten hack:
Example:
#!/bin/bash
targetpath="/tmp/phpdoc"
[ -d "$targetpath" ] && rm -r $targetpath
mkdir -p $targetpath
for twigfile in $(find src/ -name '*.html.twig'); do
newtwigfile="$targetpath/${twigfile//\//_}.php"
perl -pe 's|{#|<?php /*|g' $twigfile | perl -pe 's|#}|*/ ?>|g' > $newtwigfile
done
php phpDocumentor.phar -d $targetpath -t docs/api/ -v
This may need some tweaking in regard to what phpDocumentor accepts as valid comment blocks.
Before:
<div>
{#
This is the glorious lorem ipsum.
#}
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</p>
</div>
After:
<div>
<?php /*
This is the glorious lorem ipsum.
*/ ?>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</p>
</div>
The downside of this, like of any hack, is that you need to know about this “processing” when you write your Twig comments.
Upvotes: 1