timber/teak 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

timber/teak

Composer 安装命令:

composer require timber/teak

包简介

Generate a Markdown reference documentation for PHP projects (optimized for WordPress)

README 文档

README

Teak is a CLI utility to generate a Markdown reference documentation for PHP projects (optimized for WordPress).

It can generate documentation for

You can use documentation generated by Teak to create a documentation website when you use it in combination with a static site generator.

Teak is used to generate the documentation for Timber, which uses Hugo as a static site generator.

Installation

You can install the package with Composer:

composer require timber/teak --dev

CLI Usage

Generate a class reference

When you pass a folder to the Class Reference Generator, it will generate a separate Markdown file for each class that it finds.

Use a folder as the input

vendor/bin/teak generate:class-reference ./lib/ --output ./docs/reference

This searches all the PHP classes in ./lib/ and outputs the Markdown files into ./docs/reference.

Use a single file as the input

vendor/bin/teak generate:class-reference ./lib/Post.php --output ./docs/reference

Generate a function reference

The Function Reference Generator will search all the files for global functions and output them in a single Markdown file.

vendor/bin/teak generate:function-reference ./lib/ --output ./docs/

Generate a hook reference

The Hook Reference Generator will search all the files for WordPress actions or filters and outputs one single Markdown file, with all the hooks found.

vendor/bin/teak generate:hook-reference ./lib --output ./docs/hooks --hook_type=filter
vendor/bin/teak generate:hook-reference ./lib --output ./docs/hooks --hook_type=action

Options

  • --hook_type – The hook type to look for. Has to be either filter or action.
  • --hook_prefix – Hook prefix (to select only hooks with a certain prefix).

Global CLI options

Display help for commands

vendor/bin/teak generate:class-reference -h
vendor/bin/teak generate:function-reference -h
vendor/bin/teak generate:hook-reference -h

File options

  • --file_name – File Name (the .md extension is appended automatically)
  • --file_prefix - File Prefix
  • --file_title - File Title (Heading 1 in the Markdown document). Only applicable to hooks and functions reference.

Front Matter options

Teak can generate Front Matter Blocks that you will use if you use the generated Markdown files to generate a website using a static site generator.

  • --front_matter_style – Front Matter type. Currently, only "YAML" is supported (if not provided, will output a Heading 1 instead of a Front Matter block).

DocBlocks

Teak works best if you follow the WordPress PHP Documentation Standards. Because the documentation renders to Markdown, you can use Markdown syntax in your DocBlocks.

Ignoring Structural Elements

An element (class, method, property) is ignored when one of the following conditions applies:

  • No DocBlock is provided
  • No @api tag is present
  • An @ignore tag is present
  • An @internal tag is present
  • The visibility is private (applies to methods only)

This means that for Markdown files to be generated for a class at all, you’ll need at least a DocBlock, with an @api tag.

/**
 * Class My_Public_Class
 *
 * @api
 */
class My_Public_Class {}

Special Tags

@example

The @example tag allows you add code examples to your DocBlocks, including fenced code blocks:

/**
 * Function summary.
 * 
 * Function description.
 *
 * @api
 * @example
 *
 * Optional text to describe the example
 * 
 * ```php
 * my_method( 'example', false );
 * ```
 *
 * @param string $param1 Description. Default 'value'.
 * @param bool   $param2 Description. Default true.
 */
function my_method( $param1 = 'value', $param2 = true ) {}

@hooked

The @hooked tag allows you to mark which internal functions are hooked to your action.

/**
 * Fires in the head element of the website
 * 
 * @hooked my_statistics_function - 10 (Outputs the statistics code, if enabled)
 * @hooked my_analytics_function - 11 (Outputs the analytics meta tags, if enabled)
 */
do_action('my_custom_head');

Parameters that are arrays

Teak supports parameters that are arrays.

Hook Variations

Sometimes you’ll have two hooks that follow each other and do basically the same, but allow you to make the hook apply only on certain conditions:

/**
 * Fires on a specific processing status.
 * 
 * The status can be one of the following: `success`, `error` or `fail`.
 */
do_action( "myplugin/process/status/{$status}" );
do_action( "myplugin/process/status/{$status}/{$action}" );

In this example, you’d have a variable $status and an $action. The first action is triggered when you use it with a certain status, the second action would be triggered if you use a certain status and a certain action. Teak will list these hook variations under the same hook. Because of this, you only need to define a DocBlock for the first hook.

Limitations

This compiler is not a full implementation of phpDocumentor. Rather, it tries to make code documentation that follows the WordPress PHP Documentation Standards more readable, and less techy. Not all official tags are considered yet.

Contributing

Contributions are very welcome.

Roadmap

  • CLI: accept a list of files.
  • Support nested array arguments
  • Add support for Inline Tags.
  • Add tests.
  • Optimize linking between Markdown documents.

timber/teak 适用场景与选型建议

timber/teak 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 134 次下载、GitHub Stars 达 6, 最近一次更新时间为 2018 年 04 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 timber/teak 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 timber/teak 我们能提供哪些服务?
定制开发 / 二次开发

基于 timber/teak 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 134
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 10
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-04-04