mindplay.dk Posted April 13, 2013 Share Posted April 13, 2013 This module generates a "stubs.php" file containing PHP-classes with documentation for the properties of each Template, based on it's fields - which means IDE support (auto-complete, inspections, documentation) for templates in modern IDEs that perform static analysis, such as PhpStorm. The output looks like this: <?php /** * Generated by TemplateStubs module 2013-04-13 15:29:33 * This file may be overwritten at any time. */ namespace tpl; use Page; /** * "basic-page" template * * @property string $title Title * @property string $headline Use this instead of the Title if a longer headline is needed than what you want to appear in navigation. * @property string $summary Summary * @property string $body Body Content * @property string $sidebar Sidebar * @property Pageimages|Pageimage[] $images Images */ class basicpage extends Page {} To use the generated documentation, start your template-file like this: <?php /** * @var tpl\basicpage $page */ Documentation and more details on this page: https://github.com/mindplay-dk/TemplateStubs You can consider this an alpha-release - I haven't tagged a release yet, and some details like template-class naming convention may change before I tag release 1.0. 9 Link to comment Share on other sites More sharing options...
mindplay.dk Posted April 14, 2013 Author Share Posted April 14, 2013 Some updates: a use-clause is now generated, pretty big oversight there. PageReference types are now documented with their pseudo-types, which means you'll be able to directly follow a reference to a related page (or list of child-pages) while still getting IDE support. I simplified the class-name convention - "basic-page" now simply becomes "tpl\basic_page". And the generated documentation can now be viewed on the configuration-screen - you will see it when you install the module. Link to comment Share on other sites More sharing options...
Soma Posted April 15, 2013 Share Posted April 15, 2013 Thanks for you work here mindplay, I'm sure this will be interesting and comes handy for people that use and like this stuff. Personally I never felt the need for this in ProcessWire, as for the hand full of objects and variables I usually need that are always the same anyway. So in other words PW is so simple this is like having a description how to use a key on a door. Link to comment Share on other sites More sharing options...
mindplay.dk Posted April 15, 2013 Author Share Posted April 15, 2013 You only have a handful of Page objects and Fields? I think you misunderstood - this does not provide IDE support for ProcessWire (which still needs a lot of work in this area) but for your templates and fields. I'm sure you have more than a handful on complex sites, and I'm prertty sure they're not always the same? It's not about simple or difficult, it's about proofing your work - knowing in advance if you misspelled a property-name, or not having to go back to find the name of a property on an admin-screen, it saves time. With inspections in PhpStorm, there is also the added benefit of being able to automatically find errors - if you have dozens of templates and you have to make a change like renaming or deleting a field, automatic inspections will instantly reveal which templates are affected. Most of my day-to-day work is not little projects, but large complicated business-systems - while I used to be able to keep it all in my head, I'm not getting any younger. A good IDE will help you stay fast and accurate when you grow older, wait and see 4 Link to comment Share on other sites More sharing options...
mindplay.dk Posted April 15, 2013 Author Share Posted April 15, 2013 PS: things are already simple - nothing wrong with making them simpler though, especially when it's no additional work or overhead for those using the module and working with an IDE. For me, personally, having full IDE support for any piece of PHP software has become a sign of high quality - it means everything can be validated automatically, which usually means it has been. You can't expect a person to do the same for 10,000 lines of code on every release. And vice versa, if a computer can't infer the meaning of your code, how can you expect a person to? Whether you have IDE support for the users who use an IDE or not, having IDE support means you have automatic safeguards and checks that cannot be performed by a person. 4 Link to comment Share on other sites More sharing options...
mindplay.dk Posted June 19, 2013 Author Share Posted June 19, 2013 I've tagged release 1.0.0 and the module is now listed in the modules directory. 4 Link to comment Share on other sites More sharing options...
bfncs Posted June 27, 2013 Share Posted June 27, 2013 Thanks for working on this. It works perfectly with PHPStorm and makes writing templates even faster and more precise than before. Please keep up the good work! 2 Link to comment Share on other sites More sharing options...
Rob Posted July 2, 2013 Share Posted July 2, 2013 ...PageReference types are now documented with their pseudo-types, which means you'll be able to directly follow a reference to a related page (or list of child-pages) while still getting IDE support... Hi - great module which will help me a lot, but I'm a bit confused about this point. My stubs.php file is generating fine and documents all the fields in each template, but it is only documenting related page fielsd like this... @property PageArray|Page[] $related_products ...meaning that I get code completion for al the core Processwire Page fields/methods but not my template fields. Shoud it be generating like this... @property tpl_product[] $related_products ...so that I get code completion for all the fields of my related page/template? Is this a bug or do I need to change some config somewhere? I couldn't find anything. I am perhaps misunderstanding how the phpdoc comments informs my IDE (PHPStorm) but as it stands, I get my first-level fields for a page but nothing for the related page fields. I downloaded the module as master.zip from github so it should be the latest code. Link to comment Share on other sites More sharing options...
mindplay.dk Posted July 2, 2013 Author Share Posted July 2, 2013 You most likely didn't configure the allowed template for your Page-field? If so, it should work. Check the "Input" tab in the Field editor, under "Template of Selectable Page(s)". Link to comment Share on other sites More sharing options...
Rob Posted July 3, 2013 Share Posted July 3, 2013 You most likely didn't configure the allowed template for your Page-field? If so, it should work. Check the "Input" tab in the Field editor, under "Template of Selectable Page(s)". Great, thanks, that makes perfect sense. Link to comment Share on other sites More sharing options...
mindplay.dk Posted November 22, 2013 Author Share Posted November 22, 2013 Just tagged version 1.0.2 which adds an "any" template, documenting all available Fields - this may be useful if you're writing code that works with any type of Page. 1 Link to comment Share on other sites More sharing options...
pwFoo Posted August 2, 2015 Share Posted August 2, 2015 Hi mindplay, with this module installed and added the following code to my (basic-page) template <?php /** * @var tpl\basic_page $page */ code completion for things like "$page->title" should be work with Netbeans? stubs.php file exists, folder is writable. Netbeans suggest variable / object names like $page, $modules, but not the object properties (example $page->title) Link to comment Share on other sites More sharing options...
mindplay.dk Posted August 2, 2015 Author Share Posted August 2, 2015 I don't use NetBeans, I use Storm, but I would be very surprised if NetBeans doesn't support basic standard php-doc annotations like @var. Maybe your IDE isn't set up to inspect the stubs.php file? Check to make sure the contents of stubs.php is being updated and reflects your templates/fields? Make sure the output matches your type-hint - this is configurable, e.g. "tpl\basic_page" is one option, but "tpl_basic_page" is also possible. Just checked, the default is the "tpl_" prefix, and no namespace (for compatibility with older PHP versions) so check the module configuration, you can set the prefix and namespace as needed. Link to comment Share on other sites More sharing options...
pwFoo Posted August 7, 2015 Share Posted August 7, 2015 Hello mindplay, stubs.php file wasn't generated correct. So I deleted it and regenerated it by submit at modules page. Now my fields are added to stubs.php, but Netbeans ignore the fields at code completion... I have to test some configuration settings and take a look at the Netbeans documentation. Thanks Link to comment Share on other sites More sharing options...
mindplay.dk Posted August 8, 2015 Author Share Posted August 8, 2015 @pwFoo if this turns out to be a NetBeans issue, and if you figure it out, please post and let me know the solution - I can add it to the README to help others get started. Link to comment Share on other sites More sharing options...
pwFoo Posted August 10, 2015 Share Posted August 10, 2015 Strange... Netbeans have code completion for variables like $page, $pages, $padRender (test instance with PadLooper installed), but missed attributes and methods ($page->myField). Quick test with Visual Studio Code (Linux, 0.5) shows me code completion for attributes and methods ($page->title, $page->body ...) out of the box (it seems also without the TemplateStubs stubs.php file?!), but not variables like $padRender, $pages, ... At the moment I can't spend time to debug, but I'll reply when I solved my problem. Link to comment Share on other sites More sharing options...
adrianmak Posted April 25, 2016 Share Posted April 25, 2016 $page variable is working find in phpstorm However, there is no code autocomplete for other variables like $session, $pages, $users, $user, etc Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now