-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e3f0f0
commit 9898e76
Showing
2,277 changed files
with
296,523 additions
and
15 deletions.
There are no files selected for viewing
Submodule DocGenerator
deleted from
fd0390
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: Unit tests, static analysis and code style | ||
|
||
on: | ||
push: | ||
branches: | ||
- develop | ||
- 'release/**' | ||
- 'hotfix/**' | ||
tags: ['**'] | ||
pull_request: | ||
types: | ||
- opened | ||
- reopened | ||
- synchronize | ||
- ready_for_review | ||
|
||
jobs: | ||
run-tests: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
php-version: ['8.0', '8.1'] | ||
steps: | ||
- uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php-version }} | ||
- uses: actions/checkout@v3 | ||
- name: Cache Composer packages | ||
id: composer-cache | ||
uses: actions/cache@v3 | ||
with: | ||
path: vendor | ||
key: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ hashFiles('**/composer.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-php-${{ matrix.php-version }}- | ||
- name: Install Dependencies | ||
run: composer install --no-scripts --no-ansi --no-interaction --no-progress | ||
- name: Run PHP Code Sniffer | ||
run: vendor/bin/phpcs -p ./src | ||
- name: Run PHPStan | ||
run: vendor/bin/phpstan analyse --no-progress -c phpstan.neon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
composer.phar | ||
/vendor/ | ||
|
||
report.txt | ||
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control | ||
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file | ||
composer.lock | ||
.phpcs-cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
language: php | ||
sudo: required | ||
php: | ||
- 8.0 | ||
- 8.1 | ||
- nightly | ||
install: | ||
- curl -s http://getcomposer.org/installer | php | ||
- php composer.phar install --dev --no-interaction | ||
script: | ||
- vendor/bin/phpcs --report=full --report-file=./report.txt -p ./ | ||
- vendor/bin/phpstan analyse -c phpstan.neon | ||
jobs: | ||
allow_failures: | ||
- php: nightly |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
## 2.0.0 (2022-06-28) | ||
|
||
### Features | ||
|
||
* Removed *Pimple* dependency, psr12 and code smell ([e3065f0](https://github.com/roadiz/doc-generator/commit/e3065f063bc2c4194868584d03903e197f7bdaed)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Ambroise Maupate and Julien Blanchet | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
test: | ||
vendor/bin/phpcs --report=full --report-file=./report.txt -p ./ | ||
vendor/bin/phpstan analyse -c phpstan.neon | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# doc-generator | ||
Roadiz sub-package which generates Markdown documentation skeleton based on your schema | ||
|
||
[![Unit tests, static analysis and code style](https://github.com/roadiz/doc-generator/actions/workflows/run-test.yml/badge.svg?branch=develop)](https://github.com/roadiz/doc-generator/actions/workflows/run-test.yml) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"name": "roadiz/doc-generator", | ||
"description": "Roadiz sub-package which generates Markdown documentation skeleton based on your schema", | ||
"type": "library", | ||
"require": { | ||
"php": ">=8.0", | ||
"roadiz/nodetype-contracts": "~1.1.2", | ||
"symfony/translation": "5.4.*", | ||
"symfony/http-foundation": "5.4.*" | ||
}, | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Ambroise Maupate", | ||
"email": "ambroise@roadiz.io", | ||
"homepage": "https://www.roadiz.io", | ||
"role": "Lead developer" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"RZ\\Roadiz\\Documentation\\": "src/" | ||
} | ||
}, | ||
"require-dev": { | ||
"phpstan/phpstan": "^1.5.3", | ||
"squizlabs/php_codesniffer": "^3.5" | ||
}, | ||
"extra": { | ||
"branch-alias": { | ||
"dev-main": "2.0.x-dev", | ||
"dev-develop": "2.1.x-dev" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd"> | ||
|
||
<arg name="basepath" value="."/> | ||
<arg name="cache" value=".phpcs-cache"/> | ||
<arg name="colors"/> | ||
<arg name="extensions" value="php"/> | ||
|
||
<rule ref="PSR12"> | ||
<exclude name="Generic.Files.LineLength"/> | ||
</rule> | ||
<file>./src</file> | ||
<exclude-pattern>*/node_modules</exclude-pattern> | ||
<exclude-pattern>*/.AppleDouble</exclude-pattern> | ||
<exclude-pattern>*/vendor</exclude-pattern> | ||
</ruleset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
parameters: | ||
level: max | ||
paths: | ||
- src | ||
reportUnmatchedIgnoredErrors: false | ||
checkGenericClassInNonGenericObjectType: false | ||
checkMissingIterableValueType: false |
68 changes: 68 additions & 0 deletions
68
lib/DocGenerator/src/Generators/AbstractFieldGenerator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RZ\Roadiz\Documentation\Generators; | ||
|
||
use RZ\Roadiz\Contracts\NodeType\NodeTypeFieldInterface; | ||
use Symfony\Component\HttpFoundation\ParameterBag; | ||
use Symfony\Contracts\Translation\TranslatorInterface; | ||
|
||
abstract class AbstractFieldGenerator | ||
{ | ||
protected NodeTypeFieldInterface $field; | ||
protected TranslatorInterface $translator; | ||
protected ParameterBag $nodeTypesBag; | ||
protected MarkdownGeneratorFactory $markdownGeneratorFactory; | ||
|
||
/** | ||
* @param MarkdownGeneratorFactory $fieldGeneratorFactory | ||
* @param NodeTypeFieldInterface $field | ||
* @param ParameterBag $nodeTypesBag | ||
* @param TranslatorInterface $translator | ||
*/ | ||
public function __construct( | ||
MarkdownGeneratorFactory $fieldGeneratorFactory, | ||
NodeTypeFieldInterface $field, | ||
ParameterBag $nodeTypesBag, | ||
TranslatorInterface $translator | ||
) { | ||
$this->field = $field; | ||
$this->nodeTypesBag = $nodeTypesBag; | ||
$this->translator = $translator; | ||
$this->markdownGeneratorFactory = $fieldGeneratorFactory; | ||
} | ||
|
||
abstract public function getContents(): string; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getIntroduction(): string | ||
{ | ||
$lines = [ | ||
'### ' . $this->field->getLabel(), | ||
]; | ||
if (!empty($this->field->getDescription())) { | ||
$lines[] = $this->field->getDescription(); | ||
} | ||
$lines = array_merge($lines, [ | ||
'', | ||
'| | |', | ||
'| --- | --- |', | ||
'| **' . trim($this->translator->trans('docs.type')) . '** | ' . $this->translator->trans($this->field->getTypeName()) . ' |', | ||
'| **' . trim($this->translator->trans('docs.technical_name')) . '** | `' . $this->field->getVarName() . '` |', | ||
'| **' . trim($this->translator->trans('docs.universal')) . '** | *' . $this->markdownGeneratorFactory->getHumanBool($this->field->isUniversal()) . '* |', | ||
]); | ||
|
||
if (!empty($this->field->getGroupName())) { | ||
$lines[] = '| **' . trim($this->translator->trans('docs.group')) . '** | ' . $this->field->getGroupName() . ' |'; | ||
} | ||
|
||
if (!$this->field->isVisible()) { | ||
$lines[] = '| **' . trim($this->translator->trans('docs.visible')) . '** | *' . $this->markdownGeneratorFactory->getHumanBool($this->field->isVisible()) . '* |'; | ||
} | ||
|
||
return implode("\n", $lines) . "\n"; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
lib/DocGenerator/src/Generators/ChildrenNodeFieldGenerator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RZ\Roadiz\Documentation\Generators; | ||
|
||
use RZ\Roadiz\Contracts\NodeType\NodeTypeInterface; | ||
|
||
class ChildrenNodeFieldGenerator extends AbstractFieldGenerator | ||
{ | ||
public function getContents(): string | ||
{ | ||
return implode("\n\n", [ | ||
$this->getIntroduction(), | ||
'#### ' . $this->translator->trans('docs.available_children_blocks'), | ||
$this->getAvailableChildren() | ||
]); | ||
} | ||
|
||
/** | ||
* @return array<NodeTypeInterface> | ||
*/ | ||
protected function getChildrenNodeTypes(): array | ||
{ | ||
if (null !== $this->field->getDefaultValues()) { | ||
return array_filter(array_map(function (string $nodeTypeName) { | ||
$nodeType = $this->nodeTypesBag->get(trim($nodeTypeName)); | ||
return $nodeType instanceof NodeTypeInterface ? $nodeType : null; | ||
}, explode(',', $this->field->getDefaultValues()))); | ||
} | ||
return []; | ||
} | ||
|
||
protected function getAvailableChildren(): string | ||
{ | ||
return implode("\n", array_map(function (NodeTypeInterface $nodeType) { | ||
$nodeTypeGenerator = $this->markdownGeneratorFactory->createForNodeType($nodeType); | ||
return implode("\n", [ | ||
'* **' . trim($nodeTypeGenerator->getMenuEntry()) . '** ', | ||
$nodeType->getDescription(), | ||
]); | ||
}, $this->getChildrenNodeTypes())) . "\n"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RZ\Roadiz\Documentation\Generators; | ||
|
||
final class CommonFieldGenerator extends AbstractFieldGenerator | ||
{ | ||
public function getContents(): string | ||
{ | ||
return implode("\n\n", [ | ||
$this->getIntroduction() | ||
]); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
lib/DocGenerator/src/Generators/DefaultValuedFieldGenerator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RZ\Roadiz\Documentation\Generators; | ||
|
||
final class DefaultValuedFieldGenerator extends AbstractFieldGenerator | ||
{ | ||
public function getContents(): string | ||
{ | ||
return implode("\n\n", [ | ||
$this->getIntroduction(), | ||
$this->getDefaultValues() | ||
]); | ||
} | ||
|
||
private function getDefaultValues(): string | ||
{ | ||
return implode("\n", array_map(function (string $value) { | ||
return implode("\n", [ | ||
'* **' . trim($this->translator->trans(trim($value))) . '** `' . $value . '`', | ||
]); | ||
}, explode(',', $this->field->getDefaultValues() ?? ''))) . "\n"; | ||
} | ||
} |
Oops, something went wrong.