Part of meta-issue #1788918: [GTD] [META] Prepare for Twig main engine core inclusion until December 1
Problem
When converting tpl.php files and theme functions to twig templates one thing we also have to convert are comments. Currently there is no standard for that.
Why would that be good?
- If we do it right (almost) from the beginning, there will be no need to come back to that later
- the Doxygen team will have time to chip in and voice their needs/preferences/...
Initial proposal
I couldn't find any guidelines on the the matter in the twig coding standards page, so here is an initial idea we can discuss.
Headers
{#
/**
* @file
* Summary here; one sentence on one line (should not, but can exceed 80 chars).
*
* A more detailed description goes here.
*
* A blank line forms a paragraph. There should be no trailing white-space
* anywhere.
*
* Available variables:
* - content: The content for this region, typically blocks.
* - attributes: Array of attributes
* - attributes.class: String of classes that can be used to style contextually through CSS.
*
* @see template_preprocess()
* @see template_preprocess_region()
*/
#}
In-line comment
{# Short inline comment is short. #}
{#
A little longer inline comment is not so pretty any more, but I have
no idea how to make it prettier. Perhaps by indeting the subsequent lines
after the first line with 3 spaces, so that it lines up with the first word of
the first line?
#}
Comments
Comment #1
jenlamptonI'm not sure what the "Doxygen team" thinks - it will be important to hear from them - but I think we should leave the doc blocks at the top of the files very similar to the way they are now, like so:
My thought is that we'll certainly have to add some extra magic to make the parsing on the API site work, and my thoughts were that if we left it this way then all we'd need to do is strip off an additional twig comment indicator at the beginning and at the end of the docblock.
(I didn't see a patch here, so changing status)
Comment #2
jhodgdonAs the maintainer of the API project (which generates api.drupal.org), I am in favor of #1. I will be able to make a simple patch to the API module parser to parse a file that looks like this and display the documentation on api.drupal.org just like we are now doing for the tpl.php files. Even I can write a regexp to find everything between {# and #}, and then assume that's an @file doc block and parse as normal. :)
Comment #3
jhodgdonalso, adding tag
Comment #4
jenlamptonAlso adding a note that we will need to update http://drupal.org/node/1354 when this is decided :)
Comment #5
jenlamptonDoh. cross-post.
Comment #6
jhodgdonHm. I'd like to note that the suggestion in comment #1 is not quite the same as the issue summary: it has /** */ inside of {# #}. The version in comment #1 would actually be easier for the API module to parse, since it is already set up to parse documentation comments in /** */.
Also, I'd suggest in the issue summary that the second section about how to do in-line comments -- the {# #} should always be on their own lines for readability unless the comment is exactly one line long. I think that would make it a lot easier to read/scan.
Comment #6.0
jhodgdonUpdated issue summary.
Comment #6.1
fabianx commentedAdded example from #1
Comment #7
fabianx commentedApplied standards from #6 to issue summary. Thanks @jhogdon.
Comment #8
robloachLet's post-pone this until
front-endis in core. Having Doxygen index the templates would be nice, but I believe we should discuss that later on. There's more pressing things to think about :-) .Comment #9
jhodgdonIsn't it relevant to discuss now? It seems like if we agree on how to do this now, when we convert the tpl files we can do it right the first time?
Comment #10
fabianx commentedAgree, this is a policy we need to discuss then add to standards and follow.
Comment #10.0
fabianx commentedAdd inline comment
Comment #10.1
carwin commentedUpdated issue summary to include jenlampton's stuff from first comment.
Comment #11
jwilson3Also agree. Having already gone through and cleaned up lots of existing docs in the twig front-end branch, to conform to the current instructions for conversion, IMO, it is best to define this earlier than later. The current conversions have so far produced very inconsistent doc that takes a non-trivial amount of time to clean up and format, whereas if the person writing the conversion pays equal attention to the doc as they do the code conversion, following the instructions, there's much less formatting work to do later on. Futhermore, there will be solid examples to copy from, reference, read, and improve, so if they are all consistent now, bad doc habits and formatting will have less chance of perpetuating themselves.
Comment #12
jenlamptonThere are very clear instructions in the documentation for converting now. I don't think the docs were written when the converting started, and I also don't think all the people working on them read all the documentation :)
I did a huge pass on docs updates over the weekend, cleaning up stuff and getting things back in order. But do you have a suggestion as to how to make things clearer, or where to write new docs for people to read?
Comment #13
jhodgdonIf you can point me to where the docs are about twig conversion, I would be happy to review them. Also, if some standards for the comments at the top have in fact been adopted (which I would think should have happened on this issue or on another issue tagged "coding standards" so that those of us interested could comment on proposals?!?), we need to add them to the coding standards section of drupal.org/coding-standards somewhere.
So... where are the standards?
Comment #14
jenlamptonRight now the documentation we are using is specifically for converting theme functions to twig templates, and lives in a google doc:
https://docs.google.com/document/d/1zf7LOdms2x9iqA7b_9vMxw540vg1tT_9VOcm...
...but I'd love to create a d.o docs page somewhere but I'm not really sure where that should live, or what it should look like.
I started a page here but could use some guidance.
Comment #15
jhodgdonThanks! That looks like the right place to put the page.
I fixed a couple of spelling errors on the page, and also here are a couple of notes on the standard docblock itself:
- @ingroup themeable => was misspelled themable [missing e] in the previous revision, but it looks like it's correct in the Google Doc.
- The first line of the docblock was not the same as our standard, so I updated it.
I also added a link to the standards for PHP template files on node/1354, and added a note that comments should wrap at 80 characters. But it looks good! I think we can call this issue fixed, since the standard has apparently been adopted and now it is also documented. Thanks!
Comment #16
jwilson3I've reopened #1813240: Cleanup twig template documentation to fix any instances of misspellings of "themeable" in the twig sandbox front-end branch.
Comment #17.0
(not verified) commentedUpdated issue summary.