Winter /wn-docs-plugin
在 Winter CMS 中读取和管理文档
v1.0.2
2024-07-23 12:04 UTC
Requires
- php: >=7.2.9
- composer/installers: ~1.0
- nikic/php-parser: ^4.11.0
- phpdocumentor/reflection-docblock: ^5.2.2
README
将完整套件的文档直接集成到 Winter CMS 安装中。文档可以由 Markdown 文件生成,或从 PHP 代码中分析。
功能
- 从插件或远程 ZIP 文件本地生成文档。
- 从 Markdown 文件创建基于内容的文档。
- 从 PHP doc-blocks 和解析的 PHP 代码创建 API 文档。
- 可在后端和 CMS 中使用。
入门
要安装插件,您可以通过 Winter CMS 市场place 安装,或者使用 Composer 安装
composer require winter/wn-docs-plugin
然后,运行迁移以确保插件已启用
php artisan winter:up
注册文档
可以通过向您的插件类(Plugin.php
)中添加 registerDocumentation
方法来注册文档,具体取决于文档是基于内容还是基于 API,以及文档或代码是本地存储还是远程存储。
<?php class MyPlugin extends \System\Classes\PluginBase { // ... public function registerDocumentation() { return [ 'guide' => [ 'name' => 'Documentation Guide', 'type' => 'user', 'source' => 'local', 'path' => 'docs' ], ]; } // ... }
该方法应返回一个数组,其中每个项的键代表文档的“代码”,以下参数以数组形式作为值
对于 API 文档(即 type
参数为 php
),可以指定一些额外的参数
文档类型
当前 Docs 插件支持两种文档类型,Markdown(md
)和 PHP(php
)。
Markdown
Markdown 用于生成文本和基于图像的文档,允许在短时间内轻松编写大量文档。Markdown 文档处理器使用 CommonMark 库 来确保 Markdown 的准确解析并启用这些有用功能
- 自动链接网页和电子邮件地址
- 自动生成目录和锚点标签
- 外部链接处理
- 前端内容(标题和元定义)
- Markdown 表格
Markdown 文档可以以任何您喜欢的方式排列 - 主要目录可以在文档源中的 .yaml
文件中指定。
示例目录 YAML 文件
rootPage: home sections: Introduction: pages: welcome: "Welcome" Functionality: pages: functionality/cool-stuff: "Cool Stuff" functionality/big-things: "Big Things"
示例 Markdown 文档
--- title: Big Things --- # Big Things We have some big things available in this software. ## Awesome Feature One This feature allows you to reach a new level of awesome.
PHP
PHP 文档涉及解析 PHP 源代码目录,并确定所有源代码对象(如类、命名空间、属性和方法)中可用的 API。
使用出色的 PHP 解析库,代码根据类的所有方面的签名进行分析和推导,以及编写的 doc-blocks 提供了额外的上下文。
这允许以下类
<?php namespace Acme\Blog; use MarkdownParser; class Post extends \BasePost { public string $title; public string $content; /** * Whether the post is published or not */ protected boolean $published = false; /** * Renders the post and returns an array * * @return array Title and content */ public function render() { return [ 'title' => $this->title, 'content' => MarkdownParser::parse($this->content), ]; } }
被渲染成可读的文档,概述可用的属性($title
、$content
)和方法(render()
)。