我目前正在用Twig模板做一个交响乐项目。为了知道每个模板是什么,我在文件上添加了大量的注释,包括描述、参数、返回等。
为了能够在这些文件上运行phpDocumentator (或任何其他合适的工具),并为我们的所有开发人员提供一个容易访问的文档,我跳过了一步,但是每次我运行以下命令时,我都会跳起来:
php phpDocumentor.phar -d src/dir1/dir2/CoreBundle/Resources/views/ -t docs/api/ -v
因此,我得到了一个很好的例外:
[Exception]
No parsable files were found, did you specify any using the -f or -d parameter?
我知道docBlock看起来应该像/** comment */
,但是Twig上的评论看起来像{# comment #}
。
是否有办法/工具能够产生这些文件?如果是的话,我该如何做?
谢谢
发布于 2014-08-29 22:24:37
没有“适当”的方法,但你可以采用一种相当糟糕的方法:
示例:
#!/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
这可能需要对phpDocumentor接受的有效评论块进行一些调整。
在此之前:
<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>
之后:
<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>
这一点的缺点,就像任何黑客,是你需要知道这个“处理”时,你写你的Twig评论。
https://stackoverflow.com/questions/25532303
复制相似问题