Coder Social home page Coder Social logo

templatestubs's Introduction

TemplateStubs

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.

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.

To make use of the generated stub classes, add an annotation to the top of your 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 properties of the $page object, defined by the Fields used in the Template.

Because everything is a Page in ProcessWire, the built-in templates for things 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, documenting all 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
{}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.