About Template Stubs

ProcessWire module that generates stub classes for IDE support. This is a useful tool for Template development for those using IDEs with static analysis, such as PhpStorm, NetBeans, etc.

Category Development Tools
Modules that have more to do with assisting development of a site rather than managing its content.
Release StateStable
Should be safe for use in production environments. *
Authormindplay.dk
Module Version1.0.2
Class NameTemplateStubs
Compatibility2.2, 2.3, 2.4
Date AddedJune 19, 2013
Recommended ByNew recommendations may take up to 1 day to appear.

Details

The module generates a file named "stubs.php" in the TemplateStubs folder, so make sure this folder is write-enabled. The entire documentation file is rebuilt after saving a Template or Field, which adds overhead - do not deploy this module in production, this is a development tool only.

Instructions

See Project Page for examples and further instructions.

README

TemplateStubs

ProcessWire module that generates stub classes for IDE support.

This is a useful tool for Template development for those using IDEs with staticanalysis, such as PhpStorm, NetBeans, etc.

The module generates a file named "stubs.php" in the TemplateStubs folder, somake sure this folder is write-enabled. The entire documentation file is rebuilt after saving a Template or Field, which adds overhead - do not deploy this module in production, this is a development tool only.

To make use of the generated stub classes, add an annotation to the top ofyour template-file - for example, in the top of your "basic-page" template, you would add the following:

<?php

/**
 * @var tpl\basic_page $page
 */

This should enable an IDE with static analysis to auto-complete propertiesof the $page object, defined by the Fields used in the Template.

Because everything is a Page in ProcessWire, the built-in templates forthings like "admin", "role" and "user" will also be documented, which means you can have IDE support for internal templates in modules, for any custom user-fields, etc.

In addition, a special class (e.g. tpl\any) will be generated, documentingall available Fields - this may be useful in situations where you have code intended to work with all (or certain) Fields, e.g. any type of Page.

Example

The output from this module looks like this:

<?php

/**
 * Generated by TemplateStubs module 2013-04-14 11:20:10
 * This file may be overwritten at any time.
 */

namespace tpl;

use Pageimages, Pageimage, PageArray, Page, Password;

/**
 * "admin" template
 *
 * @property string $title Title
 * @property string $process The process that is executed on this page. Since this
 *                           is mostly used by ProcessWire internally, it is
 *                           recommended that you don't change the value of this
 *                           unless adding your own pages in the admin.
 */
class admin extends 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 Yea
 * @property string $sidebar Sidebar
 * @property Pageimages|Pageimage[] $images Images
 */
class basic_page extends Page
{}

/**
 * "permission" template
 *
 * @property string $title Title
 */
class permission extends Page
{}

/**
 * "role" template
 *
 * @property PageArray|Page[] $permissions Permissions
 */
class role extends Page
{}

/**
 * "user" template
 *
 * @property Password $pass Set Password
 * @property string $email E-Mail Address
 * @property PageArray|Page[] $roles User will inherit the permissions assigned to
 *                                   each role. You may assign multiple roles to a
 *                                   user. When accessing a page, the user will
 *                                   only inherit permissions from the roles that
 *                                   are also assigned to the page's template.
 */
class user extends Page
{}

Comments

No comments yet. Be the first to post!

Post a Comment

Your e-mail is kept confidential and not included with your comment. Website is optional.