|
2 | 2 |
|
3 | 3 | ## Configuring phpDocumentor
|
4 | 4 |
|
5 |
| -Add a file called `phpdoc.xml` with the following content to the root of your project and invoke the `phpdoc` command without arguments. Modify the configuration to suit your project. |
| 5 | +> These instructions are for phpDocumentor 2, but similar approachment will be valid for phpDocumentor 3. |
| 6 | +
|
| 7 | +You need to tell phpDocumentor (1) where are your PHP source files, (2) where to generate the API documentation and (3) where is the template (for a Composer project, is ). You can, also, (4) configure which elements include by its visibility. |
| 8 | + |
| 9 | +In order to accomplish this, you must create a configuration file named `phpdoc.dist.xml` and setup (1, 2, and 3). |
| 10 | + |
| 11 | +:::tip Template location [3] |
| 12 | +If you installed via Composer, the template will be `vendor/nelson6e65/phpdoc-vuepress/data/templates/vuepress`. |
6 | 13 |
|
7 | 14 | ```xml
|
8 |
| -<?xml version="1.0" encoding="UTF-8" ?> |
9 |
| -<phpdoc> |
10 |
| - <parser> |
11 |
| - <visibility>public,protected</visibility> |
12 |
| - <target>build/api-cache</target> |
13 |
| - </parser> |
14 |
| - |
15 |
| - <transformer> |
16 |
| - <target>docs/api</target> |
17 |
| - </transformer> |
18 |
| - |
19 |
| - <transformations> |
20 |
| - <template name="vendor/nelson6e65/phpdoc-vuepress/data/templates/vuepress" /> |
21 |
| - </transformations> |
22 |
| - |
23 |
| - <files> |
24 |
| - <directory>src</directory> |
25 |
| - </files> |
26 |
| -</phpdoc> |
| 15 | +<transformations> |
| 16 | + <template name="vendor/nelson6e65/phpdoc-vuepress/data/templates/vuepress" /> |
| 17 | +</transformations> |
27 | 18 | ```
|
| 19 | +::: |
| 20 | + |
| 21 | + |
| 22 | +You can use the configuration of this project as example and guide. Just edit the values that suits your project. |
| 23 | + |
| 24 | + |
| 25 | +### Example |
| 26 | + |
| 27 | +Here is the explained phpDocumentor configuration for this project: |
| 28 | + |
| 29 | +<<< @/phpdoc.dist.xml |
| 30 | + |
| 31 | +Then, you can just run `phpdoc`. |
28 | 32 |
|
29 |
| -More information about [configuring phpDocumentor](http://www.phpdoc.org/docs/latest/references/configuration.html). |
| 33 | +> For further information, check the [Configuring phpDocumentor page](http://www.phpdoc.org/docs/latest/references/configuration.html). |
30 | 34 |
|
31 |
| -> Yo can use [`phpdoc.dist.xml`](https://github.com/nelson6e65/phpdoc-vuepress/blob/master/phpdoc.dist.xml) of this repo as a guide. |
32 | 35 |
|
33 | 36 |
|
34 | 37 | ## Configuring VuePress
|
35 | 38 |
|
36 |
| -Create a **`docs/.vuepress/config.js`** file like this: |
37 |
| - |
38 |
| -```js |
39 |
| -module.exports = { |
40 |
| - dest: 'dist/phpdoc-vuepress', |
41 |
| - base: '/phpdoc-vuepress/', |
42 |
| - |
43 |
| - markdown: { |
44 |
| - lineNumbers: false, |
45 |
| - }, |
46 |
| - |
47 |
| - themeConfig: { |
48 |
| - nav: [ |
49 |
| - { text: 'API', link: '/api/' }, |
50 |
| - ], |
51 |
| - |
52 |
| - sidebar: { |
53 |
| - '/api/': [ // `docs/api/` directory |
54 |
| - { |
55 |
| - title: 'API', |
56 |
| - collapsable: false, |
57 |
| - children: [ |
58 |
| - '', |
59 |
| - 'classes', |
60 |
| - 'interfaces', |
61 |
| - 'traits', |
62 |
| - 'functions', |
63 |
| - 'constants' |
64 |
| - ] |
65 |
| - } |
66 |
| - ], |
67 |
| - '/': [ |
68 |
| - '' |
69 |
| - ] |
70 |
| - }, |
71 |
| - sidebarDepth: 3, |
72 |
| - |
73 |
| - docsDir: 'docs', |
| 39 | +If you don't already have configured your VuePress, create **`docs/.vuepress/config.js`** following the ***Config Reference*** according to [v0.x](https://v0.vuepress.vuejs.org/config/) or [v1.x](https://vuepress.vuejs.org/config/) version of VuePress you use. |
| 40 | + |
| 41 | +Once done, you only need to include the files generated by ***phpDocumentor*** in your sidebar as you like. |
| 42 | + |
| 43 | +This template generates this files: |
| 44 | + |
| 45 | +- `README.md`: Introduction to your API documentation. [extra] |
| 46 | +- `classes.md`: Documentation of your classes. |
| 47 | +- `interfaces.md`: Documentation of your interfaces. |
| 48 | +- `traits.md`: Documentation of your traits. |
| 49 | +- `functions.md`: Documentation of your global/namespaced functions. |
| 50 | +- `constants.md`: Documentation of your global/namespaced constants. |
| 51 | + |
| 52 | + |
| 53 | +### Example |
| 54 | + |
| 55 | +Here is the explained VuePress configuration for this project. Use it as example and guide: |
| 56 | + |
| 57 | +<<< @/docs/.vuepress/config.js |
| 58 | + |
| 59 | + |
| 60 | +Then, you can just run `vuepress build docs`. |
| 61 | + |
| 62 | +::: tip |
| 63 | +If you installed VuePress as project dependency, you can configure scripts in your `package.json`: |
| 64 | + |
| 65 | +```json |
| 66 | +{ |
| 67 | + "scripts": { |
| 68 | + "docs:dev": "vuepress dev docs", |
| 69 | + "docs:build": "vuepress build docs" |
74 | 70 | }
|
75 | 71 | }
|
76 | 72 | ```
|
77 | 73 |
|
78 |
| -> Read mor about recommended directory structure at [https://vuepress.vuejs.org/guide/directory-structure.html](https://vuepress.vuejs.org/guide/directory-structure.html) |
| 74 | +And then just run `yarn docs:build` :sunglasses:. |
| 75 | +::: |
| 76 | + |
| 77 | +> Read about recommended directory structure at [https://vuepress.vuejs.org/guide/directory-structure.html](https://vuepress.vuejs.org/guide/directory-structure.html) |
| 78 | +
|
| 79 | + |
| 80 | +::: warning |
| 81 | +You can use any directory as the target for your API, but you need to use the same route level for them in order link references work. For example, all under '/demo/' as the above example. |
| 82 | +::: |
| 83 | + |
| 84 | + |
| 85 | +## Extras |
| 86 | + |
| 87 | +### Running `phpDocumentor` without a configuration file |
| 88 | + |
| 89 | +Is not recommended, but for small projects (not using many directories), you can build your documentation without a configuration file by passing the arguments to the `phpdoc` command directly. |
| 90 | + |
| 91 | +For example, if your code is under `demo/` directory and your VuePress resides in `docs/`, and your route `/api/`, you may use: |
| 92 | + |
| 93 | +``` |
| 94 | +$ phpdoc -d demo/ -t docs/api/ --template=vendor/nelson6e65/phpdoc-vuepress/data/templates/vuepress |
| 95 | +``` |
| 96 | + |
| 97 | +::: warning |
| 98 | +The target directory (`-t`) will be used by phpDocumentor as cache too, so there will be some extra files populating your documentation directory. In order to avoid this, use the `--cache-folder` option. |
| 99 | +::: |
| 100 | + |
| 101 | +::: tip |
| 102 | +You can add the command as Composer script: |
| 103 | + |
| 104 | +```json |
| 105 | +"scripts": { |
| 106 | + "phpdoc": [ |
| 107 | + "phpdoc -d demo/ -t docs/api/ --template=vendor/nelson6e65/phpdoc-vuepress/data/templates/vuepress --ansi" |
| 108 | + ] |
| 109 | +}, |
| 110 | +``` |
| 111 | + |
| 112 | +And then just run `composer phpdoc` :sunglasses:. |
| 113 | + |
| 114 | +::: |
79 | 115 |
|
80 |
| -> You can use [`docs/.vuepress/config.js`](https://github.com/nelson6e65/phpdoc-vuepress/blob/master/docs/.vuepress/config.js) used in this repo as an example. |
| 116 | +> For further information, check the [Runing phpDocumentor documentation](https://docs.phpdoc.org/guides/running-phpdocumentor.html). |
0 commit comments