From 787e87b5babcad3b7153a64c8f562f0507ddd185 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Fri, 12 Jul 2024 15:10:35 +0200 Subject: [PATCH 01/30] Introduce phpdoc guides builder I introduced an interface to be able to switch between the different implementations. The first setup of guides is done at the required locations and allows us to render the documentation. However this doesn't work yet without issues. More might be needed consider this work in progress. --- composer.json | 3 + composer.lock | 1029 ++++++++++++++++++++++++++- config/services.xml | 7 + config/services/rst-parser.xml | 4 + lib/Application.php | 9 + lib/Docs/BuildDocs.php | 1 + lib/Docs/RST/BuilderInterface.php | 15 + lib/Docs/RST/DoctrineRSTBuilder.php | 36 + lib/Docs/RST/Guides.php | 66 ++ lib/Docs/RST/Logger.php | 15 + lib/Docs/RST/RSTBuilder.php | 10 +- lib/WebsiteBuilder.php | 22 +- 12 files changed, 1181 insertions(+), 36 deletions(-) create mode 100644 lib/Docs/RST/BuilderInterface.php create mode 100644 lib/Docs/RST/DoctrineRSTBuilder.php create mode 100644 lib/Docs/RST/Guides.php create mode 100644 lib/Docs/RST/Logger.php diff --git a/composer.json b/composer.json index 1602d01c..6be426d8 100644 --- a/composer.json +++ b/composer.json @@ -21,6 +21,9 @@ "erusev/parsedown": "^1.7", "knplabs/github-api": "^3.9", "php-http/guzzle7-adapter": "^1.0", + "phpdocumentor/guides": "^1.3", + "phpdocumentor/guides-code": "^1.0", + "phpdocumentor/guides-restructured-text": "^1.3", "scrivo/highlight.php": "^9.18", "symfony/cache": "^6.4", "symfony/config": "^6.4", diff --git a/composer.lock b/composer.lock index 15e54b59..4b0e41bd 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ec98ddcba45e7d0d36d1ac29d8038f18", + "content-hash": "db9fbeed65aeaab41437a2f44c6039b5", "packages": [ { "name": "algolia/algoliasearch-client-php", @@ -1497,6 +1497,473 @@ ], "time": "2023-11-19T21:08:19+00:00" }, + { + "name": "league/csv", + "version": "9.16.0", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/csv.git", + "reference": "998280c6c34bd67d8125fdc8b45bae28d761b440" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/csv/zipball/998280c6c34bd67d8125fdc8b45bae28d761b440", + "reference": "998280c6c34bd67d8125fdc8b45bae28d761b440", + "shasum": "" + }, + "require": { + "ext-filter": "*", + "php": "^8.1.2" + }, + "require-dev": { + "doctrine/collections": "^2.2.2", + "ext-dom": "*", + "ext-xdebug": "*", + "friendsofphp/php-cs-fixer": "^3.57.1", + "phpbench/phpbench": "^1.2.15", + "phpstan/phpstan": "^1.11.1", + "phpstan/phpstan-deprecation-rules": "^1.2.0", + "phpstan/phpstan-phpunit": "^1.4.0", + "phpstan/phpstan-strict-rules": "^1.6.0", + "phpunit/phpunit": "^10.5.16 || ^11.1.3", + "symfony/var-dumper": "^6.4.6 || ^7.0.7" + }, + "suggest": { + "ext-dom": "Required to use the XMLConverter and the HTMLConverter classes", + "ext-iconv": "Needed to ease transcoding CSV using iconv stream filters", + "ext-mbstring": "Needed to ease transcoding CSV using mb stream filters" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "9.x-dev" + } + }, + "autoload": { + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "League\\Csv\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ignace Nyamagana Butera", + "email": "nyamsprod@gmail.com", + "homepage": "https://github.com/nyamsprod/", + "role": "Developer" + } + ], + "description": "CSV data manipulation made easy in PHP", + "homepage": "https://csv.thephpleague.com", + "keywords": [ + "convert", + "csv", + "export", + "filter", + "import", + "read", + "transform", + "write" + ], + "support": { + "docs": "https://csv.thephpleague.com", + "issues": "https://github.com/thephpleague/csv/issues", + "rss": "https://github.com/thephpleague/csv/releases.atom", + "source": "https://github.com/thephpleague/csv" + }, + "funding": [ + { + "url": "https://github.com/sponsors/nyamsprod", + "type": "github" + } + ], + "time": "2024-05-24T11:04:54+00:00" + }, + { + "name": "league/flysystem", + "version": "1.1.10", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/flysystem.git", + "reference": "3239285c825c152bcc315fe0e87d6b55f5972ed1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/3239285c825c152bcc315fe0e87d6b55f5972ed1", + "reference": "3239285c825c152bcc315fe0e87d6b55f5972ed1", + "shasum": "" + }, + "require": { + "ext-fileinfo": "*", + "league/mime-type-detection": "^1.3", + "php": "^7.2.5 || ^8.0" + }, + "conflict": { + "league/flysystem-sftp": "<1.0.6" + }, + "require-dev": { + "phpspec/prophecy": "^1.11.1", + "phpunit/phpunit": "^8.5.8" + }, + "suggest": { + "ext-ftp": "Allows you to use FTP server storage", + "ext-openssl": "Allows you to use FTPS server storage", + "league/flysystem-aws-s3-v2": "Allows you to use S3 storage with AWS SDK v2", + "league/flysystem-aws-s3-v3": "Allows you to use S3 storage with AWS SDK v3", + "league/flysystem-azure": "Allows you to use Windows Azure Blob storage", + "league/flysystem-cached-adapter": "Flysystem adapter decorator for metadata caching", + "league/flysystem-eventable-filesystem": "Allows you to use EventableFilesystem", + "league/flysystem-rackspace": "Allows you to use Rackspace Cloud Files", + "league/flysystem-sftp": "Allows you to use SFTP server storage via phpseclib", + "league/flysystem-webdav": "Allows you to use WebDAV storage", + "league/flysystem-ziparchive": "Allows you to use ZipArchive adapter", + "spatie/flysystem-dropbox": "Allows you to use Dropbox storage", + "srmklive/flysystem-dropbox-v2": "Allows you to use Dropbox storage for PHP 5 applications" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "psr-4": { + "League\\Flysystem\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Frank de Jonge", + "email": "info@frenky.net" + } + ], + "description": "Filesystem abstraction: Many filesystems, one API.", + "keywords": [ + "Cloud Files", + "WebDAV", + "abstraction", + "aws", + "cloud", + "copy.com", + "dropbox", + "file systems", + "files", + "filesystem", + "filesystems", + "ftp", + "rackspace", + "remote", + "s3", + "sftp", + "storage" + ], + "support": { + "issues": "https://github.com/thephpleague/flysystem/issues", + "source": "https://github.com/thephpleague/flysystem/tree/1.1.10" + }, + "funding": [ + { + "url": "https://offset.earth/frankdejonge", + "type": "other" + } + ], + "time": "2022-10-04T09:16:37+00:00" + }, + { + "name": "league/mime-type-detection", + "version": "1.15.0", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/mime-type-detection.git", + "reference": "ce0f4d1e8a6f4eb0ddff33f57c69c50fd09f4301" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/mime-type-detection/zipball/ce0f4d1e8a6f4eb0ddff33f57c69c50fd09f4301", + "reference": "ce0f4d1e8a6f4eb0ddff33f57c69c50fd09f4301", + "shasum": "" + }, + "require": { + "ext-fileinfo": "*", + "php": "^7.4 || ^8.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.2", + "phpstan/phpstan": "^0.12.68", + "phpunit/phpunit": "^8.5.8 || ^9.3 || ^10.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "League\\MimeTypeDetection\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Frank de Jonge", + "email": "info@frankdejonge.nl" + } + ], + "description": "Mime-type detection for Flysystem", + "support": { + "issues": "https://github.com/thephpleague/mime-type-detection/issues", + "source": "https://github.com/thephpleague/mime-type-detection/tree/1.15.0" + }, + "funding": [ + { + "url": "https://github.com/frankdejonge", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/league/flysystem", + "type": "tidelift" + } + ], + "time": "2024-01-28T23:22:08+00:00" + }, + { + "name": "league/tactician", + "version": "v1.1.0", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/tactician.git", + "reference": "e79f763170f3d5922ec29e85cffca0bac5cd8975" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/tactician/zipball/e79f763170f3d5922ec29e85cffca0bac5cd8975", + "reference": "e79f763170f3d5922ec29e85cffca0bac5cd8975", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "require-dev": { + "mockery/mockery": "^1.3", + "phpunit/phpunit": "^7.5.20 || ^9.3.8", + "squizlabs/php_codesniffer": "^3.5.8" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "psr-4": { + "League\\Tactician\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ross Tuck", + "homepage": "http://tactician.thephpleague.com" + } + ], + "description": "A small, flexible command bus. Handy for building service layers.", + "keywords": [ + "command", + "command bus", + "service layer" + ], + "support": { + "issues": "https://github.com/thephpleague/tactician/issues", + "source": "https://github.com/thephpleague/tactician/tree/v1.1.0" + }, + "time": "2021-02-14T15:29:04+00:00" + }, + { + "name": "league/uri", + "version": "7.4.1", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/uri.git", + "reference": "bedb6e55eff0c933668addaa7efa1e1f2c417cc4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/uri/zipball/bedb6e55eff0c933668addaa7efa1e1f2c417cc4", + "reference": "bedb6e55eff0c933668addaa7efa1e1f2c417cc4", + "shasum": "" + }, + "require": { + "league/uri-interfaces": "^7.3", + "php": "^8.1" + }, + "conflict": { + "league/uri-schemes": "^1.0" + }, + "suggest": { + "ext-bcmath": "to improve IPV4 host parsing", + "ext-fileinfo": "to create Data URI from file contennts", + "ext-gmp": "to improve IPV4 host parsing", + "ext-intl": "to handle IDN host with the best performance", + "jeremykendall/php-domain-parser": "to resolve Public Suffix and Top Level Domain", + "league/uri-components": "Needed to easily manipulate URI objects components", + "php-64bit": "to improve IPV4 host parsing", + "symfony/polyfill-intl-idn": "to handle IDN host via the Symfony polyfill if ext-intl is not present" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "7.x-dev" + } + }, + "autoload": { + "psr-4": { + "League\\Uri\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ignace Nyamagana Butera", + "email": "nyamsprod@gmail.com", + "homepage": "https://nyamsprod.com" + } + ], + "description": "URI manipulation library", + "homepage": "https://uri.thephpleague.com", + "keywords": [ + "data-uri", + "file-uri", + "ftp", + "hostname", + "http", + "https", + "middleware", + "parse_str", + "parse_url", + "psr-7", + "query-string", + "querystring", + "rfc3986", + "rfc3987", + "rfc6570", + "uri", + "uri-template", + "url", + "ws" + ], + "support": { + "docs": "https://uri.thephpleague.com", + "forum": "https://thephpleague.slack.com", + "issues": "https://github.com/thephpleague/uri-src/issues", + "source": "https://github.com/thephpleague/uri/tree/7.4.1" + }, + "funding": [ + { + "url": "https://github.com/sponsors/nyamsprod", + "type": "github" + } + ], + "time": "2024-03-23T07:42:40+00:00" + }, + { + "name": "league/uri-interfaces", + "version": "7.4.1", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/uri-interfaces.git", + "reference": "8d43ef5c841032c87e2de015972c06f3865ef718" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/uri-interfaces/zipball/8d43ef5c841032c87e2de015972c06f3865ef718", + "reference": "8d43ef5c841032c87e2de015972c06f3865ef718", + "shasum": "" + }, + "require": { + "ext-filter": "*", + "php": "^8.1", + "psr/http-factory": "^1", + "psr/http-message": "^1.1 || ^2.0" + }, + "suggest": { + "ext-bcmath": "to improve IPV4 host parsing", + "ext-gmp": "to improve IPV4 host parsing", + "ext-intl": "to handle IDN host with the best performance", + "php-64bit": "to improve IPV4 host parsing", + "symfony/polyfill-intl-idn": "to handle IDN host via the Symfony polyfill if ext-intl is not present" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "7.x-dev" + } + }, + "autoload": { + "psr-4": { + "League\\Uri\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ignace Nyamagana Butera", + "email": "nyamsprod@gmail.com", + "homepage": "https://nyamsprod.com" + } + ], + "description": "Common interfaces and classes for URI representation and interaction", + "homepage": "https://uri.thephpleague.com", + "keywords": [ + "data-uri", + "file-uri", + "ftp", + "hostname", + "http", + "https", + "parse_str", + "parse_url", + "psr-7", + "query-string", + "querystring", + "rfc3986", + "rfc3987", + "rfc6570", + "uri", + "url", + "ws" + ], + "support": { + "docs": "https://uri.thephpleague.com", + "forum": "https://thephpleague.slack.com", + "issues": "https://github.com/thephpleague/uri-src/issues", + "source": "https://github.com/thephpleague/uri-interfaces/tree/7.4.1" + }, + "funding": [ + { + "url": "https://github.com/sponsors/nyamsprod", + "type": "github" + } + ], + "time": "2024-03-23T07:42:40+00:00" + }, { "name": "php-http/cache-plugin", "version": "1.8.1", @@ -2049,32 +2516,253 @@ }, "time": "2023-11-08T12:57:08+00:00" }, + { + "name": "phpdocumentor/flyfinder", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/FlyFinder.git", + "reference": "6e145e676d9fbade7527fd8d4c99ab36b687b958" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/FlyFinder/zipball/6e145e676d9fbade7527fd8d4c99ab36b687b958", + "reference": "6e145e676d9fbade7527fd8d4c99ab36b687b958", + "shasum": "" + }, + "require": { + "league/flysystem": "^1.0", + "php": "^7.2||^8.0" + }, + "require-dev": { + "league/flysystem-memory": "~1", + "mockery/mockery": "^1.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Flyfinder\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Flysystem plugin to add file finding capabilities to the Filesystem entity", + "homepage": "http://www.phpdoc.org", + "keywords": [ + "Flysystem", + "phpdoc" + ], + "support": { + "issues": "https://github.com/phpDocumentor/FlyFinder/issues", + "source": "https://github.com/phpDocumentor/FlyFinder/tree/1.1.0" + }, + "time": "2021-06-04T13:44:40+00:00" + }, + { + "name": "phpdocumentor/guides", + "version": "1.3.5", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/guides-core.git", + "reference": "c6766d529735adf8d1b32c8b1c0169aaf448e565" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/guides-core/zipball/c6766d529735adf8d1b32c8b1c0169aaf448e565", + "reference": "c6766d529735adf8d1b32c8b1c0169aaf448e565", + "shasum": "" + }, + "require": { + "doctrine/deprecations": "^1.0", + "ext-json": "*", + "ext-zlib": "*", + "league/flysystem": "^1.1", + "league/tactician": "^1.1", + "league/uri": "^6.5 || ^7.0", + "php": "^8.1", + "phpdocumentor/flyfinder": "^1.1", + "psr/event-dispatcher": "^1.0", + "symfony/clock": "^6.4.3", + "symfony/http-client": "^6.4.4", + "symfony/string": "^5.4 || ^6.3 || ^7.0", + "symfony/translation-contracts": "^3.4.1", + "twig/twig": "~2.15 || ^3.0", + "webmozart/assert": "^1.11" + }, + "require-dev": { + "psr/log": "^2.0 || ^3.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "phpDocumentor\\Guides\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Contains the core functionality from the phpDocumentor Guides.", + "homepage": "https://www.phpdoc.org", + "support": { + "issues": "https://github.com/phpDocumentor/guides-core/issues", + "source": "https://github.com/phpDocumentor/guides-core/tree/1.3.5" + }, + "time": "2024-05-07T18:12:18+00:00" + }, + { + "name": "phpdocumentor/guides-code", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/guides-code.git", + "reference": "f6aefca78d3a9b56d36202bfdbf8239a6d254b74" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/guides-code/zipball/f6aefca78d3a9b56d36202bfdbf8239a6d254b74", + "reference": "f6aefca78d3a9b56d36202bfdbf8239a6d254b74", + "shasum": "" + }, + "require": { + "php": "^8.1", + "scrivo/highlight.php": "^9.18.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "phpDocumentor\\Guides\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A library to provide code-related functionality to phpDocumentor's Guides", + "homepage": "https://www.phpdoc.org", + "support": { + "issues": "https://github.com/phpDocumentor/guides-code/issues", + "source": "https://github.com/phpDocumentor/guides-code/tree/1.0.0" + }, + "time": "2024-03-03T20:57:20+00:00" + }, + { + "name": "phpdocumentor/guides-restructured-text", + "version": "1.3.8", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/guides-restructured-text.git", + "reference": "916a09f05adb85763aa23bb2c1db86d35214e6aa" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/guides-restructured-text/zipball/916a09f05adb85763aa23bb2c1db86d35214e6aa", + "reference": "916a09f05adb85763aa23bb2c1db86d35214e6aa", + "shasum": "" + }, + "require": { + "doctrine/lexer": "^3.0", + "league/csv": "^9.10.0", + "php": "^8.1", + "phpdocumentor/guides": "^1.0", + "webmozart/assert": "^1.11" + }, + "type": "library", + "autoload": { + "psr-4": { + "phpDocumentor\\Guides\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Adds reStructuredText Markup support to the phpDocumentor's Guides library.", + "homepage": "https://www.phpdoc.org", + "support": { + "source": "https://github.com/phpDocumentor/guides-restructured-text/tree/1.3.8" + }, + "time": "2024-05-19T20:03:16+00:00" + }, { "name": "psr/cache", "version": "3.0.0", "source": { "type": "git", - "url": "https://github.com/php-fig/cache.git", - "reference": "aa5030cfa5405eccfdcb1083ce040c2cb8d253bf" + "url": "https://github.com/php-fig/cache.git", + "reference": "aa5030cfa5405eccfdcb1083ce040c2cb8d253bf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/cache/zipball/aa5030cfa5405eccfdcb1083ce040c2cb8d253bf", + "reference": "aa5030cfa5405eccfdcb1083ce040c2cb8d253bf", + "shasum": "" + }, + "require": { + "php": ">=8.0.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Cache\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for caching libraries", + "keywords": [ + "cache", + "psr", + "psr-6" + ], + "support": { + "source": "https://github.com/php-fig/cache/tree/3.0.0" + }, + "time": "2021-02-03T23:26:27+00:00" + }, + { + "name": "psr/clock", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/clock.git", + "reference": "e41a24703d4560fd0acb709162f73b8adfc3aa0d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/cache/zipball/aa5030cfa5405eccfdcb1083ce040c2cb8d253bf", - "reference": "aa5030cfa5405eccfdcb1083ce040c2cb8d253bf", + "url": "https://api.github.com/repos/php-fig/clock/zipball/e41a24703d4560fd0acb709162f73b8adfc3aa0d", + "reference": "e41a24703d4560fd0acb709162f73b8adfc3aa0d", "shasum": "" }, "require": { - "php": ">=8.0.0" + "php": "^7.0 || ^8.0" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, "autoload": { "psr-4": { - "Psr\\Cache\\": "src/" + "Psr\\Clock\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -2087,16 +2775,20 @@ "homepage": "https://www.php-fig.org/" } ], - "description": "Common interface for caching libraries", + "description": "Common interface for reading the clock.", + "homepage": "https://github.com/php-fig/clock", "keywords": [ - "cache", + "clock", + "now", "psr", - "psr-6" + "psr-20", + "time" ], "support": { - "source": "https://github.com/php-fig/cache/tree/3.0.0" + "issues": "https://github.com/php-fig/clock/issues", + "source": "https://github.com/php-fig/clock/tree/1.0.0" }, - "time": "2021-02-03T23:26:27+00:00" + "time": "2022-11-25T14:36:26+00:00" }, { "name": "psr/container", @@ -2756,6 +3448,80 @@ ], "time": "2024-04-18T09:32:20+00:00" }, + { + "name": "symfony/clock", + "version": "v6.4.8", + "source": { + "type": "git", + "url": "https://github.com/symfony/clock.git", + "reference": "7a4840efd17135cbd547e41ec49fb910ed4f8b98" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/clock/zipball/7a4840efd17135cbd547e41ec49fb910ed4f8b98", + "reference": "7a4840efd17135cbd547e41ec49fb910ed4f8b98", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "psr/clock": "^1.0", + "symfony/polyfill-php83": "^1.28" + }, + "provide": { + "psr/clock-implementation": "1.0" + }, + "type": "library", + "autoload": { + "files": [ + "Resources/now.php" + ], + "psr-4": { + "Symfony\\Component\\Clock\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Decouples applications from the system clock", + "homepage": "https://symfony.com", + "keywords": [ + "clock", + "psr20", + "time" + ], + "support": { + "source": "https://github.com/symfony/clock/tree/v6.4.8" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-05-31T14:51:39+00:00" + }, { "name": "symfony/config", "version": "v6.4.0", @@ -3434,6 +4200,177 @@ ], "time": "2024-05-31T14:49:08+00:00" }, + { + "name": "symfony/http-client", + "version": "v6.4.9", + "source": { + "type": "git", + "url": "https://github.com/symfony/http-client.git", + "reference": "6e9db0025db565bcf8f1d46ed734b549e51e6045" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/http-client/zipball/6e9db0025db565bcf8f1d46ed734b549e51e6045", + "reference": "6e9db0025db565bcf8f1d46ed734b549e51e6045", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "psr/log": "^1|^2|^3", + "symfony/deprecation-contracts": "^2.5|^3", + "symfony/http-client-contracts": "^3.4.1", + "symfony/service-contracts": "^2.5|^3" + }, + "conflict": { + "php-http/discovery": "<1.15", + "symfony/http-foundation": "<6.3" + }, + "provide": { + "php-http/async-client-implementation": "*", + "php-http/client-implementation": "*", + "psr/http-client-implementation": "1.0", + "symfony/http-client-implementation": "3.0" + }, + "require-dev": { + "amphp/amp": "^2.5", + "amphp/http-client": "^4.2.1", + "amphp/http-tunnel": "^1.0", + "amphp/socket": "^1.1", + "guzzlehttp/promises": "^1.4|^2.0", + "nyholm/psr7": "^1.0", + "php-http/httplug": "^1.0|^2.0", + "psr/http-client": "^1.0", + "symfony/dependency-injection": "^5.4|^6.0|^7.0", + "symfony/http-kernel": "^5.4|^6.0|^7.0", + "symfony/messenger": "^5.4|^6.0|^7.0", + "symfony/process": "^5.4|^6.0|^7.0", + "symfony/stopwatch": "^5.4|^6.0|^7.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\HttpClient\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides powerful methods to fetch HTTP resources synchronously or asynchronously", + "homepage": "https://symfony.com", + "keywords": [ + "http" + ], + "support": { + "source": "https://github.com/symfony/http-client/tree/v6.4.9" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-06-28T07:59:05+00:00" + }, + { + "name": "symfony/http-client-contracts", + "version": "v3.5.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/http-client-contracts.git", + "reference": "20414d96f391677bf80078aa55baece78b82647d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/http-client-contracts/zipball/20414d96f391677bf80078aa55baece78b82647d", + "reference": "20414d96f391677bf80078aa55baece78b82647d", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.5-dev" + }, + "thanks": { + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Contracts\\HttpClient\\": "" + }, + "exclude-from-classmap": [ + "/Test/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Generic abstractions related to HTTP clients", + "homepage": "https://symfony.com", + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "support": { + "source": "https://github.com/symfony/http-client-contracts/tree/v3.5.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-04-18T09:32:20+00:00" + }, { "name": "symfony/http-foundation", "version": "v7.1.1", @@ -4870,6 +5807,64 @@ } ], "time": "2024-05-16T10:04:27+00:00" + }, + { + "name": "webmozart/assert", + "version": "1.11.0", + "source": { + "type": "git", + "url": "https://github.com/webmozarts/assert.git", + "reference": "11cb2199493b2f8a3b53e7f19068fc6aac760991" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/webmozarts/assert/zipball/11cb2199493b2f8a3b53e7f19068fc6aac760991", + "reference": "11cb2199493b2f8a3b53e7f19068fc6aac760991", + "shasum": "" + }, + "require": { + "ext-ctype": "*", + "php": "^7.2 || ^8.0" + }, + "conflict": { + "phpstan/phpstan": "<0.12.20", + "vimeo/psalm": "<4.6.1 || 4.6.2" + }, + "require-dev": { + "phpunit/phpunit": "^8.5.13" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.10-dev" + } + }, + "autoload": { + "psr-4": { + "Webmozart\\Assert\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Assertions to validate method input/output with nice error messages.", + "keywords": [ + "assert", + "check", + "validate" + ], + "support": { + "issues": "https://github.com/webmozarts/assert/issues", + "source": "https://github.com/webmozarts/assert/tree/1.11.0" + }, + "time": "2022-06-03T18:03:27+00:00" } ], "packages-dev": [ diff --git a/config/services.xml b/config/services.xml index a34d872f..e5377bea 100644 --- a/config/services.xml +++ b/config/services.xml @@ -145,5 +145,12 @@ + + + + + + + diff --git a/config/services/rst-parser.xml b/config/services/rst-parser.xml index 5b7c1ec5..3d204562 100644 --- a/config/services/rst-parser.xml +++ b/config/services/rst-parser.xml @@ -52,6 +52,10 @@ + + + + diff --git a/lib/Application.php b/lib/Application.php index 63876346..50ea04a1 100644 --- a/lib/Application.php +++ b/lib/Application.php @@ -10,6 +10,9 @@ use Doctrine\Website\Commands\BuildWebsiteCommand; use Doctrine\Website\Commands\ClearBuildCacheCommand; use Doctrine\Website\Commands\SyncRepositoriesCommand; +use phpDocumentor\Guides\Code\DependencyInjection\CodeExtension; +use phpDocumentor\Guides\DependencyInjection\GuidesExtension; +use phpDocumentor\Guides\RestructuredText\DependencyInjection\ReStructuredTextExtension; use Symfony\Component\Config\FileLocator; use Symfony\Component\Console\Application as BaseApplication; use Symfony\Component\Console\Helper\HelperSet; @@ -85,6 +88,7 @@ public static function getContainer(string $env): ContainerBuilder $container->setParameter('doctrine.website.algolia.admin_api_key', getenv('doctrine_website_algolia_admin_api_key') ?: '1234'); $container->setParameter('doctrine.website.stripe.secret_key', getenv('doctrine_website_stripe_secret_key') ?: ''); $container->setParameter('doctrine.website.send_grid.api_key', getenv('doctrine_website_send_grid_api_key') ?: ''); + $container->setParameter('vendor_dir', realpath(__DIR__ . '/../vendor')); $xmlConfigLoader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../config')); $xmlConfigLoader->load('services.xml'); @@ -100,6 +104,11 @@ public static function getContainer(string $env): ContainerBuilder $yamlConfigLoader->load('local.yml'); } + foreach ([new GuidesExtension(), new ReStructuredTextExtension(), new CodeExtension()] as $extension) { + $container->registerExtension($extension); + $container->loadFromExtension($extension->getAlias()); + } + $container->compile(); date_default_timezone_set('America/New_York'); diff --git a/lib/Docs/BuildDocs.php b/lib/Docs/BuildDocs.php index 05685021..0e53009b 100644 --- a/lib/Docs/BuildDocs.php +++ b/lib/Docs/BuildDocs.php @@ -91,6 +91,7 @@ public function build( $documents = $this->rstBuilder->buildRSTDocs($project, $version, $language); + return; if ($language->getCode() !== RSTLanguagesDetector::ENGLISH_LANGUAGE_CODE) { continue; } diff --git a/lib/Docs/RST/BuilderInterface.php b/lib/Docs/RST/BuilderInterface.php new file mode 100644 index 00000000..3c140697 --- /dev/null +++ b/lib/Docs/RST/BuilderInterface.php @@ -0,0 +1,15 @@ +builder = $this->builder->recreate(); + + // build the docs from the files in $docsDir and write them to $outputPath + // which is contained inside the $sourceDir + $this->builder->build( + $directory, + $targetDirectory, + ); + } + + #[\Override] + public function getDocuments(): array + { + return $this->builder->getDocuments()->getAll(); + } +} diff --git a/lib/Docs/RST/Guides.php b/lib/Docs/RST/Guides.php new file mode 100644 index 00000000..77931327 --- /dev/null +++ b/lib/Docs/RST/Guides.php @@ -0,0 +1,66 @@ +addPlugin(new Finder()); + + $projectNode = new ProjectNode(); + $documents = $this->commandBus->handle( + new ParseDirectoryCommand( + $sourceFileSystem, + '', + 'rst', + $projectNode, + new Glob('/**/sidebar.rst') + ), + ); + + $documents = $this->commandBus->handle( + new CompileDocumentsCommand($documents, new CompilerContext($projectNode)) + ); + + $destinationFileSystem = new Filesystem(new Local($targetDirectory)); + + $this->commandBus->handle( + new RenderCommand( + 'html', + $documents, + $sourceFileSystem, + $destinationFileSystem, + $projectNode, + ), + ); + } + + #[\Override] + public function getDocuments(): array + { + return []; + } +} diff --git a/lib/Docs/RST/Logger.php b/lib/Docs/RST/Logger.php new file mode 100644 index 00000000..44e4b616 --- /dev/null +++ b/lib/Docs/RST/Logger.php @@ -0,0 +1,15 @@ +rstPostBuildProcessor->postRstBuild($project, $version, $language); - return $this->builder->getDocuments()->getAll(); + return $this->builder->getDocuments(); } private function buildRst(Project $project, ProjectVersion $version, RSTLanguage $language): void @@ -46,11 +45,6 @@ private function buildRst(Project $project, ProjectVersion $version, RSTLanguage // clear the files in the output path first $this->filesystem->remove($this->rstFileRepository->findFiles($outputPath)); - // we have to get a fresh builder due to how the RST parser works - $this->builder = $this->builder->recreate(); - - // build the docs from the files in $docsDir and write them to $outputPath - // which is contained inside the $sourceDir $this->builder->build( $project->getProjectVersionDocsPath($this->docsDir, $version, $language->getCode()), $outputPath, diff --git a/lib/WebsiteBuilder.php b/lib/WebsiteBuilder.php index 3c4fd62d..81ed3ef8 100644 --- a/lib/WebsiteBuilder.php +++ b/lib/WebsiteBuilder.php @@ -103,17 +103,17 @@ private function buildWebpackAssets(OutputInterface $output, string $buildDir, b { $output->writeln(sprintf(' - running npm run %s ', $isPublishableEnv ? 'build' : 'dev')); - $this->filesystem->remove((array) glob($this->webpackBuildDir . '/*')); - - $process = $this->processFactory->run(sprintf( - 'cd %s && npm run %s', - $this->rootDir, - $isPublishableEnv ? 'build' : 'dev', - )); - - if ($output->isVerbose()) { - $output->write($process->getOutput()); - } +// $this->filesystem->remove((array) glob($this->webpackBuildDir . '/*')); + +// $process = $this->processFactory->run(sprintf( +// 'cd %s && npm run %s', +// $this->rootDir, +// $isPublishableEnv ? 'build' : 'dev', +// )); +// +// if ($output->isVerbose()) { +// $output->write($process->getOutput()); +// } // Copy built assets if this is a publishable build if ($isPublishableEnv) { From a25281261bd196d6862286c777c6032fd194a7bc Mon Sep 17 00:00:00 2001 From: Jaapio Date: Fri, 16 Aug 2024 17:28:04 +0200 Subject: [PATCH 02/30] Replace post processing --- config/config.yml | 2 +- config/packages/guides.yml | 14 ++++++++++ config/services.xml | 4 +++ lib/Application.php | 11 ++++---- lib/Docs/BuildDocs.php | 1 - lib/Docs/RST/Guides.php | 5 +++- lib/Docs/RST/RSTPostBuildProcessor.php | 1 + lib/Twig/MainExtension.php | 25 ++++++++++++++++++ templates/guides/structure/document.html.twig | 26 +++++++++++++++++++ 9 files changed, 81 insertions(+), 8 deletions(-) create mode 100644 config/packages/guides.yml create mode 100644 templates/guides/structure/document.html.twig diff --git a/config/config.yml b/config/config.yml index 0c0b999d..74ce4215 100644 --- a/config/config.yml +++ b/config/config.yml @@ -13,7 +13,7 @@ parameters: doctrine.website.title: Doctrine doctrine.website.subtitle: PHP Open Source Project - doctrine.website.url: https://lcl.doctrine-project.org + doctrine.website.url: http://lcl.doctrine-project.org doctrine.website.assets_url: https://www.doctrine-project.org doctrine.website.keywords: [php, mysql, orm, dbal, database, mongodb, odm, annotations, migrations, cache, couchdb] doctrine.website.description: > diff --git a/config/packages/guides.yml b/config/packages/guides.yml new file mode 100644 index 00000000..643b18d5 --- /dev/null +++ b/config/packages/guides.yml @@ -0,0 +1,14 @@ +guides: + theme: doctrine + links_are_relative: true + themes: + doctrine: '%doctrine.website.root_dir%/templates/guides' + +code: + aliases: + html+php: php + html+jinja: html + php-annotations: php + php-attributes: php + languages: + diff --git a/config/services.xml b/config/services.xml index e5377bea..0f9b5f68 100644 --- a/config/services.xml +++ b/config/services.xml @@ -146,6 +146,10 @@ + + + + diff --git a/lib/Application.php b/lib/Application.php index 50ea04a1..5802025a 100644 --- a/lib/Application.php +++ b/lib/Application.php @@ -90,6 +90,11 @@ public static function getContainer(string $env): ContainerBuilder $container->setParameter('doctrine.website.send_grid.api_key', getenv('doctrine_website_send_grid_api_key') ?: ''); $container->setParameter('vendor_dir', realpath(__DIR__ . '/../vendor')); + foreach ([new GuidesExtension(), new ReStructuredTextExtension(), new CodeExtension()] as $extension) { + $container->registerExtension($extension); + $container->loadFromExtension($extension->getAlias()); + } + $xmlConfigLoader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../config')); $xmlConfigLoader->load('services.xml'); @@ -97,6 +102,7 @@ public static function getContainer(string $env): ContainerBuilder $yamlConfigLoader->load('routes.yml'); $yamlConfigLoader->load(sprintf('config_%s.yml', $env)); + $yamlConfigLoader->load('packages/guides.yml'); $configDir = $container->getParameter('doctrine.website.config_dir'); assert(is_string($configDir)); @@ -104,11 +110,6 @@ public static function getContainer(string $env): ContainerBuilder $yamlConfigLoader->load('local.yml'); } - foreach ([new GuidesExtension(), new ReStructuredTextExtension(), new CodeExtension()] as $extension) { - $container->registerExtension($extension); - $container->loadFromExtension($extension->getAlias()); - } - $container->compile(); date_default_timezone_set('America/New_York'); diff --git a/lib/Docs/BuildDocs.php b/lib/Docs/BuildDocs.php index 0e53009b..05685021 100644 --- a/lib/Docs/BuildDocs.php +++ b/lib/Docs/BuildDocs.php @@ -91,7 +91,6 @@ public function build( $documents = $this->rstBuilder->buildRSTDocs($project, $version, $language); - return; if ($language->getCode() !== RSTLanguagesDetector::ENGLISH_LANGUAGE_CODE) { continue; } diff --git a/lib/Docs/RST/Guides.php b/lib/Docs/RST/Guides.php index 77931327..73e8e2ad 100644 --- a/lib/Docs/RST/Guides.php +++ b/lib/Docs/RST/Guides.php @@ -14,12 +14,14 @@ use phpDocumentor\Guides\Handlers\ParseDirectoryCommand; use phpDocumentor\Guides\Handlers\RenderCommand; use phpDocumentor\Guides\Nodes\ProjectNode; +use phpDocumentor\Guides\Twig\Theme\ThemeManager; final class Guides implements BuilderInterface { public function __construct( - private readonly CommandBus $commandBus + private readonly CommandBus $commandBus, + private readonly ThemeManager $themeManager ) { } @@ -46,6 +48,7 @@ public function build(string $directory, string $targetDirectory = 'output'): vo ); $destinationFileSystem = new Filesystem(new Local($targetDirectory)); + $this->themeManager->useTheme('doctrine'); $this->commandBus->handle( new RenderCommand( diff --git a/lib/Docs/RST/RSTPostBuildProcessor.php b/lib/Docs/RST/RSTPostBuildProcessor.php index 9cd8211b..da4b3b55 100644 --- a/lib/Docs/RST/RSTPostBuildProcessor.php +++ b/lib/Docs/RST/RSTPostBuildProcessor.php @@ -37,6 +37,7 @@ public function __construct( public function postRstBuild(Project $project, ProjectVersion $version, RSTLanguage $language): void { + return; $projectVersionDocsOutputPath = $project->getProjectVersionDocsOutputPath( $this->sourceDir, $version, diff --git a/lib/Twig/MainExtension.php b/lib/Twig/MainExtension.php index fcba7c3a..2a13984c 100644 --- a/lib/Twig/MainExtension.php +++ b/lib/Twig/MainExtension.php @@ -8,10 +8,13 @@ use Doctrine\Website\Model\Project; use Doctrine\Website\Model\ProjectVersion; use Parsedown; +use phpDocumentor\Guides\Nodes\Menu\TocNode; +use phpDocumentor\Guides\Nodes\Node; use Twig\Extension\AbstractExtension; use Twig\TwigFilter; use Twig\TwigFunction; +use Twig\TwigTest; use function assert; use function file_get_contents; use function is_int; @@ -51,9 +54,19 @@ public function getFilters(): array return [ new TwigFilter('markdown', [$this->parsedown, 'text'], ['is_safe' => ['html']]), new TwigFilter('truncate', [$this, 'truncate']), + new TwigFilter('yaml_encode', [$this, 'yamlEncode']), ]; } + #[\Override] + public function getTests() + { + return [ + new TwigTest('tocNode', [$this, 'isTocNode']), + ]; + } + + public function getSearchBoxPlaceholder(Project|null $project = null, ProjectVersion|null $projectVersion = null): string { if ($project !== null && $projectVersion !== null) { @@ -103,4 +116,16 @@ private function getAssetCacheBuster(string $path, string $rootPath): string return substr(sha1($contents), 0, 6); } + + public function yamlEncode(mixed $value) + { + if (is_string($value)) { + return str_replace('\\', '\\\\', $value); + } + } + + public function isTocNode(Node $node): bool + { + return $node instanceof TocNode; + } } diff --git a/templates/guides/structure/document.html.twig b/templates/guides/structure/document.html.twig new file mode 100644 index 00000000..7f873939 --- /dev/null +++ b/templates/guides/structure/document.html.twig @@ -0,0 +1,26 @@ +--- +title: "{{ node.pageTitle | yaml_encode }}" +docsIndex: {% if node.filePath ends with 'index' %}true{% else %}false{% endif %} + +docsSourcePath: "/en/{{ node.filePath }}.rst" +--- +{% verbatim %} +{% block sidebar %} +{% endverbatim %} + +{{ renderNode(node.tocNodes) }} + + +{% verbatim %} +{% endblock %}{% block content %}{% verbatim %} +{% endverbatim %} + {% for child in node.children -%} + {% if child is not tocNode %} + {{ renderNode(child) }} + {% endif %} + {%~ endfor -%} + +{{ "{% endverbatim %}" }} +{% verbatim %} + {% endblock %} +{% endverbatim %} From 620f05b3c70bb1cbc2d14a1b8feab44336cd758c Mon Sep 17 00:00:00 2001 From: Jaapio Date: Fri, 16 Aug 2024 22:27:26 +0200 Subject: [PATCH 03/30] Add custom code rendering --- config/services.xml | 4 ++ lib/Guides/Renderer/CodeBlockRenderer.php | 52 +++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 lib/Guides/Renderer/CodeBlockRenderer.php diff --git a/config/services.xml b/config/services.xml index 0f9b5f68..5050eaef 100644 --- a/config/services.xml +++ b/config/services.xml @@ -156,5 +156,9 @@ + + + + diff --git a/lib/Guides/Renderer/CodeBlockRenderer.php b/lib/Guides/Renderer/CodeBlockRenderer.php new file mode 100644 index 00000000..808ad966 --- /dev/null +++ b/lib/Guides/Renderer/CodeBlockRenderer.php @@ -0,0 +1,52 @@ +getValue()); + $language = $this->codeBlockLanguageDetector->detectLanguage( + $node->getLanguage(), + $lines + ); + + + + if (in_array($language, self::CONSOLE_LANGUAGES, true)) { + return $this->codeBlockConsoleRenderer->render($lines); + } + + return $this->codeBlockWithLineNumbersRenderer->render( + $lines, + $language, + ); + } +} From 801a75b8367f0635681f018ab31b84539091c4f1 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Fri, 16 Aug 2024 23:18:47 +0200 Subject: [PATCH 04/30] Add improved sidebar handling --- config/services.xml | 4 ++ lib/Guides/Compiler/SidebarTransformer.php | 48 +++++++++++++++++++ templates/guides/body/directive/toc.html.twig | 3 ++ .../guides/body/directive/tocheader.html.twig | 1 + templates/guides/structure/document.html.twig | 7 ++- 5 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 lib/Guides/Compiler/SidebarTransformer.php create mode 100644 templates/guides/body/directive/toc.html.twig create mode 100644 templates/guides/body/directive/tocheader.html.twig diff --git a/config/services.xml b/config/services.xml index 5050eaef..3bf4b6f1 100644 --- a/config/services.xml +++ b/config/services.xml @@ -160,5 +160,9 @@ + + + + diff --git a/lib/Guides/Compiler/SidebarTransformer.php b/lib/Guides/Compiler/SidebarTransformer.php new file mode 100644 index 00000000..ebe56146 --- /dev/null +++ b/lib/Guides/Compiler/SidebarTransformer.php @@ -0,0 +1,48 @@ +getDocumentNode()->getDocumentPartNodes()['sidebar'] ?? []; + $nodes[] = $node; + + $compilerContext->getDocumentNode()->addDocumentPart('sidebar', $nodes); + + return null; + } + + #[\Override] + public function supports(Node $node): bool + { + if ($node instanceof GeneralDirectiveNode) { + return $node->getName() === 'toc'; + } + + return $node instanceof TocNode; + } + + #[\Override] + public function getPriority(): int + { + return 3000; + } +} diff --git a/templates/guides/body/directive/toc.html.twig b/templates/guides/body/directive/toc.html.twig new file mode 100644 index 00000000..110e570e --- /dev/null +++ b/templates/guides/body/directive/toc.html.twig @@ -0,0 +1,3 @@ +
+{{ renderNode(node.value) }} +
diff --git a/templates/guides/body/directive/tocheader.html.twig b/templates/guides/body/directive/tocheader.html.twig new file mode 100644 index 00000000..ef896f3d --- /dev/null +++ b/templates/guides/body/directive/tocheader.html.twig @@ -0,0 +1 @@ +

{{ renderNode(node.content) }}

diff --git a/templates/guides/structure/document.html.twig b/templates/guides/structure/document.html.twig index 7f873939..00d1072e 100644 --- a/templates/guides/structure/document.html.twig +++ b/templates/guides/structure/document.html.twig @@ -8,8 +8,11 @@ docsSourcePath: "/en/{{ node.filePath }}.rst" {% block sidebar %} {% endverbatim %} -{{ renderNode(node.tocNodes) }} - +{% for id,value in node.documentPartNodes %} + {% if id == 'sidebar' %} + {{ renderNode(value) }} + {% endif %} +{% endfor %} {% verbatim %} {% endblock %}{% block content %}{% verbatim %} From 834246694ddc46b533237d8796f8cbfab43507e6 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Tue, 20 Aug 2024 21:45:14 +0200 Subject: [PATCH 05/30] Fix code blocks, menu and header links --- lib/Docs/CodeBlockWithLineNumbersRenderer.php | 1 + lib/Docs/RST/RSTCopier.php | 8 +-- source/js/main.js | 59 ++++++++++--------- source/styles/index.scss | 23 +++++++- templates/guides/body/admonition.html.twig | 30 ++++++++++ .../guides/body/menu/menu-item.html.twig | 17 ++++++ .../guides/structure/header-title.html.twig | 6 ++ 7 files changed, 106 insertions(+), 38 deletions(-) create mode 100644 templates/guides/body/admonition.html.twig create mode 100644 templates/guides/body/menu/menu-item.html.twig create mode 100644 templates/guides/structure/header-title.html.twig diff --git a/lib/Docs/CodeBlockWithLineNumbersRenderer.php b/lib/Docs/CodeBlockWithLineNumbersRenderer.php index e67fb37f..0c2d0b18 100644 --- a/lib/Docs/CodeBlockWithLineNumbersRenderer.php +++ b/lib/Docs/CodeBlockWithLineNumbersRenderer.php @@ -27,6 +27,7 @@ class CodeBlockWithLineNumbersRenderer 'mysql', 'postgres', 'html+php', + 'rst', ]; private const LINE_NUMBER_TABLE_COLUMN_TEMPLATE = '%d'; diff --git a/lib/Docs/RST/RSTCopier.php b/lib/Docs/RST/RSTCopier.php index e346db06..194ec1e5 100644 --- a/lib/Docs/RST/RSTCopier.php +++ b/lib/Docs/RST/RSTCopier.php @@ -19,12 +19,8 @@ class RSTCopier { final public const RST_TEMPLATE = <<<'TEMPLATE' - SIDEBAR BEGIN - {{ sidebar }} - - CONTENT BEGIN - + {{ content }} TEMPLATE; @@ -106,7 +102,7 @@ private function prepareRSTTemplate(string $content, string $sidebar, string $so // append the source file name to the content so we can parse it back out // for use in the build process - return $content . "\n\n" . sprintf('{{ DOCS_SOURCE_PATH : %s }}', $sourceFile); + return $content; } private function fixRSTSyntax(Project $project, string $content): string diff --git a/source/js/main.js b/source/js/main.js index 099b0d09..595bedc8 100644 --- a/source/js/main.js +++ b/source/js/main.js @@ -20,40 +20,41 @@ export default function () { }); $(document).ready(function () { - $('div.configuration-block [class^=highlight-]').hide(); - $('div.configuration-block [class^=highlight-]').width( - $('div.configuration-block').width(), - ); + $('button[role="tab"]').on('click', function () { + const tabId = $(this).attr('aria-controls'); + const tabContent = $('#' + tabId); - $('div.configuration-block').addClass('jsactive'); - $('div.configuration-block').addClass('clearfix'); + $(this).closest('[role=tablist]').find('button[role="tab"]') + .attr('data-active', null) + .attr('aria-selected', 'false'); - $('div.configuration-block').each(function () { - var el = $('[class^=highlight-]:first', $(this)); - el.show(); - el.parents('ul').height(el.height() + 40); - }); - - // Global - $('div.configuration-block li').each(function () { - var str = $(':first', $(this)).html(); - $(':first ', $(this)).html(''); - $(':first ', $(this)).append('' + str + ''); - $(':first', $(this)).bind('click', function () { - $('[class^=highlight-]', $(this).parents('ul')).hide(); - $('li', $(this).parents('ul')).removeClass('selected'); - $(this).parent().addClass('selected'); + $(this).attr('data-active', 'true').attr('aria-selected', 'true'); - var block = $('[class^=highlight-]', $(this).parent('li')); - block.show(); - block.parents('ul').height(block.height() + 40); - return false; - }); + $(this).closest('[role=tablist]').parent().find('div[role="tabpanel"]').hide(); + tabContent.show(); }); - $('div.configuration-block').each(function () { - $('li:first', $(this)).addClass('selected'); - }); + // + // // Global + // $('div.configuration-block li').each(function () { + // var str = $(':first', $(this)).html(); + // $(':first ', $(this)).html(''); + // $(':first ', $(this)).append('' + str + ''); + // $(':first', $(this)).bind('click', function () { + // $('[class^=highlight-]', $(this).parents('ul')).hide(); + // $('li', $(this).parents('ul')).removeClass('selected'); + // $(this).parent().addClass('selected'); + // + // var block = $('[class^=highlight-]', $(this).parent('li')); + // block.show(); + // block.parents('ul').height(block.height() + 40); + // return false; + // }); + // }); + // + // $('div.configuration-block').each(function () { + // $('li:first', $(this)).addClass('selected'); + // }); $('button.copy-to-clipboard').on('click', function () { var copyElementId = $(this).data('copy-element-id'); diff --git a/source/styles/index.scss b/source/styles/index.scss index 863fc847..5214bc03 100644 --- a/source/styles/index.scss +++ b/source/styles/index.scss @@ -267,7 +267,7 @@ pre code table.code-block-table tr:last-child td { supported by Chrome and Opera */ } -pre code table.code-block-table tr td.line-number { +table.code-block-table tr td.line-number { background-color: #333; padding-left: 10px; padding-right: 10px; @@ -275,11 +275,11 @@ pre code table.code-block-table tr td.line-number { color: #63606b; } -pre code table.code-block-table tr td.line-number a { +table.code-block-table tr td.line-number a { color: #63606b; } -pre code table.code-block-table tr td.code-line { +table.code-block-table tr td.code-line { padding-left: 15px; vertical-align: top; line-height: 23px; @@ -449,6 +449,23 @@ div.jsactive pre { margin: 0; } +button[role='tab'] { + border-radius: 5px 5px 0 0; + border: 0; + font-weight: bold; + font-size: 90%; + text-transform: uppercase; + + &[aria-selected='true'] { + background-color: #000; + color: #fff; + } + + &:hover { + text-decoration: underline; + } +} + .bg-success { code { color: #ffffff; diff --git a/templates/guides/body/admonition.html.twig b/templates/guides/body/admonition.html.twig new file mode 100644 index 00000000..94cd6f78 --- /dev/null +++ b/templates/guides/body/admonition.html.twig @@ -0,0 +1,30 @@ +{% if name == 'important' %} +{% endif %} +{% if name == 'note' %} + {% set admonitionClass='note' %} + {% set textClass='text-primary' %} + {% set icon='fa-sticky-note' %} +{% endif %} +{% if name == 'warning' or name == 'caution' %} + {% set admonitionClass='warning' %} + {% set textClass='text-primary' %} + {% set icon='fa-exclamation-circle' %} +{% endif %} +{% if name == 'tip' or name == 'hint' %} +{% endif %} +{% if name == 'seealso' %} +{% endif %} +
+ + + + + + + +
+ {% if title and isTitled %}

{{ renderNode(title) }}

{% endif %} + {% if title and not isTitled %}

{{ renderNode(title) }}

{% endif %} + {{ renderNode(node) }} +
+
diff --git a/templates/guides/body/menu/menu-item.html.twig b/templates/guides/body/menu/menu-item.html.twig new file mode 100644 index 00000000..9953cda5 --- /dev/null +++ b/templates/guides/body/menu/menu-item.html.twig @@ -0,0 +1,17 @@ +
  • + {{ node.value.toString }} + {%~ if node.children|length %} + + {%- endif ~%} + {%~ if node.sections|length %} +
      + {% for subsection in node.sections -%} + {{ renderNode(subsection) }} + {% endfor %} +
    + {%- endif ~%} +
  • diff --git a/templates/guides/structure/header-title.html.twig b/templates/guides/structure/header-title.html.twig new file mode 100644 index 00000000..7bf9b772 --- /dev/null +++ b/templates/guides/structure/header-title.html.twig @@ -0,0 +1,6 @@ + + + {{ renderNode(node.value) }} + + + From 3c15f3450b6a965da0049726c89f39534fc7b01f Mon Sep 17 00:00:00 2001 From: Jaapio Date: Tue, 20 Aug 2024 21:56:53 +0200 Subject: [PATCH 06/30] Fix style issues --- lib/Docs/RST/DoctrineRSTBuilder.php | 10 ++++++---- ...lderInterface.php => DocumentsBuilder.php} | 2 +- lib/Docs/RST/Guides.php | 19 ++++++++++--------- lib/Docs/RST/Logger.php | 9 ++++++++- lib/Docs/RST/RSTBuilder.php | 2 +- lib/Docs/RST/RSTPostBuildProcessor.php | 1 + lib/Guides/Compiler/SidebarTransformer.php | 12 ++++++------ lib/Guides/Renderer/CodeBlockRenderer.php | 14 ++++++++------ lib/Twig/MainExtension.php | 14 +++++++++----- 9 files changed, 50 insertions(+), 33 deletions(-) rename lib/Docs/RST/{BuilderInterface.php => DocumentsBuilder.php} (91%) diff --git a/lib/Docs/RST/DoctrineRSTBuilder.php b/lib/Docs/RST/DoctrineRSTBuilder.php index d866eda4..61be2725 100644 --- a/lib/Docs/RST/DoctrineRSTBuilder.php +++ b/lib/Docs/RST/DoctrineRSTBuilder.php @@ -5,16 +5,17 @@ namespace Doctrine\Website\Docs\RST; use Doctrine\RST\Builder; +use Override; +use phpDocumentor\Guides\Nodes\DocumentNode; -final class DoctrineRSTBuilder implements BuilderInterface +final class DoctrineRSTBuilder implements DocumentsBuilder { public function __construct( private Builder $builder, ) { } - - #[\Override] + #[Override] public function build(string $directory, string $targetDirectory = 'output'): void { // we have to get a fresh builder due to how the RST parser works @@ -28,7 +29,8 @@ public function build(string $directory, string $targetDirectory = 'output'): vo ); } - #[\Override] + /** @return DocumentNode[] */ + #[Override] public function getDocuments(): array { return $this->builder->getDocuments()->getAll(); diff --git a/lib/Docs/RST/BuilderInterface.php b/lib/Docs/RST/DocumentsBuilder.php similarity index 91% rename from lib/Docs/RST/BuilderInterface.php rename to lib/Docs/RST/DocumentsBuilder.php index 3c140697..20f60d2d 100644 --- a/lib/Docs/RST/BuilderInterface.php +++ b/lib/Docs/RST/DocumentsBuilder.php @@ -6,7 +6,7 @@ use Doctrine\RST\Nodes\DocumentNode; -interface BuilderInterface +interface DocumentsBuilder { public function build(string $directory, string $targetDirectory = 'output'): void; diff --git a/lib/Docs/RST/Guides.php b/lib/Docs/RST/Guides.php index 73e8e2ad..9a9cfb9d 100644 --- a/lib/Docs/RST/Guides.php +++ b/lib/Docs/RST/Guides.php @@ -9,42 +9,42 @@ use League\Flysystem\Adapter\Local; use League\Flysystem\Filesystem; use League\Tactician\CommandBus; +use Override; use phpDocumentor\Guides\Compiler\CompilerContext; use phpDocumentor\Guides\Handlers\CompileDocumentsCommand; use phpDocumentor\Guides\Handlers\ParseDirectoryCommand; use phpDocumentor\Guides\Handlers\RenderCommand; +use phpDocumentor\Guides\Nodes\DocumentNode; use phpDocumentor\Guides\Nodes\ProjectNode; use phpDocumentor\Guides\Twig\Theme\ThemeManager; -final class Guides implements BuilderInterface +final class Guides implements DocumentsBuilder { - public function __construct( private readonly CommandBus $commandBus, - private readonly ThemeManager $themeManager + private readonly ThemeManager $themeManager, ) { } - - #[\Override] + #[Override] public function build(string $directory, string $targetDirectory = 'output'): void { $sourceFileSystem = new Filesystem(new Local($directory)); $sourceFileSystem->addPlugin(new Finder()); $projectNode = new ProjectNode(); - $documents = $this->commandBus->handle( + $documents = $this->commandBus->handle( new ParseDirectoryCommand( $sourceFileSystem, '', 'rst', $projectNode, - new Glob('/**/sidebar.rst') + new Glob('/**/sidebar.rst'), ), ); $documents = $this->commandBus->handle( - new CompileDocumentsCommand($documents, new CompilerContext($projectNode)) + new CompileDocumentsCommand($documents, new CompilerContext($projectNode)), ); $destinationFileSystem = new Filesystem(new Local($targetDirectory)); @@ -61,7 +61,8 @@ public function build(string $directory, string $targetDirectory = 'output'): vo ); } - #[\Override] + /** @return DocumentNode[] */ + #[Override] public function getDocuments(): array { return []; diff --git a/lib/Docs/RST/Logger.php b/lib/Docs/RST/Logger.php index 44e4b616..fe1aed26 100644 --- a/lib/Docs/RST/Logger.php +++ b/lib/Docs/RST/Logger.php @@ -5,10 +5,17 @@ namespace Doctrine\Website\Docs\RST; use Psr\Log\AbstractLogger; +use Stringable; + +use function date; +use function sprintf; + +use const PHP_EOL; class Logger extends AbstractLogger { - public function log($level, \Stringable|string $message, array $context = []): void + /** @param mixed[] $context */ + public function log(mixed $level, Stringable|string $message, array $context = []): void { echo sprintf('[%s] %s: %s', date('Y-m-d H:i:s'), $level, $message) . PHP_EOL; } diff --git a/lib/Docs/RST/RSTBuilder.php b/lib/Docs/RST/RSTBuilder.php index fecc4eff..2d1510e0 100644 --- a/lib/Docs/RST/RSTBuilder.php +++ b/lib/Docs/RST/RSTBuilder.php @@ -15,7 +15,7 @@ class RSTBuilder public function __construct( private readonly RSTFileRepository $rstFileRepository, private readonly RSTCopier $rstCopier, - private readonly BuilderInterface $builder, + private readonly DocumentsBuilder $builder, private readonly RSTPostBuildProcessor $rstPostBuildProcessor, private readonly Filesystem $filesystem, private readonly string $sourceDir, diff --git a/lib/Docs/RST/RSTPostBuildProcessor.php b/lib/Docs/RST/RSTPostBuildProcessor.php index da4b3b55..ad003fae 100644 --- a/lib/Docs/RST/RSTPostBuildProcessor.php +++ b/lib/Docs/RST/RSTPostBuildProcessor.php @@ -38,6 +38,7 @@ public function __construct( public function postRstBuild(Project $project, ProjectVersion $version, RSTLanguage $language): void { return; + $projectVersionDocsOutputPath = $project->getProjectVersionDocsOutputPath( $this->sourceDir, $version, diff --git a/lib/Guides/Compiler/SidebarTransformer.php b/lib/Guides/Compiler/SidebarTransformer.php index ebe56146..9b7a6718 100644 --- a/lib/Guides/Compiler/SidebarTransformer.php +++ b/lib/Guides/Compiler/SidebarTransformer.php @@ -5,6 +5,7 @@ namespace Doctrine\Website\Guides\Compiler; use Doctrine\RST\Nodes\TocNode; +use Override; use phpDocumentor\Guides\Compiler\CompilerContext; use phpDocumentor\Guides\Compiler\NodeTransformer; use phpDocumentor\Guides\Nodes\Node; @@ -12,17 +13,16 @@ final class SidebarTransformer implements NodeTransformer { - - #[\Override] + #[Override] public function enterNode(Node $node, CompilerContext $compilerContext): Node { return $node; } - #[\Override] + #[Override] public function leaveNode(Node $node, CompilerContext $compilerContext): Node|null { - $nodes = $compilerContext->getDocumentNode()->getDocumentPartNodes()['sidebar'] ?? []; + $nodes = $compilerContext->getDocumentNode()->getDocumentPartNodes()['sidebar'] ?? []; $nodes[] = $node; $compilerContext->getDocumentNode()->addDocumentPart('sidebar', $nodes); @@ -30,7 +30,7 @@ public function leaveNode(Node $node, CompilerContext $compilerContext): Node|nu return null; } - #[\Override] + #[Override] public function supports(Node $node): bool { if ($node instanceof GeneralDirectiveNode) { @@ -40,7 +40,7 @@ public function supports(Node $node): bool return $node instanceof TocNode; } - #[\Override] + #[Override] public function getPriority(): int { return 3000; diff --git a/lib/Guides/Renderer/CodeBlockRenderer.php b/lib/Guides/Renderer/CodeBlockRenderer.php index 808ad966..c649f08e 100644 --- a/lib/Guides/Renderer/CodeBlockRenderer.php +++ b/lib/Guides/Renderer/CodeBlockRenderer.php @@ -7,11 +7,15 @@ use Doctrine\Website\Docs\CodeBlockConsoleRenderer; use Doctrine\Website\Docs\CodeBlockLanguageDetector; use Doctrine\Website\Docs\CodeBlockWithLineNumbersRenderer; +use Override; use phpDocumentor\Guides\NodeRenderers\NodeRenderer; use phpDocumentor\Guides\Nodes\CodeNode; use phpDocumentor\Guides\Nodes\Node; use phpDocumentor\Guides\RenderContext; +use function explode; +use function in_array; + final class CodeBlockRenderer implements NodeRenderer { private const CONSOLE_LANGUAGES = ['terminal', 'bash', 'sh', 'console']; @@ -23,23 +27,21 @@ public function __construct( ) { } - #[\Override] + #[Override] public function supports(string $nodeFqcn): bool { return $nodeFqcn === CodeNode::class; } - #[\Override] + #[Override] public function render(Node $node, RenderContext $renderContext): string { - $lines = explode("\n", $node->getValue()); + $lines = explode("\n", $node->getValue()); $language = $this->codeBlockLanguageDetector->detectLanguage( $node->getLanguage(), - $lines + $lines, ); - - if (in_array($language, self::CONSOLE_LANGUAGES, true)) { return $this->codeBlockConsoleRenderer->render($lines); } diff --git a/lib/Twig/MainExtension.php b/lib/Twig/MainExtension.php index 2a13984c..9db61301 100644 --- a/lib/Twig/MainExtension.php +++ b/lib/Twig/MainExtension.php @@ -7,14 +7,15 @@ use Doctrine\Website\Assets\AssetIntegrityGenerator; use Doctrine\Website\Model\Project; use Doctrine\Website\Model\ProjectVersion; +use Override; use Parsedown; use phpDocumentor\Guides\Nodes\Menu\TocNode; use phpDocumentor\Guides\Nodes\Node; use Twig\Extension\AbstractExtension; use Twig\TwigFilter; use Twig\TwigFunction; - use Twig\TwigTest; + use function assert; use function file_get_contents; use function is_int; @@ -22,6 +23,7 @@ use function realpath; use function sha1; use function sprintf; +use function str_replace; use function strlen; use function strrpos; use function substr; @@ -58,15 +60,15 @@ public function getFilters(): array ]; } - #[\Override] - public function getTests() + /** {@inheritDoc} */ + #[Override] + public function getTests(): array { return [ new TwigTest('tocNode', [$this, 'isTocNode']), ]; } - public function getSearchBoxPlaceholder(Project|null $project = null, ProjectVersion|null $projectVersion = null): string { if ($project !== null && $projectVersion !== null) { @@ -117,11 +119,13 @@ private function getAssetCacheBuster(string $path, string $rootPath): string return substr(sha1($contents), 0, 6); } - public function yamlEncode(mixed $value) + public function yamlEncode(mixed $value): mixed { if (is_string($value)) { return str_replace('\\', '\\\\', $value); } + + return $value; } public function isTocNode(Node $node): bool From d544ef5822cafb33ec3cd155a8c859e08df02fcc Mon Sep 17 00:00:00 2001 From: Jaapio Date: Tue, 20 Aug 2024 22:03:17 +0200 Subject: [PATCH 07/30] Cleanup code --- lib/WebsiteBuilder.php | 22 +++++++++++----------- source/js/main.js | 22 ---------------------- 2 files changed, 11 insertions(+), 33 deletions(-) diff --git a/lib/WebsiteBuilder.php b/lib/WebsiteBuilder.php index 81ed3ef8..3c4fd62d 100644 --- a/lib/WebsiteBuilder.php +++ b/lib/WebsiteBuilder.php @@ -103,17 +103,17 @@ private function buildWebpackAssets(OutputInterface $output, string $buildDir, b { $output->writeln(sprintf(' - running npm run %s ', $isPublishableEnv ? 'build' : 'dev')); -// $this->filesystem->remove((array) glob($this->webpackBuildDir . '/*')); - -// $process = $this->processFactory->run(sprintf( -// 'cd %s && npm run %s', -// $this->rootDir, -// $isPublishableEnv ? 'build' : 'dev', -// )); -// -// if ($output->isVerbose()) { -// $output->write($process->getOutput()); -// } + $this->filesystem->remove((array) glob($this->webpackBuildDir . '/*')); + + $process = $this->processFactory->run(sprintf( + 'cd %s && npm run %s', + $this->rootDir, + $isPublishableEnv ? 'build' : 'dev', + )); + + if ($output->isVerbose()) { + $output->write($process->getOutput()); + } // Copy built assets if this is a publishable build if ($isPublishableEnv) { diff --git a/source/js/main.js b/source/js/main.js index 595bedc8..2631267f 100644 --- a/source/js/main.js +++ b/source/js/main.js @@ -34,28 +34,6 @@ export default function () { tabContent.show(); }); - // - // // Global - // $('div.configuration-block li').each(function () { - // var str = $(':first', $(this)).html(); - // $(':first ', $(this)).html(''); - // $(':first ', $(this)).append('' + str + ''); - // $(':first', $(this)).bind('click', function () { - // $('[class^=highlight-]', $(this).parents('ul')).hide(); - // $('li', $(this).parents('ul')).removeClass('selected'); - // $(this).parent().addClass('selected'); - // - // var block = $('[class^=highlight-]', $(this).parent('li')); - // block.show(); - // block.parents('ul').height(block.height() + 40); - // return false; - // }); - // }); - // - // $('div.configuration-block').each(function () { - // $('li:first', $(this)).addClass('selected'); - // }); - $('button.copy-to-clipboard').on('click', function () { var copyElementId = $(this).data('copy-element-id'); From 49da8dba219dd4a0c94296b450089ef82da8c1f6 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Wed, 21 Aug 2024 14:42:21 +0200 Subject: [PATCH 08/30] Revert wrong config change --- config/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.yml b/config/config.yml index 74ce4215..0c0b999d 100644 --- a/config/config.yml +++ b/config/config.yml @@ -13,7 +13,7 @@ parameters: doctrine.website.title: Doctrine doctrine.website.subtitle: PHP Open Source Project - doctrine.website.url: http://lcl.doctrine-project.org + doctrine.website.url: https://lcl.doctrine-project.org doctrine.website.assets_url: https://www.doctrine-project.org doctrine.website.keywords: [php, mysql, orm, dbal, database, mongodb, odm, annotations, migrations, cache, couchdb] doctrine.website.description: > From 017d252b5ddc0cb4a272eeb1bf15ec2676f82fc1 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Wed, 21 Aug 2024 21:11:54 +0200 Subject: [PATCH 09/30] Remove guides-code as it is not used right now. --- composer.json | 1 - composer.lock | 38 +------------------------------------- config/packages/guides.yml | 8 -------- lib/Application.php | 3 +-- 4 files changed, 2 insertions(+), 48 deletions(-) diff --git a/composer.json b/composer.json index 6be426d8..66663a54 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,6 @@ "knplabs/github-api": "^3.9", "php-http/guzzle7-adapter": "^1.0", "phpdocumentor/guides": "^1.3", - "phpdocumentor/guides-code": "^1.0", "phpdocumentor/guides-restructured-text": "^1.3", "scrivo/highlight.php": "^9.18", "symfony/cache": "^6.4", diff --git a/composer.lock b/composer.lock index 4b0e41bd..00a35592 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "db9fbeed65aeaab41437a2f44c6039b5", + "content-hash": "6009a56807bee47f1c2adad6ef19c53f", "packages": [ { "name": "algolia/algoliasearch-client-php", @@ -2619,42 +2619,6 @@ }, "time": "2024-05-07T18:12:18+00:00" }, - { - "name": "phpdocumentor/guides-code", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/phpDocumentor/guides-code.git", - "reference": "f6aefca78d3a9b56d36202bfdbf8239a6d254b74" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/guides-code/zipball/f6aefca78d3a9b56d36202bfdbf8239a6d254b74", - "reference": "f6aefca78d3a9b56d36202bfdbf8239a6d254b74", - "shasum": "" - }, - "require": { - "php": "^8.1", - "scrivo/highlight.php": "^9.18.0" - }, - "type": "library", - "autoload": { - "psr-4": { - "phpDocumentor\\Guides\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "A library to provide code-related functionality to phpDocumentor's Guides", - "homepage": "https://www.phpdoc.org", - "support": { - "issues": "https://github.com/phpDocumentor/guides-code/issues", - "source": "https://github.com/phpDocumentor/guides-code/tree/1.0.0" - }, - "time": "2024-03-03T20:57:20+00:00" - }, { "name": "phpdocumentor/guides-restructured-text", "version": "1.3.8", diff --git a/config/packages/guides.yml b/config/packages/guides.yml index 643b18d5..a4eb3818 100644 --- a/config/packages/guides.yml +++ b/config/packages/guides.yml @@ -4,11 +4,3 @@ guides: themes: doctrine: '%doctrine.website.root_dir%/templates/guides' -code: - aliases: - html+php: php - html+jinja: html - php-annotations: php - php-attributes: php - languages: - diff --git a/lib/Application.php b/lib/Application.php index 5802025a..f18b7242 100644 --- a/lib/Application.php +++ b/lib/Application.php @@ -10,7 +10,6 @@ use Doctrine\Website\Commands\BuildWebsiteCommand; use Doctrine\Website\Commands\ClearBuildCacheCommand; use Doctrine\Website\Commands\SyncRepositoriesCommand; -use phpDocumentor\Guides\Code\DependencyInjection\CodeExtension; use phpDocumentor\Guides\DependencyInjection\GuidesExtension; use phpDocumentor\Guides\RestructuredText\DependencyInjection\ReStructuredTextExtension; use Symfony\Component\Config\FileLocator; @@ -90,7 +89,7 @@ public static function getContainer(string $env): ContainerBuilder $container->setParameter('doctrine.website.send_grid.api_key', getenv('doctrine_website_send_grid_api_key') ?: ''); $container->setParameter('vendor_dir', realpath(__DIR__ . '/../vendor')); - foreach ([new GuidesExtension(), new ReStructuredTextExtension(), new CodeExtension()] as $extension) { + foreach ([new GuidesExtension(), new ReStructuredTextExtension()] as $extension) { $container->registerExtension($extension); $container->loadFromExtension($extension->getAlias()); } From 456878eded1463c56a42f07b353a484cff3cd771 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Wed, 21 Aug 2024 21:37:16 +0200 Subject: [PATCH 10/30] Remove all rst parser related code --- composer.json | 1 - composer.lock | 74 ++++----- config/services.xml | 1 - config/services/rst-parser.xml | 73 --------- lib/Docs/CodeBlockRenderer.php | 33 ---- lib/Docs/RST/DoctrineRSTBuilder.php | 38 ----- lib/Docs/RST/RSTPostBuildProcessor.php | 149 ------------------ lib/EventListener/NodeValue.php | 25 --- lib/EventListener/TableIncompatibility.php | 26 --- lib/RST/Directive/AdmonitionDirective.php | 35 ---- lib/RST/Directive/CautionDirective.php | 13 -- lib/RST/Directive/CodeBlockDirective.php | 100 ------------ .../Directive/ConfigurationBlockDirective.php | 55 ------- lib/RST/Directive/HintDirective.php | 13 -- lib/RST/Directive/IndexDirective.php | 15 -- lib/RST/Directive/NoteDirective.php | 13 -- lib/RST/Directive/NoticeDirective.php | 13 -- lib/RST/Directive/RoleDirective.php | 29 ---- lib/RST/Directive/SectionAuthorDirective.php | 53 ------- lib/RST/Directive/SeeAlsoDirective.php | 13 -- lib/RST/Directive/SidebarDirective.php | 13 -- lib/RST/Directive/TipDirective.php | 13 -- lib/RST/Directive/TocDirective.php | 29 ---- lib/RST/Directive/TocHeaderDirective.php | 29 ---- lib/RST/Directive/VersionAddedDirective.php | 47 ------ lib/RST/Directive/WarningDirective.php | 13 -- 26 files changed, 37 insertions(+), 879 deletions(-) delete mode 100644 config/services/rst-parser.xml delete mode 100644 lib/Docs/CodeBlockRenderer.php delete mode 100644 lib/Docs/RST/DoctrineRSTBuilder.php delete mode 100644 lib/Docs/RST/RSTPostBuildProcessor.php delete mode 100644 lib/EventListener/NodeValue.php delete mode 100644 lib/EventListener/TableIncompatibility.php delete mode 100644 lib/RST/Directive/AdmonitionDirective.php delete mode 100644 lib/RST/Directive/CautionDirective.php delete mode 100644 lib/RST/Directive/CodeBlockDirective.php delete mode 100644 lib/RST/Directive/ConfigurationBlockDirective.php delete mode 100644 lib/RST/Directive/HintDirective.php delete mode 100644 lib/RST/Directive/IndexDirective.php delete mode 100644 lib/RST/Directive/NoteDirective.php delete mode 100644 lib/RST/Directive/NoticeDirective.php delete mode 100644 lib/RST/Directive/RoleDirective.php delete mode 100644 lib/RST/Directive/SectionAuthorDirective.php delete mode 100644 lib/RST/Directive/SeeAlsoDirective.php delete mode 100644 lib/RST/Directive/SidebarDirective.php delete mode 100644 lib/RST/Directive/TipDirective.php delete mode 100644 lib/RST/Directive/TocDirective.php delete mode 100644 lib/RST/Directive/TocHeaderDirective.php delete mode 100644 lib/RST/Directive/VersionAddedDirective.php delete mode 100644 lib/RST/Directive/WarningDirective.php diff --git a/composer.json b/composer.json index 66663a54..59e1f82c 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,6 @@ "doctrine/dbal": "^4.0", "doctrine/inflector": "^2.0", "doctrine/orm": "^3.2", - "doctrine/rst-parser": "^0.5", "doctrine/static-website-generator": "^2.1", "erusev/parsedown": "^1.7", "knplabs/github-api": "^3.9", diff --git a/composer.lock b/composer.lock index 00a35592..37c82996 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6009a56807bee47f1c2adad6ef19c53f", + "content-hash": "ce075fb57999b1c23ce00a7d80c59720", "packages": [ { "name": "algolia/algoliasearch-client-php", @@ -4595,16 +4595,16 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.29.0", + "version": "v1.30.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "ef4d7e442ca910c4764bce785146269b30cb5fc4" + "reference": "0424dff1c58f028c451efff2045f5d92410bd540" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/ef4d7e442ca910c4764bce785146269b30cb5fc4", - "reference": "ef4d7e442ca910c4764bce785146269b30cb5fc4", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/0424dff1c58f028c451efff2045f5d92410bd540", + "reference": "0424dff1c58f028c451efff2045f5d92410bd540", "shasum": "" }, "require": { @@ -4654,7 +4654,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.29.0" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.30.0" }, "funding": [ { @@ -4670,20 +4670,20 @@ "type": "tidelift" } ], - "time": "2024-01-29T20:11:03+00:00" + "time": "2024-05-31T15:07:36+00:00" }, { "name": "symfony/polyfill-intl-grapheme", - "version": "v1.29.0", + "version": "v1.30.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-grapheme.git", - "reference": "32a9da87d7b3245e09ac426c83d334ae9f06f80f" + "reference": "64647a7c30b2283f5d49b874d84a18fc22054b7a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/32a9da87d7b3245e09ac426c83d334ae9f06f80f", - "reference": "32a9da87d7b3245e09ac426c83d334ae9f06f80f", + "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/64647a7c30b2283f5d49b874d84a18fc22054b7a", + "reference": "64647a7c30b2283f5d49b874d84a18fc22054b7a", "shasum": "" }, "require": { @@ -4732,7 +4732,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.29.0" + "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.30.0" }, "funding": [ { @@ -4748,20 +4748,20 @@ "type": "tidelift" } ], - "time": "2024-01-29T20:11:03+00:00" + "time": "2024-05-31T15:07:36+00:00" }, { "name": "symfony/polyfill-intl-normalizer", - "version": "v1.29.0", + "version": "v1.30.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-normalizer.git", - "reference": "bc45c394692b948b4d383a08d7753968bed9a83d" + "reference": "a95281b0be0d9ab48050ebd988b967875cdb9fdb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/bc45c394692b948b4d383a08d7753968bed9a83d", - "reference": "bc45c394692b948b4d383a08d7753968bed9a83d", + "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/a95281b0be0d9ab48050ebd988b967875cdb9fdb", + "reference": "a95281b0be0d9ab48050ebd988b967875cdb9fdb", "shasum": "" }, "require": { @@ -4813,7 +4813,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.29.0" + "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.30.0" }, "funding": [ { @@ -4829,20 +4829,20 @@ "type": "tidelift" } ], - "time": "2024-01-29T20:11:03+00:00" + "time": "2024-05-31T15:07:36+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.29.0", + "version": "v1.30.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "9773676c8a1bb1f8d4340a62efe641cf76eda7ec" + "reference": "fd22ab50000ef01661e2a31d850ebaa297f8e03c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/9773676c8a1bb1f8d4340a62efe641cf76eda7ec", - "reference": "9773676c8a1bb1f8d4340a62efe641cf76eda7ec", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/fd22ab50000ef01661e2a31d850ebaa297f8e03c", + "reference": "fd22ab50000ef01661e2a31d850ebaa297f8e03c", "shasum": "" }, "require": { @@ -4893,7 +4893,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.29.0" + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.30.0" }, "funding": [ { @@ -4909,20 +4909,20 @@ "type": "tidelift" } ], - "time": "2024-01-29T20:11:03+00:00" + "time": "2024-06-19T12:30:46+00:00" }, { "name": "symfony/polyfill-php80", - "version": "v1.29.0", + "version": "v1.30.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "87b68208d5c1188808dd7839ee1e6c8ec3b02f1b" + "reference": "77fa7995ac1b21ab60769b7323d600a991a90433" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/87b68208d5c1188808dd7839ee1e6c8ec3b02f1b", - "reference": "87b68208d5c1188808dd7839ee1e6c8ec3b02f1b", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/77fa7995ac1b21ab60769b7323d600a991a90433", + "reference": "77fa7995ac1b21ab60769b7323d600a991a90433", "shasum": "" }, "require": { @@ -4973,7 +4973,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php80/tree/v1.29.0" + "source": "https://github.com/symfony/polyfill-php80/tree/v1.30.0" }, "funding": [ { @@ -4989,7 +4989,7 @@ "type": "tidelift" } ], - "time": "2024-01-29T20:11:03+00:00" + "time": "2024-05-31T15:07:36+00:00" }, { "name": "symfony/polyfill-php83", @@ -5297,16 +5297,16 @@ }, { "name": "symfony/string", - "version": "v7.1.1", + "version": "v7.1.3", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "60bc311c74e0af215101235aa6f471bcbc032df2" + "reference": "ea272a882be7f20cad58d5d78c215001617b7f07" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/60bc311c74e0af215101235aa6f471bcbc032df2", - "reference": "60bc311c74e0af215101235aa6f471bcbc032df2", + "url": "https://api.github.com/repos/symfony/string/zipball/ea272a882be7f20cad58d5d78c215001617b7f07", + "reference": "ea272a882be7f20cad58d5d78c215001617b7f07", "shasum": "" }, "require": { @@ -5364,7 +5364,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v7.1.1" + "source": "https://github.com/symfony/string/tree/v7.1.3" }, "funding": [ { @@ -5380,7 +5380,7 @@ "type": "tidelift" } ], - "time": "2024-06-04T06:40:14+00:00" + "time": "2024-07-22T10:25:37+00:00" }, { "name": "symfony/translation-contracts", diff --git a/config/services.xml b/config/services.xml index 3bf4b6f1..08856a55 100644 --- a/config/services.xml +++ b/config/services.xml @@ -6,7 +6,6 @@ - diff --git a/config/services/rst-parser.xml b/config/services/rst-parser.xml deleted file mode 100644 index 3d204562..00000000 --- a/config/services/rst-parser.xml +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - - false - - - true - - - false - - - html - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Doctrine\RST\Event\PreNodeRenderEvent::PRE_NODE_RENDER - - - - Doctrine\RST\Event\PreParseDocumentEvent::PRE_PARSE_DOCUMENT - - - - - diff --git a/lib/Docs/CodeBlockRenderer.php b/lib/Docs/CodeBlockRenderer.php deleted file mode 100644 index eb39c90e..00000000 --- a/lib/Docs/CodeBlockRenderer.php +++ /dev/null @@ -1,33 +0,0 @@ -codeBlockConsoleRenderer->render( - $lines, - ); - } - - return $this->codeBlockWithLineNumbersRenderer->render( - $lines, - $language, - ); - } -} diff --git a/lib/Docs/RST/DoctrineRSTBuilder.php b/lib/Docs/RST/DoctrineRSTBuilder.php deleted file mode 100644 index 61be2725..00000000 --- a/lib/Docs/RST/DoctrineRSTBuilder.php +++ /dev/null @@ -1,38 +0,0 @@ -builder = $this->builder->recreate(); - - // build the docs from the files in $docsDir and write them to $outputPath - // which is contained inside the $sourceDir - $this->builder->build( - $directory, - $targetDirectory, - ); - } - - /** @return DocumentNode[] */ - #[Override] - public function getDocuments(): array - { - return $this->builder->getDocuments()->getAll(); - } -} diff --git a/lib/Docs/RST/RSTPostBuildProcessor.php b/lib/Docs/RST/RSTPostBuildProcessor.php deleted file mode 100644 index ad003fae..00000000 --- a/lib/Docs/RST/RSTPostBuildProcessor.php +++ /dev/null @@ -1,149 +0,0 @@ -getProjectVersionDocsOutputPath( - $this->sourceDir, - $version, - $language->getCode(), - ); - - $this->filesystem->remove($this->rstFileRepository->findMetaFiles($projectVersionDocsOutputPath)); - - $files = $this->rstFileRepository->findFiles($projectVersionDocsOutputPath); - - foreach ($files as $file) { - $this->processFile($file); - } - } - - private function processFile(string $file): void - { - $contents = $this->getFileContents($file); - - $processedContents = $this->processFileContents( - $file, - $contents, - ); - - $this->filesystem->dumpFile($file, $processedContents); - } - - private function processFileContents(string $file, string $contents): string - { - if (strpos($file, '.html') !== false) { - return $this->processHtmlFile($file, $contents); - } - - return $contents; - } - - private function processHtmlFile( - string $file, - string $contents, - ): string { - // parse out the source file that generated this file - preg_match('/

    {{ DOCS_SOURCE_PATH : (.*) }}<\/p>/', $contents, $match); - - $docsSourcePath = $match[1]; - - // get rid of the special DOCS_SOURCE_PATH : syntax in the contents - $contents = str_replace($match[0], '', $contents); - - $title = $this->extractTitle($contents); - - $contents = $this->fixHeaderAnchors($contents); - - $contents = str_replace('

    SIDEBAR BEGIN

    ', '{% block sidebar %}', $contents); - $contents = str_replace('

    CONTENT BEGIN

    ', '{% endblock %}{% block content %}{% verbatim %}', $contents); - - $contents .= '{% endverbatim %}'; - $contents .= '{% endblock %}'; - - return sprintf( - self::PARAMETERS_TEMPLATE, - $this->escapeYaml($title), - strpos($file, 'index.html') !== false ? 'true' : 'false', - $docsSourcePath, - $contents, - ); - } - - private function escapeYaml(string $text): string - { - return str_replace('\\', '\\\\', $text); - } - - private function getFileContents(string $file): string - { - $contents = $this->rstFileRepository->getFileContents($file); - - // grab the html out of the because that is all we need - preg_match('/(.*)<\/body>/s', $contents, $matches); - - return $matches[1] ?? $contents; - } - - private function fixHeaderAnchors(string $contents): string - { - $contents = preg_replace( - '/
    \n(.*)<\/h(\d)>/', - '
    $3', - $contents, - ); - - assert(is_string($contents)); - - return $contents; - } - - private function extractTitle(string $contents): string - { - preg_match('/

    (.*)<\/h1>/', $contents, $matches); - - $title = ''; - - if ($matches !== []) { - $title = $matches[1]; - } - - return $title; - } -} diff --git a/lib/EventListener/NodeValue.php b/lib/EventListener/NodeValue.php deleted file mode 100644 index 545db993..00000000 --- a/lib/EventListener/NodeValue.php +++ /dev/null @@ -1,25 +0,0 @@ -getNode()->getValue(); - - if (! $value instanceof Node) { - return; - } - - $valueString = str_replace('"', '', $value->getValueString()); - $value->setValue($valueString); - } -} diff --git a/lib/EventListener/TableIncompatibility.php b/lib/EventListener/TableIncompatibility.php deleted file mode 100644 index f0c6c511..00000000 --- a/lib/EventListener/TableIncompatibility.php +++ /dev/null @@ -1,26 +0,0 @@ -getContents(), self::BEFORE)) { - return; - } - - $content = str_replace(self::BEFORE, self::AFTER, $event->getContents()); - $event->setContents($content); - } -} diff --git a/lib/RST/Directive/AdmonitionDirective.php b/lib/RST/Directive/AdmonitionDirective.php deleted file mode 100644 index 1f06b36f..00000000 --- a/lib/RST/Directive/AdmonitionDirective.php +++ /dev/null @@ -1,35 +0,0 @@ -name; - } - - /** @param string[] $options */ - public function processSub( - Parser $parser, - Node|null $document, - string $variable, - string $data, - array $options, - ): Node|null { - return new WrapperNode($document, sprintf('
    ', $this->name, $this->backgroundColor, $this->textColor, $this->icon), '
    '); - } -} diff --git a/lib/RST/Directive/CautionDirective.php b/lib/RST/Directive/CautionDirective.php deleted file mode 100644 index 9c60e228..00000000 --- a/lib/RST/Directive/CautionDirective.php +++ /dev/null @@ -1,13 +0,0 @@ -getValue(); - - $lines = $this->getLines($nodeValue); - - $language = $this->codeBlockLanguageDetector->detectLanguage($data, $lines); - - $node->setLanguage($language); - - $codeBlock = $this->codeBlockRenderer->render($lines, $language); - - $node->setRaw(true); - $node->setValue($codeBlock); - - if ($variable !== '') { - $environment = $parser->getEnvironment(); - $environment->setVariable($variable, $node); - } else { - $document = $parser->getDocument(); - $document->addNode($node); - } - } - - /** @return string[] */ - private function getLines(string $code): array - { - $lines = preg_split('/\r\n|\r|\n/', $code); - assert(is_array($lines)); - - $reversedLines = array_reverse($lines); - - // trim empty lines at the end of the code - foreach ($reversedLines as $key => $line) { - if (trim($line) !== '') { - break; - } - - unset($reversedLines[$key]); - } - - return array_reverse($reversedLines); - } - - public function wantCode(): bool - { - return true; - } -} diff --git a/lib/RST/Directive/ConfigurationBlockDirective.php b/lib/RST/Directive/ConfigurationBlockDirective.php deleted file mode 100644 index fb9b0cab..00000000 --- a/lib/RST/Directive/ConfigurationBlockDirective.php +++ /dev/null @@ -1,55 +0,0 @@ -
      '; - - foreach ($document->getNodes() as $node) { - if (! $node instanceof CodeNode) { - continue; - } - - $language = $node->getLanguage() ?? 'Unknown'; - - $html .= '
    • '; - $html .= '' . strtoupper($language) . ''; - $html .= '
      ' . $node->render() . '
      '; - $html .= '
    • '; - } - - $html .= '
    '; - $html .= '

    '; - - return new RawNode($html); - } -} diff --git a/lib/RST/Directive/HintDirective.php b/lib/RST/Directive/HintDirective.php deleted file mode 100644 index e07132b2..00000000 --- a/lib/RST/Directive/HintDirective.php +++ /dev/null @@ -1,13 +0,0 @@ -', '
    '); - } -} diff --git a/lib/RST/Directive/SectionAuthorDirective.php b/lib/RST/Directive/SectionAuthorDirective.php deleted file mode 100644 index e3a3c1a6..00000000 --- a/lib/RST/Directive/SectionAuthorDirective.php +++ /dev/null @@ -1,53 +0,0 @@ -/', $data, $match); - - if (count($match) === 3) { - $name = $match[1]; - $email = $match[2]; - } else { - $name = $data; - $email = ''; - } - - if ($email !== '') { - $nameHtml = sprintf('%s', $email, $name); - } else { - $nameHtml = $name; - } - - $document = $parser->getDocument(); - - $rawNode = new RawNode(sprintf('', $nameHtml)); - - $document->addNode($rawNode); - } -} diff --git a/lib/RST/Directive/SeeAlsoDirective.php b/lib/RST/Directive/SeeAlsoDirective.php deleted file mode 100644 index 9b2836a7..00000000 --- a/lib/RST/Directive/SeeAlsoDirective.php +++ /dev/null @@ -1,13 +0,0 @@ -', ''); - } -} diff --git a/lib/RST/Directive/TocHeaderDirective.php b/lib/RST/Directive/TocHeaderDirective.php deleted file mode 100644 index c9371ea5..00000000 --- a/lib/RST/Directive/TocHeaderDirective.php +++ /dev/null @@ -1,29 +0,0 @@ -' . $data . ''); - } -} diff --git a/lib/RST/Directive/VersionAddedDirective.php b/lib/RST/Directive/VersionAddedDirective.php deleted file mode 100644 index 8e38a281..00000000 --- a/lib/RST/Directive/VersionAddedDirective.php +++ /dev/null @@ -1,47 +0,0 @@ -getDocument(); - - $renderedNode = ''; - - if ($node !== null) { - $renderedNode = $node->render(); - } - - $nodeFactory = $parser->getNodeFactory(); - - if ($node instanceof QuoteNode) { - $rawNode = $nodeFactory->createRawNode(sprintf('

    New in version %s

    %s

    ', $data, $renderedNode)); - } else { - $rawNode = $nodeFactory->createRawNode(sprintf('

    New in version %s

    %s

    ', $data, $renderedNode)); - } - - $document->addNode($rawNode); - } -} diff --git a/lib/RST/Directive/WarningDirective.php b/lib/RST/Directive/WarningDirective.php deleted file mode 100644 index bbe84f29..00000000 --- a/lib/RST/Directive/WarningDirective.php +++ /dev/null @@ -1,13 +0,0 @@ - Date: Wed, 21 Aug 2024 22:45:52 +0200 Subject: [PATCH 11/30] Add new static website generator Use guides to render rst pages. --- config/services.xml | 4 + config/services/static-website-generator.xml | 6 +- lib/Docs/RST/RSTBuilder.php | 4 - lib/Docs/RST/RSTCopier.php | 1 - .../GuidesRstConverter.php | 49 ++++++++++++ lib/WebsiteBuilder.php | 22 +++--- tests/Docs/CodeBlockRendererTest.php | 77 ------------------- tests/Docs/RST/RSTBuilderTest.php | 32 ++------ tests/Docs/SearchIndexerTest.php | 3 - .../TableIncompatibilityTest.php | 39 ---------- 10 files changed, 72 insertions(+), 165 deletions(-) create mode 100644 lib/Guides/StaticWebsiteGenerator/GuidesRstConverter.php delete mode 100644 tests/Docs/CodeBlockRendererTest.php delete mode 100644 tests/EventListener/TableIncompatibilityTest.php diff --git a/config/services.xml b/config/services.xml index 08856a55..1f4349de 100644 --- a/config/services.xml +++ b/config/services.xml @@ -163,5 +163,9 @@ + + + +
    diff --git a/config/services/static-website-generator.xml b/config/services/static-website-generator.xml index 067f33ce..7bfb5765 100644 --- a/config/services/static-website-generator.xml +++ b/config/services/static-website-generator.xml @@ -16,16 +16,12 @@
    - - - - - + /\/api\// diff --git a/lib/Docs/RST/RSTBuilder.php b/lib/Docs/RST/RSTBuilder.php index 2d1510e0..2701690a 100644 --- a/lib/Docs/RST/RSTBuilder.php +++ b/lib/Docs/RST/RSTBuilder.php @@ -16,7 +16,6 @@ public function __construct( private readonly RSTFileRepository $rstFileRepository, private readonly RSTCopier $rstCopier, private readonly DocumentsBuilder $builder, - private readonly RSTPostBuildProcessor $rstPostBuildProcessor, private readonly Filesystem $filesystem, private readonly string $sourceDir, private readonly string $docsDir, @@ -32,9 +31,6 @@ public function buildRSTDocs(Project $project, ProjectVersion $version, RSTLangu // build the rst and prepare html for ./bin/console build-website $this->buildRst($project, $version, $language); - // process the built html and do extra things to the html - $this->rstPostBuildProcessor->postRstBuild($project, $version, $language); - return $this->builder->getDocuments(); } diff --git a/lib/Docs/RST/RSTCopier.php b/lib/Docs/RST/RSTCopier.php index 194ec1e5..f8ef1d73 100644 --- a/lib/Docs/RST/RSTCopier.php +++ b/lib/Docs/RST/RSTCopier.php @@ -12,7 +12,6 @@ use function file_exists; use function is_string; use function preg_replace; -use function sprintf; use function str_replace; /** @final */ diff --git a/lib/Guides/StaticWebsiteGenerator/GuidesRstConverter.php b/lib/Guides/StaticWebsiteGenerator/GuidesRstConverter.php new file mode 100644 index 00000000..0a015840 --- /dev/null +++ b/lib/Guides/StaticWebsiteGenerator/GuidesRstConverter.php @@ -0,0 +1,49 @@ +parser->parse($sourceFile->getContents(), 'rst'); + + $renderContext = RenderContext::forDocument( + $document, + [$document], + new Filesystem(new NullAdapter()), + new Filesystem(new NullAdapter()), + '/', + 'html', + new ProjectNode(), + ); + + return $this->nodeRenderer->render($document, $renderContext); + } +} diff --git a/lib/WebsiteBuilder.php b/lib/WebsiteBuilder.php index 3c4fd62d..5acf6b59 100644 --- a/lib/WebsiteBuilder.php +++ b/lib/WebsiteBuilder.php @@ -103,17 +103,17 @@ private function buildWebpackAssets(OutputInterface $output, string $buildDir, b { $output->writeln(sprintf(' - running npm run %s ', $isPublishableEnv ? 'build' : 'dev')); - $this->filesystem->remove((array) glob($this->webpackBuildDir . '/*')); - - $process = $this->processFactory->run(sprintf( - 'cd %s && npm run %s', - $this->rootDir, - $isPublishableEnv ? 'build' : 'dev', - )); - - if ($output->isVerbose()) { - $output->write($process->getOutput()); - } +// $this->filesystem->remove((array) glob($this->webpackBuildDir . '/*')); +// +// $process = $this->processFactory->run(sprintf( +// 'cd %s && npm run %s', +// $this->rootDir, +// $isPublishableEnv ? 'build' : 'dev', +// )); + +// if ($output->isVerbose()) { +// $output->write($process->getOutput()); +// } // Copy built assets if this is a publishable build if ($isPublishableEnv) { diff --git a/tests/Docs/CodeBlockRendererTest.php b/tests/Docs/CodeBlockRendererTest.php deleted file mode 100644 index f2353d53..00000000 --- a/tests/Docs/CodeBlockRendererTest.php +++ /dev/null @@ -1,77 +0,0 @@ -codeBlockWithLineNumbersRenderer->expects(self::once()) - ->method('render') - ->with($lines, $language) - ->willReturn('expected'); - - self::assertSame('expected', $this->codeBlockRenderer->render($lines, $language)); - } - - #[DataProvider('getConsoleLanguages')] - public function testRenderConsole(string $consoleLanguage): void - { - $lines = [ - 'codeBlockConsoleRenderer->expects(self::once()) - ->method('render') - ->with($lines) - ->willReturn('expected'); - - self::assertSame('expected', $this->codeBlockRenderer->render($lines, $consoleLanguage)); - } - - /** @return string[][] */ - public static function getConsoleLanguages(): array - { - return [ - ['console'], - ['bash'], - ['sh'], - ]; - } - - protected function setUp(): void - { - $this->codeBlockConsoleRenderer = $this->createMock(CodeBlockConsoleRenderer::class); - $this->codeBlockWithLineNumbersRenderer = $this->createMock(CodeBlockWithLineNumbersRenderer::class); - - $this->codeBlockRenderer = new CodeBlockRenderer( - $this->codeBlockConsoleRenderer, - $this->codeBlockWithLineNumbersRenderer, - ); - } -} diff --git a/tests/Docs/RST/RSTBuilderTest.php b/tests/Docs/RST/RSTBuilderTest.php index ec8368bd..40278614 100644 --- a/tests/Docs/RST/RSTBuilderTest.php +++ b/tests/Docs/RST/RSTBuilderTest.php @@ -4,16 +4,15 @@ namespace Doctrine\Website\Tests\Docs\RST; -use Doctrine\RST\Builder; use Doctrine\RST\Builder\Documents; -use Doctrine\RST\Nodes\DocumentNode; +use Doctrine\Website\Docs\RST\DocumentsBuilder; use Doctrine\Website\Docs\RST\RSTBuilder; use Doctrine\Website\Docs\RST\RSTCopier; use Doctrine\Website\Docs\RST\RSTFileRepository; use Doctrine\Website\Docs\RST\RSTLanguage; -use Doctrine\Website\Docs\RST\RSTPostBuildProcessor; use Doctrine\Website\Model\ProjectVersion; use Doctrine\Website\Tests\TestCase; +use phpDocumentor\Guides\Nodes\DocumentNode; use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Filesystem\Filesystem; @@ -23,9 +22,7 @@ class RSTBuilderTest extends TestCase private RSTCopier&MockObject $rstCopier; - private Builder&MockObject $builder; - - private RSTPostBuildProcessor&MockObject $rstPostBuildProcessor; + private DocumentsBuilder&MockObject $builder; private Filesystem&MockObject $filesystem; @@ -39,8 +36,7 @@ protected function setUp(): void { $this->rstFileRepository = $this->createMock(RSTFileRepository::class); $this->rstCopier = $this->createMock(RSTCopier::class); - $this->builder = $this->createMock(Builder::class); - $this->rstPostBuildProcessor = $this->createMock(RSTPostBuildProcessor::class); + $this->builder = $this->createMock(DocumentsBuilder::class); $this->filesystem = $this->createMock(Filesystem::class); $this->sourceDir = '/source'; $this->docsDir = '/docs'; @@ -49,7 +45,6 @@ protected function setUp(): void $this->rstFileRepository, $this->rstCopier, $this->builder, - $this->rstPostBuildProcessor, $this->filesystem, $this->sourceDir, $this->docsDir, @@ -77,10 +72,6 @@ public function testBuildRSTDocs(): void ->method('remove') ->with(['/test1', '/test2']); - $this->builder->expects(self::once()) - ->method('recreate') - ->willReturn($this->builder); - $this->builder->expects(self::once()) ->method('build') ->with( @@ -88,23 +79,14 @@ public function testBuildRSTDocs(): void '/source/projects/docs-slug/en/version-slug', ); - $this->rstPostBuildProcessor->expects(self::once()) - ->method('postRstBuild') - ->with($project, $version); - - $document1 = $this->createMock(DocumentNode::class); - $document2 = $this->createMock(DocumentNode::class); + $document1 = new DocumentNode('test1', 'test1'); + $document2 = new DocumentNode('test2', 'test2'); $documentsArray = [$document1, $document2]; - $documents = $this->createMock(Documents::class); - - $documents->expects(self::once()) - ->method('getAll') - ->willReturn($documentsArray); $this->builder->expects(self::once()) ->method('getDocuments') - ->willReturn($documents); + ->willReturn($documentsArray); $english = new RSTLanguage('en', '/en'); diff --git a/tests/Docs/SearchIndexerTest.php b/tests/Docs/SearchIndexerTest.php index d9de01b8..b4847261 100644 --- a/tests/Docs/SearchIndexerTest.php +++ b/tests/Docs/SearchIndexerTest.php @@ -9,10 +9,8 @@ use Doctrine\Common\EventManager; use Doctrine\RST\Builder; use Doctrine\RST\Configuration; -use Doctrine\RST\Event\PreNodeRenderEvent; use Doctrine\RST\Kernel; use Doctrine\Website\Docs\SearchIndexer; -use Doctrine\Website\EventListener\NodeValue; use Doctrine\Website\Model\ProjectVersion; use Doctrine\Website\Tests\TestCase; use PHPUnit\Framework\MockObject\MockObject; @@ -233,7 +231,6 @@ public function testBuildSearchIndexesContainingQuotes(): void ->willReturn($index); $eventManager = new EventManager(); - $eventManager->addEventListener(PreNodeRenderEvent::PRE_NODE_RENDER, new NodeValue()); $configuration = new Configuration(); $configuration->setEventManager($eventManager); $configuration->setUseCachedMetas(false); diff --git a/tests/EventListener/TableIncompatibilityTest.php b/tests/EventListener/TableIncompatibilityTest.php deleted file mode 100644 index df165f56..00000000 --- a/tests/EventListener/TableIncompatibilityTest.php +++ /dev/null @@ -1,39 +0,0 @@ -preParseDocument($event); - - self::assertSame('content', $event->getContents()); - } - - public function testPreParseDocumentTableChange(): void - { - $content = '#| **SQL Server** | +----------------------------------------------------------+#'; - - $parser = self::createStub(Parser::class); - $event = new PreParseDocumentEvent($parser, $content); - - $eventListener = new TableIncompatibility(); - $eventListener->preParseDocument($event); - - $expected = '#| **SQL Server** | | |#'; - - self::assertSame($expected, $event->getContents()); - } -} From 971020a87ac079c67bc9010a833e831e0d13cafa Mon Sep 17 00:00:00 2001 From: Jaapio Date: Fri, 23 Aug 2024 17:10:34 +0200 Subject: [PATCH 12/30] Fix doc style --- lib/Docs/RST/DocumentsBuilder.php | 2 +- lib/Docs/RST/Guides.php | 6 ++-- lib/Docs/RST/RSTBuilder.php | 2 +- lib/Docs/SearchIndexer.php | 33 +++++-------------- lib/Guides/Compiler/SidebarTransformer.php | 3 +- lib/Guides/Renderer/CodeBlockRenderer.php | 3 +- .../GuidesRstConverter.php | 4 ++- lib/WebsiteBuilder.php | 22 ++++++------- phpstan.neon.dist | 6 ---- tests/Docs/RST/RSTBuilderTest.php | 13 ++++---- tests/Docs/SearchIndexerTest.php | 2 +- 11 files changed, 38 insertions(+), 58 deletions(-) diff --git a/lib/Docs/RST/DocumentsBuilder.php b/lib/Docs/RST/DocumentsBuilder.php index 20f60d2d..da0cabcd 100644 --- a/lib/Docs/RST/DocumentsBuilder.php +++ b/lib/Docs/RST/DocumentsBuilder.php @@ -4,7 +4,7 @@ namespace Doctrine\Website\Docs\RST; -use Doctrine\RST\Nodes\DocumentNode; +use phpDocumentor\Guides\Nodes\DocumentNode; interface DocumentsBuilder { diff --git a/lib/Docs/RST/Guides.php b/lib/Docs/RST/Guides.php index 9a9cfb9d..3d4c0258 100644 --- a/lib/Docs/RST/Guides.php +++ b/lib/Docs/RST/Guides.php @@ -18,11 +18,11 @@ use phpDocumentor\Guides\Nodes\ProjectNode; use phpDocumentor\Guides\Twig\Theme\ThemeManager; -final class Guides implements DocumentsBuilder +final readonly class Guides implements DocumentsBuilder { public function __construct( - private readonly CommandBus $commandBus, - private readonly ThemeManager $themeManager, + private CommandBus $commandBus, + private ThemeManager $themeManager, ) { } diff --git a/lib/Docs/RST/RSTBuilder.php b/lib/Docs/RST/RSTBuilder.php index 2701690a..2c5439df 100644 --- a/lib/Docs/RST/RSTBuilder.php +++ b/lib/Docs/RST/RSTBuilder.php @@ -4,9 +4,9 @@ namespace Doctrine\Website\Docs\RST; -use Doctrine\RST\Nodes\DocumentNode; use Doctrine\Website\Model\Project; use Doctrine\Website\Model\ProjectVersion; +use phpDocumentor\Guides\Nodes\DocumentNode; use Symfony\Component\Filesystem\Filesystem; /** @final */ diff --git a/lib/Docs/SearchIndexer.php b/lib/Docs/SearchIndexer.php index d0d77829..af4aa1c6 100644 --- a/lib/Docs/SearchIndexer.php +++ b/lib/Docs/SearchIndexer.php @@ -6,17 +6,15 @@ use Algolia\AlgoliaSearch\SearchClient; use Algolia\AlgoliaSearch\SearchIndex; -use Doctrine\RST\Nodes\DocumentNode; -use Doctrine\RST\Nodes\Node; -use Doctrine\RST\Nodes\ParagraphNode; -use Doctrine\RST\Nodes\TitleNode; use Doctrine\Website\Model\Project; use Doctrine\Website\Model\ProjectVersion; +use phpDocumentor\Guides\Nodes\DocumentNode; +use phpDocumentor\Guides\Nodes\Node; +use phpDocumentor\Guides\Nodes\ParagraphNode; +use phpDocumentor\Guides\Nodes\TitleNode; -use function in_array; use function is_string; use function md5; -use function preg_match; use function strip_tags; use function strpos; @@ -76,10 +74,7 @@ private function buildDocumentSearchRecords( Project $project, ProjectVersion $version, ): void { - $environment = $document->getEnvironment(); - - $slug = $environment->getUrl(); - $currentLink = $slug; + $currentLink = $slug = $document->getFilePath() . '.html'; $current = [ 'h1' => null, @@ -89,11 +84,7 @@ private function buildDocumentSearchRecords( 'h5' => null, ]; - $nodeTypes = [TitleNode::class, ParagraphNode::class]; - - $nodes = $document->getNodes(static function (Node $node) use ($nodeTypes): bool { - return in_array($node::class, $nodeTypes, true); - }); + $nodes = $document->getNodes(TitleNode::class); foreach ($nodes as $node) { $value = $this->renderNodeValue($node); @@ -102,18 +93,10 @@ private function buildDocumentSearchRecords( continue; } - $html = $node->render(); - - if ($node instanceof TitleNode) { - preg_match('/.*<\/a>/iU', $html, $match); - - $currentLink = $slug . '.html' . (isset($match[1]) ? '#' . $match[1] : ''); - } - $records[] = $this->getNodeSearchRecord( $node, $current, - $currentLink, + $currentLink . '#' . $node->getId(), $project, $version, ); @@ -128,7 +111,7 @@ private function buildDocumentSearchRecords( private function getNodeSearchRecord( Node $node, array &$current, - string &$currentLink, + string $currentLink, Project $project, ProjectVersion $version, ): array { diff --git a/lib/Guides/Compiler/SidebarTransformer.php b/lib/Guides/Compiler/SidebarTransformer.php index 9b7a6718..41005a46 100644 --- a/lib/Guides/Compiler/SidebarTransformer.php +++ b/lib/Guides/Compiler/SidebarTransformer.php @@ -4,13 +4,14 @@ namespace Doctrine\Website\Guides\Compiler; -use Doctrine\RST\Nodes\TocNode; use Override; use phpDocumentor\Guides\Compiler\CompilerContext; use phpDocumentor\Guides\Compiler\NodeTransformer; +use phpDocumentor\Guides\Nodes\Menu\TocNode; use phpDocumentor\Guides\Nodes\Node; use phpDocumentor\Guides\RestructuredText\Nodes\GeneralDirectiveNode; +/** @implements NodeTransformer */ final class SidebarTransformer implements NodeTransformer { #[Override] diff --git a/lib/Guides/Renderer/CodeBlockRenderer.php b/lib/Guides/Renderer/CodeBlockRenderer.php index c649f08e..b946a601 100644 --- a/lib/Guides/Renderer/CodeBlockRenderer.php +++ b/lib/Guides/Renderer/CodeBlockRenderer.php @@ -16,6 +16,7 @@ use function explode; use function in_array; +/** @implements NodeRenderer */ final class CodeBlockRenderer implements NodeRenderer { private const CONSOLE_LANGUAGES = ['terminal', 'bash', 'sh', 'console']; @@ -38,7 +39,7 @@ public function render(Node $node, RenderContext $renderContext): string { $lines = explode("\n", $node->getValue()); $language = $this->codeBlockLanguageDetector->detectLanguage( - $node->getLanguage(), + $node->getLanguage() ?? 'php', $lines, ); diff --git a/lib/Guides/StaticWebsiteGenerator/GuidesRstConverter.php b/lib/Guides/StaticWebsiteGenerator/GuidesRstConverter.php index 0a015840..0090fbda 100644 --- a/lib/Guides/StaticWebsiteGenerator/GuidesRstConverter.php +++ b/lib/Guides/StaticWebsiteGenerator/GuidesRstConverter.php @@ -10,12 +10,14 @@ use League\Flysystem\Filesystem; use Override; use phpDocumentor\Guides\NodeRenderers\NodeRenderer; +use phpDocumentor\Guides\Nodes\DocumentNode; use phpDocumentor\Guides\Nodes\ProjectNode; use phpDocumentor\Guides\Parser; use phpDocumentor\Guides\RenderContext; -class GuidesRstConverter implements SourceFileConverter +final readonly class GuidesRstConverter implements SourceFileConverter { + /** @param NodeRenderer $nodeRenderer */ public function __construct( private Parser $parser, private NodeRenderer $nodeRenderer, diff --git a/lib/WebsiteBuilder.php b/lib/WebsiteBuilder.php index 5acf6b59..3c4fd62d 100644 --- a/lib/WebsiteBuilder.php +++ b/lib/WebsiteBuilder.php @@ -103,17 +103,17 @@ private function buildWebpackAssets(OutputInterface $output, string $buildDir, b { $output->writeln(sprintf(' - running npm run %s ', $isPublishableEnv ? 'build' : 'dev')); -// $this->filesystem->remove((array) glob($this->webpackBuildDir . '/*')); -// -// $process = $this->processFactory->run(sprintf( -// 'cd %s && npm run %s', -// $this->rootDir, -// $isPublishableEnv ? 'build' : 'dev', -// )); - -// if ($output->isVerbose()) { -// $output->write($process->getOutput()); -// } + $this->filesystem->remove((array) glob($this->webpackBuildDir . '/*')); + + $process = $this->processFactory->run(sprintf( + 'cd %s && npm run %s', + $this->rootDir, + $isPublishableEnv ? 'build' : 'dev', + )); + + if ($output->isVerbose()) { + $output->write($process->getOutput()); + } // Copy built assets if this is a publishable build if ($isPublishableEnv) { diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 10d4e39f..5aebebb0 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -13,11 +13,5 @@ parameters: message: "#While loop condition is always true#" path: "lib/Commands/BuildWebsiteCommand.php" count: 1 - - # Temporary final classes in tests are covered by nunomaduro/mock-final-classes until the refactorings start - message: "#has unresolvable native type#" - path: "tests/" - - # Temporary final classes in tests are covered by nunomaduro/mock-final-classes until the refactorings start - message: "#contains unresolvable type#" - path: "tests/" - message: "#::\\$id is never read, only written#" diff --git a/tests/Docs/RST/RSTBuilderTest.php b/tests/Docs/RST/RSTBuilderTest.php index 40278614..b8d62650 100644 --- a/tests/Docs/RST/RSTBuilderTest.php +++ b/tests/Docs/RST/RSTBuilderTest.php @@ -4,7 +4,6 @@ namespace Doctrine\Website\Tests\Docs\RST; -use Doctrine\RST\Builder\Documents; use Doctrine\Website\Docs\RST\DocumentsBuilder; use Doctrine\Website\Docs\RST\RSTBuilder; use Doctrine\Website\Docs\RST\RSTCopier; @@ -34,12 +33,12 @@ class RSTBuilderTest extends TestCase protected function setUp(): void { - $this->rstFileRepository = $this->createMock(RSTFileRepository::class); - $this->rstCopier = $this->createMock(RSTCopier::class); - $this->builder = $this->createMock(DocumentsBuilder::class); - $this->filesystem = $this->createMock(Filesystem::class); - $this->sourceDir = '/source'; - $this->docsDir = '/docs'; + $this->rstFileRepository = $this->createMock(RSTFileRepository::class); + $this->rstCopier = $this->createMock(RSTCopier::class); + $this->builder = $this->createMock(DocumentsBuilder::class); + $this->filesystem = $this->createMock(Filesystem::class); + $this->sourceDir = '/source'; + $this->docsDir = '/docs'; $this->rstBuilder = new RSTBuilder( $this->rstFileRepository, diff --git a/tests/Docs/SearchIndexerTest.php b/tests/Docs/SearchIndexerTest.php index b4847261..47d8983a 100644 --- a/tests/Docs/SearchIndexerTest.php +++ b/tests/Docs/SearchIndexerTest.php @@ -230,7 +230,7 @@ public function testBuildSearchIndexesContainingQuotes(): void ->with(SearchIndexer::INDEX_NAME) ->willReturn($index); - $eventManager = new EventManager(); + $eventManager = new EventManager(); $configuration = new Configuration(); $configuration->setEventManager($eventManager); $configuration->setUseCachedMetas(false); From d5a3cc643a18eb59afa84d142fc883f24c612051 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Tue, 17 Sep 2024 21:28:26 +0200 Subject: [PATCH 13/30] Use guides to build search index --- config/services.xml | 9 ++- lib/Docs/RST/Guides.php | 30 +++---- lib/Docs/RST/GuidesParser.php | 46 +++++++++++ lib/Docs/SearchIndexer.php | 78 ++++++++++++------- .../GuidesRstConverter.php | 3 + templates/guides/website-document.html.twig | 13 ++++ tests/Docs/SearchIndexerTest.php | 39 ++++------ 7 files changed, 146 insertions(+), 72 deletions(-) create mode 100644 lib/Docs/RST/GuidesParser.php create mode 100644 templates/guides/website-document.html.twig diff --git a/config/services.xml b/config/services.xml index 1f4349de..09449cf0 100644 --- a/config/services.xml +++ b/config/services.xml @@ -150,6 +150,7 @@ + @@ -165,7 +166,13 @@ - + + + + website-document.html.twig + phpDocumentor\Guides\Nodes\DocumentNode + + diff --git a/lib/Docs/RST/Guides.php b/lib/Docs/RST/Guides.php index 3d4c0258..3f607127 100644 --- a/lib/Docs/RST/Guides.php +++ b/lib/Docs/RST/Guides.php @@ -5,23 +5,23 @@ namespace Doctrine\Website\Docs\RST; use Flyfinder\Finder; -use Flyfinder\Specification\Glob; use League\Flysystem\Adapter\Local; use League\Flysystem\Filesystem; use League\Tactician\CommandBus; use Override; -use phpDocumentor\Guides\Compiler\CompilerContext; -use phpDocumentor\Guides\Handlers\CompileDocumentsCommand; -use phpDocumentor\Guides\Handlers\ParseDirectoryCommand; use phpDocumentor\Guides\Handlers\RenderCommand; use phpDocumentor\Guides\Nodes\DocumentNode; use phpDocumentor\Guides\Nodes\ProjectNode; use phpDocumentor\Guides\Twig\Theme\ThemeManager; -final readonly class Guides implements DocumentsBuilder +final class Guides implements DocumentsBuilder { + /** @var DocumentNode[] */ + private array $documents = []; + public function __construct( private CommandBus $commandBus, + private GuidesParser $guidesParser, private ThemeManager $themeManager, ) { } @@ -32,20 +32,8 @@ public function build(string $directory, string $targetDirectory = 'output'): vo $sourceFileSystem = new Filesystem(new Local($directory)); $sourceFileSystem->addPlugin(new Finder()); - $projectNode = new ProjectNode(); - $documents = $this->commandBus->handle( - new ParseDirectoryCommand( - $sourceFileSystem, - '', - 'rst', - $projectNode, - new Glob('/**/sidebar.rst'), - ), - ); - - $documents = $this->commandBus->handle( - new CompileDocumentsCommand($documents, new CompilerContext($projectNode)), - ); + $projectNode = new ProjectNode(); + $this->documents = $this->guidesParser->parse($directory, $projectNode); $destinationFileSystem = new Filesystem(new Local($targetDirectory)); $this->themeManager->useTheme('doctrine'); @@ -53,7 +41,7 @@ public function build(string $directory, string $targetDirectory = 'output'): vo $this->commandBus->handle( new RenderCommand( 'html', - $documents, + $this->documents, $sourceFileSystem, $destinationFileSystem, $projectNode, @@ -65,6 +53,6 @@ public function build(string $directory, string $targetDirectory = 'output'): vo #[Override] public function getDocuments(): array { - return []; + return $this->documents; } } diff --git a/lib/Docs/RST/GuidesParser.php b/lib/Docs/RST/GuidesParser.php new file mode 100644 index 00000000..c035bf0d --- /dev/null +++ b/lib/Docs/RST/GuidesParser.php @@ -0,0 +1,46 @@ +addPlugin(new Finder()); + + $projectNode ??= new ProjectNode(); + $documents = $this->commandBus->handle( + new ParseDirectoryCommand( + $sourceFileSystem, + '', + 'rst', + $projectNode, + new Glob('/**/sidebar.rst'), + ), + ); + + return $this->commandBus->handle( + new CompileDocumentsCommand($documents, new CompilerContext($projectNode)), + ); + } +} diff --git a/lib/Docs/SearchIndexer.php b/lib/Docs/SearchIndexer.php index af4aa1c6..0e428e7c 100644 --- a/lib/Docs/SearchIndexer.php +++ b/lib/Docs/SearchIndexer.php @@ -8,15 +8,16 @@ use Algolia\AlgoliaSearch\SearchIndex; use Doctrine\Website\Model\Project; use Doctrine\Website\Model\ProjectVersion; +use Generator; +use phpDocumentor\Guides\Nodes\CompoundNode; use phpDocumentor\Guides\Nodes\DocumentNode; use phpDocumentor\Guides\Nodes\Node; use phpDocumentor\Guides\Nodes\ParagraphNode; use phpDocumentor\Guides\Nodes\TitleNode; -use function is_string; use function md5; +use function str_replace; use function strip_tags; -use function strpos; /** * Influenced by Laravel.com website code search indexes that also use Algolia. @@ -61,20 +62,20 @@ public function buildSearchIndexes( $records = []; foreach ($documents as $document) { - $this->buildDocumentSearchRecords($document, $records, $project, $version); + foreach ($this->buildDocumentSearchRecords($document, $project, $version) as $record) { + $records[] = $record; + } } $this->getSearchIndex()->saveObjects($records, ['autoGenerateObjectIDIfNotExist' => true]); } - /** @param mixed[][] $records */ private function buildDocumentSearchRecords( DocumentNode $document, - array &$records, Project $project, ProjectVersion $version, - ): void { - $currentLink = $slug = $document->getFilePath() . '.html'; + ): Generator { + $currentLink = $document->getFilePath() . '.html'; $current = [ 'h1' => null, @@ -84,22 +85,37 @@ private function buildDocumentSearchRecords( 'h5' => null, ]; - $nodes = $document->getNodes(TitleNode::class); + yield from $this->iterateNodes($document, $current, $currentLink, $project, $version); + } + + /** + * @param array $current + * @param CompoundNode $node + * + * @return Generator + */ + private function iterateNodes(CompoundNode $node, array $current, string $currentLink, Project $project, ProjectVersion $version): Generator + { + foreach ($node->getChildren() as $child) { + if ($child instanceof TitleNode) { + yield $this->getNodeSearchRecord($child, $current, $currentLink, $project, $version); + + continue; + } + + if ($child instanceof ParagraphNode) { + yield $this->getNodeSearchRecord($child, $current, $currentLink, $project, $version); - foreach ($nodes as $node) { - $value = $this->renderNodeValue($node); + continue; + } - if (strpos($value, '{{ DOCS_SOURCE_PATH') !== false) { + if (! ($child instanceof CompoundNode)) { continue; } - $records[] = $this->getNodeSearchRecord( - $node, - $current, - $currentLink . '#' . $node->getId(), - $project, - $version, - ); + foreach ($this->iterateNodes($child, $current, $currentLink, $project, $version) as $record) { + yield $record; + } } } @@ -163,8 +179,8 @@ private function getRank(Node $node): int if ($node instanceof TitleNode) { $elementName = 'h' . $node->getLevel(); - } elseif ($node instanceof ParagraphNode) { - $elementName = 'p'; + + return $ranks[$elementName]; } return $ranks[$elementName]; @@ -172,17 +188,25 @@ private function getRank(Node $node): int private function renderNodeValue(Node $node): string { - $nodeValue = $node->getValue(); - - if ($nodeValue === null) { - return ''; + if ($node instanceof TitleNode) { + return $this->stripContent($node->toString()); } - if (is_string($nodeValue)) { - return $nodeValue; + if ($node instanceof ParagraphNode) { + $content = ''; + foreach ($node->getChildren() as $child) { + $content .= $this->stripContent($child->toString()); + } + + return $content; } - return $nodeValue->render(); + return ''; + } + + private function stripContent(string $content): string + { + return str_replace(['"', '\''], '', $content); } private function getSearchIndex(): SearchIndex diff --git a/lib/Guides/StaticWebsiteGenerator/GuidesRstConverter.php b/lib/Guides/StaticWebsiteGenerator/GuidesRstConverter.php index 0090fbda..41f9f2a5 100644 --- a/lib/Guides/StaticWebsiteGenerator/GuidesRstConverter.php +++ b/lib/Guides/StaticWebsiteGenerator/GuidesRstConverter.php @@ -14,6 +14,7 @@ use phpDocumentor\Guides\Nodes\ProjectNode; use phpDocumentor\Guides\Parser; use phpDocumentor\Guides\RenderContext; +use phpDocumentor\Guides\Twig\Theme\ThemeManager; final readonly class GuidesRstConverter implements SourceFileConverter { @@ -21,6 +22,7 @@ public function __construct( private Parser $parser, private NodeRenderer $nodeRenderer, + private ThemeManager $themeManager, ) { } @@ -34,6 +36,7 @@ public function getExtensions(): array #[Override] public function convertSourceFile(SourceFile $sourceFile): string { + $this->themeManager->useTheme('doctrine'); $document = $this->parser->parse($sourceFile->getContents(), 'rst'); $renderContext = RenderContext::forDocument( diff --git a/templates/guides/website-document.html.twig b/templates/guides/website-document.html.twig new file mode 100644 index 00000000..d8783b79 --- /dev/null +++ b/templates/guides/website-document.html.twig @@ -0,0 +1,13 @@ +{% verbatim %} +{% block content %}{% verbatim %} +{% endverbatim %} + {% for child in node.children -%} + {% if child is not tocNode %} + {{ renderNode(child) }} + {% endif %} + {%~ endfor -%} + +{{ "{% endverbatim %}" }} +{% verbatim %} + {% endblock %} +{% endverbatim %} diff --git a/tests/Docs/SearchIndexerTest.php b/tests/Docs/SearchIndexerTest.php index 47d8983a..805a0113 100644 --- a/tests/Docs/SearchIndexerTest.php +++ b/tests/Docs/SearchIndexerTest.php @@ -6,16 +6,15 @@ use Algolia\AlgoliaSearch\SearchClient; use Algolia\AlgoliaSearch\SearchIndex; -use Doctrine\Common\EventManager; -use Doctrine\RST\Builder; -use Doctrine\RST\Configuration; -use Doctrine\RST\Kernel; +use Doctrine\Website\Application; +use Doctrine\Website\Docs\RST\GuidesParser; use Doctrine\Website\Docs\SearchIndexer; use Doctrine\Website\Model\ProjectVersion; use Doctrine\Website\Tests\TestCase; +use phpDocumentor\Guides\Nodes\DocumentNode; use PHPUnit\Framework\MockObject\MockObject; -use function sys_get_temp_dir; +use function assert; class SearchIndexerTest extends TestCase { @@ -78,14 +77,7 @@ public function testBuildSearchIndexes(): void ->with(SearchIndexer::INDEX_NAME) ->willReturn($index); - $configuration = new Configuration(); - $configuration->setUseCachedMetas(false); - $kernel = new Kernel($configuration); - $builder = new Builder($kernel); - - $builder->build(__DIR__ . '/resources/search-indexer', sys_get_temp_dir() . '/search-indexer'); - - $documents = $builder->getDocuments()->getAll(); + $documents = $this->buildDocuments(__DIR__ . '/resources/search-indexer'); $expectedRecords = [ [ @@ -230,16 +222,7 @@ public function testBuildSearchIndexesContainingQuotes(): void ->with(SearchIndexer::INDEX_NAME) ->willReturn($index); - $eventManager = new EventManager(); - $configuration = new Configuration(); - $configuration->setEventManager($eventManager); - $configuration->setUseCachedMetas(false); - $kernel = new Kernel($configuration); - $builder = new Builder($kernel); - - $builder->build(__DIR__ . '/resources/search-indexer-with-quotes', sys_get_temp_dir() . '/search-indexer-with-quotes'); - - $documents = $builder->getDocuments()->getAll(); + $documents = $this->buildDocuments(__DIR__ . '/resources/search-indexer-with-quotes'); $expectedRecords = [ [ @@ -289,4 +272,14 @@ public function testBuildSearchIndexesContainingQuotes(): void $this->searchIndexer->buildSearchIndexes($project, $version, $documents); } + + /** @return DocumentNode[] */ + private function buildDocuments(string $directory): array + { + $container = Application::getContainer('test'); + $parser = $container->get(GuidesParser::class); + assert($parser instanceof GuidesParser); + + return $parser->parse($directory); + } } From 08e4916553def132adf389efe033b20582c73469 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Tue, 17 Sep 2024 23:14:58 +0200 Subject: [PATCH 14/30] Bump guides --- composer.lock | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/composer.lock b/composer.lock index 37c82996..2749d0b4 100644 --- a/composer.lock +++ b/composer.lock @@ -2569,16 +2569,16 @@ }, { "name": "phpdocumentor/guides", - "version": "1.3.5", + "version": "1.3.10", "source": { "type": "git", "url": "https://github.com/phpDocumentor/guides-core.git", - "reference": "c6766d529735adf8d1b32c8b1c0169aaf448e565" + "reference": "a431f1d1f398687bf93e80ef525b83e21f75b15b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/guides-core/zipball/c6766d529735adf8d1b32c8b1c0169aaf448e565", - "reference": "c6766d529735adf8d1b32c8b1c0169aaf448e565", + "url": "https://api.github.com/repos/phpDocumentor/guides-core/zipball/a431f1d1f398687bf93e80ef525b83e21f75b15b", + "reference": "a431f1d1f398687bf93e80ef525b83e21f75b15b", "shasum": "" }, "require": { @@ -2615,22 +2615,22 @@ "homepage": "https://www.phpdoc.org", "support": { "issues": "https://github.com/phpDocumentor/guides-core/issues", - "source": "https://github.com/phpDocumentor/guides-core/tree/1.3.5" + "source": "https://github.com/phpDocumentor/guides-core/tree/1.3.10" }, - "time": "2024-05-07T18:12:18+00:00" + "time": "2024-09-09T07:04:46+00:00" }, { "name": "phpdocumentor/guides-restructured-text", - "version": "1.3.8", + "version": "1.3.10", "source": { "type": "git", "url": "https://github.com/phpDocumentor/guides-restructured-text.git", - "reference": "916a09f05adb85763aa23bb2c1db86d35214e6aa" + "reference": "7719c777cdd49ce5dc7db61a6cd96cf04e3b1e63" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/guides-restructured-text/zipball/916a09f05adb85763aa23bb2c1db86d35214e6aa", - "reference": "916a09f05adb85763aa23bb2c1db86d35214e6aa", + "url": "https://api.github.com/repos/phpDocumentor/guides-restructured-text/zipball/7719c777cdd49ce5dc7db61a6cd96cf04e3b1e63", + "reference": "7719c777cdd49ce5dc7db61a6cd96cf04e3b1e63", "shasum": "" }, "require": { @@ -2653,9 +2653,9 @@ "description": "Adds reStructuredText Markup support to the phpDocumentor's Guides library.", "homepage": "https://www.phpdoc.org", "support": { - "source": "https://github.com/phpDocumentor/guides-restructured-text/tree/1.3.8" + "source": "https://github.com/phpDocumentor/guides-restructured-text/tree/1.3.10" }, - "time": "2024-05-19T20:03:16+00:00" + "time": "2024-09-06T17:05:36+00:00" }, { "name": "psr/cache", From 4ff3848fbbdcf7147cf1d29d6e6ea645ccf7cfe0 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Wed, 18 Sep 2024 23:15:49 +0200 Subject: [PATCH 15/30] Fix issue with tables in doctrine1 docs --- lib/Docs/RST/RSTCopier.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Docs/RST/RSTCopier.php b/lib/Docs/RST/RSTCopier.php index f8ef1d73..0b7d590f 100644 --- a/lib/Docs/RST/RSTCopier.php +++ b/lib/Docs/RST/RSTCopier.php @@ -139,6 +139,7 @@ private function fixRSTSyntax(Project $project, string $content): string // stuff from doctrine1 docs if ($project->getSlug() === 'doctrine1') { $content = preg_replace([ + "/\n===\r\n/", "/:code:(.*)\n/", '/:php:(.*):`(.*)`/', '/:file:`(.*)`/', @@ -148,6 +149,7 @@ private function fixRSTSyntax(Project $project, string $content): string '/.. rubric:: Notes/', "/.. sidebar:: (.*)\n/", ], [ + "\n=== ===\r\n", '$1', '$2', '$1', From 2e2ec879bcf33412267db7b410a307ce3c7ccb2a Mon Sep 17 00:00:00 2001 From: Jaapio Date: Wed, 18 Sep 2024 23:35:36 +0200 Subject: [PATCH 16/30] Fix test with new rendering --- tests/FunctionalTest.php | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/tests/FunctionalTest.php b/tests/FunctionalTest.php index 31496075..70449058 100644 --- a/tests/FunctionalTest.php +++ b/tests/FunctionalTest.php @@ -203,10 +203,10 @@ public function testLinks(): void self::assertStringContainsString('PSR-0 specification', $crawler->html()); $crawler = $this->assertValid('/projects/doctrine-inflector/en/1.3/index.html'); - self::assertStringContainsString('Classify', $crawler->html()); + self::assertStringContainsString('Classify', $crawler->html()); $crawler = $this->assertValid('/projects/doctrine-inflector/en/2.0/index.html'); - self::assertStringContainsString('Classify', $crawler->html()); + self::assertStringContainsString('Classify', $crawler->html()); $crawler = $this->assertValid('/projects/doctrine-inflector/en/2.0/index.html'); self::assertStringContainsString('Null Object design pattern', $crawler->html()); @@ -268,7 +268,12 @@ public function testContribute(): void $crawler = $this->assertValid('/contribute/index.html'); self::assertStringContainsString('
    ', $crawler->html()); - self::assertStringContainsString('

    Contribute

    ', $crawler->html()); + self::assertStringContainsString('

    + + Contribute + + +

    ', $crawler->html()); } public function testContributeMaintainer(): void @@ -276,7 +281,12 @@ public function testContributeMaintainer(): void $crawler = $this->assertValid('/contribute/maintainer/index.html'); self::assertStringContainsString('
    ', $crawler->html()); - self::assertStringContainsString('

    Maintainer Workflow

    ', $crawler->html()); + self::assertStringContainsString('

    + + Maintainer Workflow + + +

    ', $crawler->html()); } public function testContributeWebsite(): void @@ -284,7 +294,12 @@ public function testContributeWebsite(): void $crawler = $this->assertValid('/contribute/website/index.html'); self::assertStringContainsString('
    ', $crawler->html()); - self::assertStringContainsString('

    Contribute to Website

    ', $crawler->html()); + self::assertStringContainsString('

    + + Contribute to Website + + +

    ', $crawler->html()); } private function getFullPath(string $path): string From 0e6b6cde5a1b6f16b51e482a0b5c511217f937c4 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Wed, 18 Sep 2024 23:39:28 +0200 Subject: [PATCH 17/30] Link of asset may change --- tests/Twig/MainExtensionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Twig/MainExtensionTest.php b/tests/Twig/MainExtensionTest.php index 75abf8e1..104b8ab8 100644 --- a/tests/Twig/MainExtensionTest.php +++ b/tests/Twig/MainExtensionTest.php @@ -74,6 +74,6 @@ public function testGetAssetUrl(): void 'http://lcl.doctrine-project.org', ); - self::assertSame('http://lcl.doctrine-project.org/js/main.js?de1272', $url); + self::assertStringStartsWith('http://lcl.doctrine-project.org/js/main.js', $url); } } From 750eef07017011dac503644bdd782b70f7a780b4 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Fri, 20 Sep 2024 20:26:55 +0200 Subject: [PATCH 18/30] Add phpstan types for arrays --- lib/Docs/SearchIndexer.php | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/Docs/SearchIndexer.php b/lib/Docs/SearchIndexer.php index 0e428e7c..7e07428f 100644 --- a/lib/Docs/SearchIndexer.php +++ b/lib/Docs/SearchIndexer.php @@ -22,6 +22,21 @@ /** * Influenced by Laravel.com website code search indexes that also use Algolia. * + * @phpstan-type headers = array{h1: string|null, h2: string|null, h3: string|null, h4: string|null, h5: string|null} + * @phpstan-type searchRecord = array{ + * objectID: string, + * rank: int, + * h1: string|null, + * h2: string|null, + * h3: string|null, + * h4: string|null, + * h5: string|null, + * url: string, + * content: string, + * projectName: string, + * _tags: string[], + * } + * * @final */ class SearchIndexer @@ -70,6 +85,9 @@ public function buildSearchIndexes( $this->getSearchIndex()->saveObjects($records, ['autoGenerateObjectIDIfNotExist' => true]); } + /** + * @return Generator + */ private function buildDocumentSearchRecords( DocumentNode $document, Project $project, @@ -89,10 +107,10 @@ private function buildDocumentSearchRecords( } /** - * @param array $current + * @param headers $current * @param CompoundNode $node * - * @return Generator + * @return Generator */ private function iterateNodes(CompoundNode $node, array $current, string $currentLink, Project $project, ProjectVersion $version): Generator { @@ -120,9 +138,9 @@ private function iterateNodes(CompoundNode $node, array $current, string $curren } /** - * @param string[] $current + * @param headers $current * - * @return mixed[] + * @return searchRecord */ private function getNodeSearchRecord( Node $node, From 670b05217547adeecf3a14d710d8a2f38e5e8c5b Mon Sep 17 00:00:00 2001 From: Jaapio Date: Fri, 20 Sep 2024 20:35:10 +0200 Subject: [PATCH 19/30] Improve test assert --- lib/Docs/SearchIndexer.php | 9 +++------ tests/Twig/MainExtensionTest.php | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/Docs/SearchIndexer.php b/lib/Docs/SearchIndexer.php index 7e07428f..32634c2d 100644 --- a/lib/Docs/SearchIndexer.php +++ b/lib/Docs/SearchIndexer.php @@ -36,7 +36,6 @@ * projectName: string, * _tags: string[], * } - * * @final */ class SearchIndexer @@ -85,9 +84,7 @@ public function buildSearchIndexes( $this->getSearchIndex()->saveObjects($records, ['autoGenerateObjectIDIfNotExist' => true]); } - /** - * @return Generator - */ + /** @return Generator */ private function buildDocumentSearchRecords( DocumentNode $document, Project $project, @@ -107,8 +104,8 @@ private function buildDocumentSearchRecords( } /** - * @param headers $current - * @param CompoundNode $node + * @param headers $current + * @param CompoundNode $node * * @return Generator */ diff --git a/tests/Twig/MainExtensionTest.php b/tests/Twig/MainExtensionTest.php index 104b8ab8..fb1d463b 100644 --- a/tests/Twig/MainExtensionTest.php +++ b/tests/Twig/MainExtensionTest.php @@ -74,6 +74,6 @@ public function testGetAssetUrl(): void 'http://lcl.doctrine-project.org', ); - self::assertStringStartsWith('http://lcl.doctrine-project.org/js/main.js', $url); + self::assertMatchesRegularExpression('#^http://lcl.doctrine-project.org/js/main.js\?[a-z0-9+]{6}$#', $url); } } From ca5caea2371d48329a93cdfe38b6e47b5b810f60 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Fri, 20 Sep 2024 20:36:31 +0200 Subject: [PATCH 20/30] Remove nunomaduro/mock-final-classes --- composer.json | 1 - composer.lock | 128 +------------------------------------------------- 2 files changed, 1 insertion(+), 128 deletions(-) diff --git a/composer.json b/composer.json index 59e1f82c..cf8f7467 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,6 @@ "require-dev": { "doctrine/coding-standard": "^12.0", "mikey179/vfsstream": "^1.6", - "nunomaduro/mock-final-classes": "^1.2", "phpstan/phpstan": "^1.11", "phpstan/phpstan-deprecation-rules": "^1.2", "phpstan/phpstan-phpunit": "^1.4", diff --git a/composer.lock b/composer.lock index 2749d0b4..72714ac6 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ce075fb57999b1c23ce00a7d80c59720", + "content-hash": "199405197b2d08a999915c63bf5480c5", "packages": [ { "name": "algolia/algoliasearch-client-php", @@ -5910,59 +5910,6 @@ }, "time": "2023-01-05T11:28:13+00:00" }, - { - "name": "dg/bypass-finals", - "version": "v1.5.1", - "source": { - "type": "git", - "url": "https://github.com/dg/bypass-finals.git", - "reference": "12ef25e1f8d4144e4ec80d13a28895e8942f4104" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/dg/bypass-finals/zipball/12ef25e1f8d4144e4ec80d13a28895e8942f4104", - "reference": "12ef25e1f8d4144e4ec80d13a28895e8942f4104", - "shasum": "" - }, - "require": { - "php": ">=7.1" - }, - "require-dev": { - "nette/tester": "^2.3", - "phpstan/phpstan": "^0.12" - }, - "type": "library", - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause", - "GPL-2.0", - "GPL-3.0" - ], - "authors": [ - { - "name": "David Grudl", - "homepage": "https://davidgrudl.com" - } - ], - "description": "Removes final keyword from source code on-the-fly and allows mocking of final methods and classes", - "keywords": [ - "finals", - "mocking", - "phpunit", - "testing", - "unit" - ], - "support": { - "issues": "https://github.com/dg/bypass-finals/issues", - "source": "https://github.com/dg/bypass-finals/tree/v1.5.1" - }, - "time": "2023-09-16T09:13:54+00:00" - }, { "name": "doctrine/coding-standard", "version": "12.0.0", @@ -6254,79 +6201,6 @@ }, "time": "2024-01-07T17:17:35+00:00" }, - { - "name": "nunomaduro/mock-final-classes", - "version": "v1.2.0", - "source": { - "type": "git", - "url": "https://github.com/nunomaduro/mock-final-classes.git", - "reference": "b13fc71acd9d6f1e2de8209217103cbd2035871f" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/nunomaduro/mock-final-classes/zipball/b13fc71acd9d6f1e2de8209217103cbd2035871f", - "reference": "b13fc71acd9d6f1e2de8209217103cbd2035871f", - "shasum": "" - }, - "require": { - "dg/bypass-finals": "^1.1", - "php": "^7.1 || ^8.0" - }, - "require-dev": { - "localheinz/phpstan-rules": "^0.10.0", - "phpstan/phpstan": "^0.11.8", - "phpstan/phpstan-strict-rules": "^0.11.1", - "phpunit/phpunit": "^7.0|^8.0|^9.3", - "thecodingmachine/phpstan-strict-rules": "^0.11.1" - }, - "type": "library", - "autoload": { - "files": [ - "autoload.php" - ], - "psr-4": { - "NunoMaduro\\MockFinalClasses\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nuno Maduro", - "email": "enunomaduro@gmail.com" - } - ], - "description": "Allows mocking of final methods and classes in PHP.", - "keywords": [ - "class", - "classes", - "final", - "mock", - "php", - "phpunit" - ], - "support": { - "issues": "https://github.com/nunomaduro/mock-final-classes/issues", - "source": "https://github.com/nunomaduro/mock-final-classes/tree/v1.2.0" - }, - "funding": [ - { - "url": "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=66BYDWAT92N6L", - "type": "custom" - }, - { - "url": "https://github.com/nunomaduro", - "type": "github" - }, - { - "url": "https://www.patreon.com/nunomaduro", - "type": "patreon" - } - ], - "time": "2023-05-14T23:33:16+00:00" - }, { "name": "phar-io/manifest", "version": "2.0.3", From 46391cc8ddfe63b9a7aee68496e1d3ead43834aa Mon Sep 17 00:00:00 2001 From: Jaapio Date: Fri, 20 Sep 2024 20:39:00 +0200 Subject: [PATCH 21/30] Cleanup copier code --- lib/Docs/RST/RSTCopier.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/Docs/RST/RSTCopier.php b/lib/Docs/RST/RSTCopier.php index 0b7d590f..12704ea4 100644 --- a/lib/Docs/RST/RSTCopier.php +++ b/lib/Docs/RST/RSTCopier.php @@ -97,11 +97,7 @@ private function prepareRSTTemplate(string $content, string $sidebar, string $so $rstTemplate = str_replace('{{ sidebar }}', $sidebar, self::RST_TEMPLATE); // put the content in the RST template - $content = str_replace('{{ content }}', $content, $rstTemplate); - - // append the source file name to the content so we can parse it back out - // for use in the build process - return $content; + return str_replace('{{ content }}', $content, $rstTemplate); } private function fixRSTSyntax(Project $project, string $content): string From 6ef0be66c287f804eb40e33746b71b510b0e76a0 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Fri, 20 Sep 2024 21:01:28 +0200 Subject: [PATCH 22/30] Improve menu handling As toctree does modify the structure of the docs, which results in infinitif loops when items refer to eachother, we switched to menu. --- lib/Docs/RST/RSTCopier.php | 5 +++-- lib/Guides/Compiler/SidebarTransformer.php | 12 ++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/Docs/RST/RSTCopier.php b/lib/Docs/RST/RSTCopier.php index 12704ea4..58337b4e 100644 --- a/lib/Docs/RST/RSTCopier.php +++ b/lib/Docs/RST/RSTCopier.php @@ -24,7 +24,7 @@ class RSTCopier TEMPLATE; final public const DEFAULT_SIDEBAR = <<<'SIDEBAR' - .. toctree:: + .. menu:: :depth: 3 :glob: @@ -46,7 +46,7 @@ public function copyRst(Project $project, ProjectVersion $version): void // clear existing files before copying the rst over $this->filesystem->remove($this->rstFileRepository->findFiles($outputPath)); - $sidebar = $this->getSidebarRST($language->getPath()); + $sidebar = $this->fixRSTSyntax($project, $this->getSidebarRST($language->getPath())); $files = $this->rstFileRepository->getSourceFiles($language->getPath()); @@ -107,6 +107,7 @@ private function fixRSTSyntax(Project $project, string $content): string // fix :maxdepth: to :depth: $content = str_replace(':maxdepth:', ':depth:', $content); + $content = str_replace('toctree::', 'menu::', $content); // get rid of .. include:: toc.rst $content = str_replace('.. include:: toc.rst', '', $content); diff --git a/lib/Guides/Compiler/SidebarTransformer.php b/lib/Guides/Compiler/SidebarTransformer.php index 41005a46..48661a97 100644 --- a/lib/Guides/Compiler/SidebarTransformer.php +++ b/lib/Guides/Compiler/SidebarTransformer.php @@ -7,11 +7,19 @@ use Override; use phpDocumentor\Guides\Compiler\CompilerContext; use phpDocumentor\Guides\Compiler\NodeTransformer; +use phpDocumentor\Guides\Nodes\Menu\MenuNode; use phpDocumentor\Guides\Nodes\Menu\TocNode; use phpDocumentor\Guides\Nodes\Node; use phpDocumentor\Guides\RestructuredText\Nodes\GeneralDirectiveNode; -/** @implements NodeTransformer */ +/** + * This class will move the menu and toc nodes to the sidebar. + * + * As the toc node and menus should be displayed in the sidebar, this transformer will move them to a separate + * documentPart. It will be removed from the main content of the document. + * + * @implements NodeTransformer + */ final class SidebarTransformer implements NodeTransformer { #[Override] @@ -38,7 +46,7 @@ public function supports(Node $node): bool return $node->getName() === 'toc'; } - return $node instanceof TocNode; + return $node instanceof TocNode || $node instanceof MenuNode; } #[Override] From 1315f593ab977d77242366e4890d31fd69898ddd Mon Sep 17 00:00:00 2001 From: Jaapio Date: Fri, 20 Sep 2024 21:18:41 +0200 Subject: [PATCH 23/30] Move theme configuration to compilerpass To allow full usage of the configuration move the theme configuration to a compiler pass that will set the value. --- lib/Application.php | 2 ++ lib/Docs/RST/Guides.php | 3 --- .../DependencyInjection/ThemeCompilerPass.php | 24 +++++++++++++++++++ .../GuidesRstConverter.php | 3 --- 4 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 lib/Guides/DependencyInjection/ThemeCompilerPass.php diff --git a/lib/Application.php b/lib/Application.php index f18b7242..a4031def 100644 --- a/lib/Application.php +++ b/lib/Application.php @@ -10,6 +10,7 @@ use Doctrine\Website\Commands\BuildWebsiteCommand; use Doctrine\Website\Commands\ClearBuildCacheCommand; use Doctrine\Website\Commands\SyncRepositoriesCommand; +use Doctrine\Website\Guides\DependencyInjection\ThemeCompilerPass; use phpDocumentor\Guides\DependencyInjection\GuidesExtension; use phpDocumentor\Guides\RestructuredText\DependencyInjection\ReStructuredTextExtension; use Symfony\Component\Config\FileLocator; @@ -89,6 +90,7 @@ public static function getContainer(string $env): ContainerBuilder $container->setParameter('doctrine.website.send_grid.api_key', getenv('doctrine_website_send_grid_api_key') ?: ''); $container->setParameter('vendor_dir', realpath(__DIR__ . '/../vendor')); + $container->addCompilerPass(new ThemeCompilerPass()); foreach ([new GuidesExtension(), new ReStructuredTextExtension()] as $extension) { $container->registerExtension($extension); $container->loadFromExtension($extension->getAlias()); diff --git a/lib/Docs/RST/Guides.php b/lib/Docs/RST/Guides.php index 3f607127..a5a0566f 100644 --- a/lib/Docs/RST/Guides.php +++ b/lib/Docs/RST/Guides.php @@ -12,7 +12,6 @@ use phpDocumentor\Guides\Handlers\RenderCommand; use phpDocumentor\Guides\Nodes\DocumentNode; use phpDocumentor\Guides\Nodes\ProjectNode; -use phpDocumentor\Guides\Twig\Theme\ThemeManager; final class Guides implements DocumentsBuilder { @@ -22,7 +21,6 @@ final class Guides implements DocumentsBuilder public function __construct( private CommandBus $commandBus, private GuidesParser $guidesParser, - private ThemeManager $themeManager, ) { } @@ -36,7 +34,6 @@ public function build(string $directory, string $targetDirectory = 'output'): vo $this->documents = $this->guidesParser->parse($directory, $projectNode); $destinationFileSystem = new Filesystem(new Local($targetDirectory)); - $this->themeManager->useTheme('doctrine'); $this->commandBus->handle( new RenderCommand( diff --git a/lib/Guides/DependencyInjection/ThemeCompilerPass.php b/lib/Guides/DependencyInjection/ThemeCompilerPass.php new file mode 100644 index 00000000..ff69c85f --- /dev/null +++ b/lib/Guides/DependencyInjection/ThemeCompilerPass.php @@ -0,0 +1,24 @@ +getExtensionConfig('guides'); + + foreach ($guidesConfig as $config) { + $theme ??= $config['theme'] ?? null; + } + + $themeManager = $container->getDefinition(ThemeManager::class); + $themeManager->addMethodCall('useTheme', [$theme ?? 'default']); + } +} diff --git a/lib/Guides/StaticWebsiteGenerator/GuidesRstConverter.php b/lib/Guides/StaticWebsiteGenerator/GuidesRstConverter.php index 41f9f2a5..0090fbda 100644 --- a/lib/Guides/StaticWebsiteGenerator/GuidesRstConverter.php +++ b/lib/Guides/StaticWebsiteGenerator/GuidesRstConverter.php @@ -14,7 +14,6 @@ use phpDocumentor\Guides\Nodes\ProjectNode; use phpDocumentor\Guides\Parser; use phpDocumentor\Guides\RenderContext; -use phpDocumentor\Guides\Twig\Theme\ThemeManager; final readonly class GuidesRstConverter implements SourceFileConverter { @@ -22,7 +21,6 @@ public function __construct( private Parser $parser, private NodeRenderer $nodeRenderer, - private ThemeManager $themeManager, ) { } @@ -36,7 +34,6 @@ public function getExtensions(): array #[Override] public function convertSourceFile(SourceFile $sourceFile): string { - $this->themeManager->useTheme('doctrine'); $document = $this->parser->parse($sourceFile->getContents(), 'rst'); $renderContext = RenderContext::forDocument( From ea15e4dbb73aa4b96de15fe5695a3a7106b5d71b Mon Sep 17 00:00:00 2001 From: Jaapio Date: Tue, 24 Sep 2024 00:36:53 +0200 Subject: [PATCH 24/30] Do only move document level menu nodes --- lib/Guides/Compiler/SidebarTransformer.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/Guides/Compiler/SidebarTransformer.php b/lib/Guides/Compiler/SidebarTransformer.php index 48661a97..c54474b7 100644 --- a/lib/Guides/Compiler/SidebarTransformer.php +++ b/lib/Guides/Compiler/SidebarTransformer.php @@ -7,7 +7,8 @@ use Override; use phpDocumentor\Guides\Compiler\CompilerContext; use phpDocumentor\Guides\Compiler\NodeTransformer; -use phpDocumentor\Guides\Nodes\Menu\MenuNode; +use phpDocumentor\Guides\Nodes\DocumentNode; +use phpDocumentor\Guides\Nodes\Menu\NavMenuNode; use phpDocumentor\Guides\Nodes\Menu\TocNode; use phpDocumentor\Guides\Nodes\Node; use phpDocumentor\Guides\RestructuredText\Nodes\GeneralDirectiveNode; @@ -31,6 +32,10 @@ public function enterNode(Node $node, CompilerContext $compilerContext): Node #[Override] public function leaveNode(Node $node, CompilerContext $compilerContext): Node|null { + if ($compilerContext->getShadowTree()->getParent()?->getNode() instanceof DocumentNode === false) { + return $node; + } + $nodes = $compilerContext->getDocumentNode()->getDocumentPartNodes()['sidebar'] ?? []; $nodes[] = $node; @@ -46,12 +51,12 @@ public function supports(Node $node): bool return $node->getName() === 'toc'; } - return $node instanceof TocNode || $node instanceof MenuNode; + return $node instanceof NavMenuNode; } #[Override] public function getPriority(): int { - return 3000; + return 1; } } From e8dfa96f4f16bed5546ca9cfb9597ee507edd5f8 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Tue, 24 Sep 2024 00:37:24 +0200 Subject: [PATCH 25/30] Small tweaks in templates --- templates/guides/body/admonition.html.twig | 2 +- templates/guides/body/menu/menu.html.twig | 3 +++ .../guides/body/version-change.html.twig | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 templates/guides/body/menu/menu.html.twig create mode 100644 templates/guides/body/version-change.html.twig diff --git a/templates/guides/body/admonition.html.twig b/templates/guides/body/admonition.html.twig index 94cd6f78..8a9c2e21 100644 --- a/templates/guides/body/admonition.html.twig +++ b/templates/guides/body/admonition.html.twig @@ -7,7 +7,7 @@ {% endif %} {% if name == 'warning' or name == 'caution' %} {% set admonitionClass='warning' %} - {% set textClass='text-primary' %} + {% set textClass='text-warning' %} {% set icon='fa-exclamation-circle' %} {% endif %} {% if name == 'tip' or name == 'hint' %} diff --git a/templates/guides/body/menu/menu.html.twig b/templates/guides/body/menu/menu.html.twig new file mode 100644 index 00000000..20dd75a2 --- /dev/null +++ b/templates/guides/body/menu/menu.html.twig @@ -0,0 +1,3 @@ +
    + {% include "body/menu/menu-level.html.twig" %} +
    diff --git a/templates/guides/body/version-change.html.twig b/templates/guides/body/version-change.html.twig new file mode 100644 index 00000000..be0c5bc4 --- /dev/null +++ b/templates/guides/body/version-change.html.twig @@ -0,0 +1,19 @@ +{% if node.type == 'versionadded' %} +
    +

    {{ node.versionLabel }}

    + {% if (node.value) %} +
    + {{ renderNode(node.value) }} +
    + {% endif %} +
    +{% elseif node.type == 'versionchanged' %} +
    +

    {{ node.versionLabel }}

    + {% if (node.value) %} +
    + {{ renderNode(node.value) }} +
    + {% endif %} +
    +{% endif %} From 45fc3fa255129ed791cbdeb3bf2ee6c26e694a14 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Tue, 24 Sep 2024 22:13:43 +0200 Subject: [PATCH 26/30] Fix section author markup Apply the correct template for section authors. Add an extra fix in the migration from old doc styles to correct the display of author names. --- lib/Docs/RST/RSTCopier.php | 8 ++++++++ templates/guides/body/author.html.twig | 3 +++ 2 files changed, 11 insertions(+) create mode 100644 templates/guides/body/author.html.twig diff --git a/lib/Docs/RST/RSTCopier.php b/lib/Docs/RST/RSTCopier.php index 58337b4e..d506f85c 100644 --- a/lib/Docs/RST/RSTCopier.php +++ b/lib/Docs/RST/RSTCopier.php @@ -112,6 +112,14 @@ private function fixRSTSyntax(Project $project, string $content): string // get rid of .. include:: toc.rst $content = str_replace('.. include:: toc.rst', '', $content); + $content = preg_replace( + '/.. sectionauthor:: ([^\(]+) \(([^\)]+)\)/', + '.. sectionauthor:: $1 <$2>', + $content, + ); + + assert(is_string($content)); + // replace \n::\n with \n.. code-block::\n // this corrects code blocks that don't render properly. // we should update the docs code but this makes old docs code render properly. diff --git a/templates/guides/body/author.html.twig b/templates/guides/body/author.html.twig new file mode 100644 index 00000000..835f97fc --- /dev/null +++ b/templates/guides/body/author.html.twig @@ -0,0 +1,3 @@ + From f56c22f3fc934be3158e8b1d2d242ffff7eeb79f Mon Sep 17 00:00:00 2001 From: Jaapio Date: Tue, 24 Sep 2024 23:46:48 +0200 Subject: [PATCH 27/30] Full wildcard match on default menu We do want to include every document in the menu when we do a fallback to the default menu. `/*` does match all files are root level, while we wanted to match everything `*`. --- lib/Docs/RST/RSTCopier.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Docs/RST/RSTCopier.php b/lib/Docs/RST/RSTCopier.php index 58337b4e..1ce1f15c 100644 --- a/lib/Docs/RST/RSTCopier.php +++ b/lib/Docs/RST/RSTCopier.php @@ -28,7 +28,7 @@ class RSTCopier :depth: 3 :glob: - /* + * SIDEBAR; public function __construct( From 7b5c856330ad4c6ff28871e82660ad8169624d44 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Wed, 25 Sep 2024 19:49:55 +0200 Subject: [PATCH 28/30] Upgrade phpdoc/guides The upgrade of guides contains the fix required to make the menu render the section titles of each page. --- composer.json | 2 +- composer.lock | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index cf8f7467..32b31d33 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "knplabs/github-api": "^3.9", "php-http/guzzle7-adapter": "^1.0", "phpdocumentor/guides": "^1.3", - "phpdocumentor/guides-restructured-text": "^1.3", + "phpdocumentor/guides-restructured-text": "^1.4", "scrivo/highlight.php": "^9.18", "symfony/cache": "^6.4", "symfony/config": "^6.4", diff --git a/composer.lock b/composer.lock index 72714ac6..374de698 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "199405197b2d08a999915c63bf5480c5", + "content-hash": "b2b55e7b32fa2804541e69eb01a2a3b8", "packages": [ { "name": "algolia/algoliasearch-client-php", @@ -2621,16 +2621,16 @@ }, { "name": "phpdocumentor/guides-restructured-text", - "version": "1.3.10", + "version": "1.4.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/guides-restructured-text.git", - "reference": "7719c777cdd49ce5dc7db61a6cd96cf04e3b1e63" + "reference": "f21a69f2d39ae04eea8550a90863a74c5ef97d4b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/guides-restructured-text/zipball/7719c777cdd49ce5dc7db61a6cd96cf04e3b1e63", - "reference": "7719c777cdd49ce5dc7db61a6cd96cf04e3b1e63", + "url": "https://api.github.com/repos/phpDocumentor/guides-restructured-text/zipball/f21a69f2d39ae04eea8550a90863a74c5ef97d4b", + "reference": "f21a69f2d39ae04eea8550a90863a74c5ef97d4b", "shasum": "" }, "require": { @@ -2653,9 +2653,9 @@ "description": "Adds reStructuredText Markup support to the phpDocumentor's Guides library.", "homepage": "https://www.phpdoc.org", "support": { - "source": "https://github.com/phpDocumentor/guides-restructured-text/tree/1.3.10" + "source": "https://github.com/phpDocumentor/guides-restructured-text/tree/1.4.0" }, - "time": "2024-09-06T17:05:36+00:00" + "time": "2024-09-25T17:25:09+00:00" }, { "name": "psr/cache", From 679159992d9709e138887ad64598026560366dbb Mon Sep 17 00:00:00 2001 From: Jaapio Date: Tue, 24 Sep 2024 23:07:17 +0200 Subject: [PATCH 29/30] Replace logger with monolog The logger introduced before was very usefull in the setup process but by now, it should be replaced by something more mature to ensure the logs to not end up in the final output. --- composer.json | 1 + composer.lock | 103 +++++++++++++++++++++++++++++++++++++++- config/services.xml | 11 ++++- lib/Docs/RST/Logger.php | 22 --------- 4 files changed, 113 insertions(+), 24 deletions(-) delete mode 100644 lib/Docs/RST/Logger.php diff --git a/composer.json b/composer.json index 32b31d33..1e1e4c0d 100644 --- a/composer.json +++ b/composer.json @@ -19,6 +19,7 @@ "doctrine/static-website-generator": "^2.1", "erusev/parsedown": "^1.7", "knplabs/github-api": "^3.9", + "monolog/monolog": "^3.7", "php-http/guzzle7-adapter": "^1.0", "phpdocumentor/guides": "^1.3", "phpdocumentor/guides-restructured-text": "^1.4", diff --git a/composer.lock b/composer.lock index 374de698..2be08d25 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b2b55e7b32fa2804541e69eb01a2a3b8", + "content-hash": "ee0a29b539125a8fd4de75385911896b", "packages": [ { "name": "algolia/algoliasearch-client-php", @@ -1964,6 +1964,107 @@ ], "time": "2024-03-23T07:42:40+00:00" }, + { + "name": "monolog/monolog", + "version": "3.7.0", + "source": { + "type": "git", + "url": "https://github.com/Seldaek/monolog.git", + "reference": "f4393b648b78a5408747de94fca38beb5f7e9ef8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Seldaek/monolog/zipball/f4393b648b78a5408747de94fca38beb5f7e9ef8", + "reference": "f4393b648b78a5408747de94fca38beb5f7e9ef8", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "psr/log": "^2.0 || ^3.0" + }, + "provide": { + "psr/log-implementation": "3.0.0" + }, + "require-dev": { + "aws/aws-sdk-php": "^3.0", + "doctrine/couchdb": "~1.0@dev", + "elasticsearch/elasticsearch": "^7 || ^8", + "ext-json": "*", + "graylog2/gelf-php": "^1.4.2 || ^2.0", + "guzzlehttp/guzzle": "^7.4.5", + "guzzlehttp/psr7": "^2.2", + "mongodb/mongodb": "^1.8", + "php-amqplib/php-amqplib": "~2.4 || ^3", + "phpstan/phpstan": "^1.9", + "phpstan/phpstan-deprecation-rules": "^1.0", + "phpstan/phpstan-strict-rules": "^1.4", + "phpunit/phpunit": "^10.5.17", + "predis/predis": "^1.1 || ^2", + "ruflin/elastica": "^7", + "symfony/mailer": "^5.4 || ^6", + "symfony/mime": "^5.4 || ^6" + }, + "suggest": { + "aws/aws-sdk-php": "Allow sending log messages to AWS services like DynamoDB", + "doctrine/couchdb": "Allow sending log messages to a CouchDB server", + "elasticsearch/elasticsearch": "Allow sending log messages to an Elasticsearch server via official client", + "ext-amqp": "Allow sending log messages to an AMQP server (1.0+ required)", + "ext-curl": "Required to send log messages using the IFTTTHandler, the LogglyHandler, the SendGridHandler, the SlackWebhookHandler or the TelegramBotHandler", + "ext-mbstring": "Allow to work properly with unicode symbols", + "ext-mongodb": "Allow sending log messages to a MongoDB server (via driver)", + "ext-openssl": "Required to send log messages using SSL", + "ext-sockets": "Allow sending log messages to a Syslog server (via UDP driver)", + "graylog2/gelf-php": "Allow sending log messages to a GrayLog2 server", + "mongodb/mongodb": "Allow sending log messages to a MongoDB server (via library)", + "php-amqplib/php-amqplib": "Allow sending log messages to an AMQP server using php-amqplib", + "rollbar/rollbar": "Allow sending log messages to Rollbar", + "ruflin/elastica": "Allow sending log messages to an Elastic Search server" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Monolog\\": "src/Monolog" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "https://seld.be" + } + ], + "description": "Sends your logs to files, sockets, inboxes, databases and various web services", + "homepage": "https://github.com/Seldaek/monolog", + "keywords": [ + "log", + "logging", + "psr-3" + ], + "support": { + "issues": "https://github.com/Seldaek/monolog/issues", + "source": "https://github.com/Seldaek/monolog/tree/3.7.0" + }, + "funding": [ + { + "url": "https://github.com/Seldaek", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/monolog/monolog", + "type": "tidelift" + } + ], + "time": "2024-06-28T09:40:51+00:00" + }, { "name": "php-http/cache-plugin", "version": "1.8.1", diff --git a/config/services.xml b/config/services.xml index 09449cf0..e45de2b3 100644 --- a/config/services.xml +++ b/config/services.xml @@ -155,7 +155,6 @@ - @@ -174,5 +173,15 @@ phpDocumentor\Guides\Nodes\DocumentNode + + + docs + + + + + + STDERR + diff --git a/lib/Docs/RST/Logger.php b/lib/Docs/RST/Logger.php deleted file mode 100644 index fe1aed26..00000000 --- a/lib/Docs/RST/Logger.php +++ /dev/null @@ -1,22 +0,0 @@ - Date: Wed, 25 Sep 2024 22:59:57 +0200 Subject: [PATCH 30/30] Improve menu generation So the origin of the menu's not working is in the way the menu's are defined. The doctrine parser did use * as a deep search wildcard which is not according to the behavior sphinx does it. As the toctree is a directive defined by sphinx we try to follow that one closely. The correct way of writing a toctree is ``` .. toctree:: :glob: ** ``` This will include all documents and sections in a project. starting at the level of the current page. --- composer.json | 2 +- composer.lock | 14 ++--- config/services.xml | 4 ++ lib/Docs/RST/RSTCopier.php | 2 +- .../Compiler/GlobMenuFixerTransformer.php | 51 +++++++++++++++++++ 5 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 lib/Guides/Compiler/GlobMenuFixerTransformer.php diff --git a/composer.json b/composer.json index 1e1e4c0d..f6dbc874 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "knplabs/github-api": "^3.9", "monolog/monolog": "^3.7", "php-http/guzzle7-adapter": "^1.0", - "phpdocumentor/guides": "^1.3", + "phpdocumentor/guides": "^1.4", "phpdocumentor/guides-restructured-text": "^1.4", "scrivo/highlight.php": "^9.18", "symfony/cache": "^6.4", diff --git a/composer.lock b/composer.lock index 2be08d25..96113880 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ee0a29b539125a8fd4de75385911896b", + "content-hash": "c44272296c10f265ffc2149dc0e5a599", "packages": [ { "name": "algolia/algoliasearch-client-php", @@ -2670,16 +2670,16 @@ }, { "name": "phpdocumentor/guides", - "version": "1.3.10", + "version": "1.4.1", "source": { "type": "git", "url": "https://github.com/phpDocumentor/guides-core.git", - "reference": "a431f1d1f398687bf93e80ef525b83e21f75b15b" + "reference": "1f21f606ce030fd8989eb783f726cf32c44d61ef" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/guides-core/zipball/a431f1d1f398687bf93e80ef525b83e21f75b15b", - "reference": "a431f1d1f398687bf93e80ef525b83e21f75b15b", + "url": "https://api.github.com/repos/phpDocumentor/guides-core/zipball/1f21f606ce030fd8989eb783f726cf32c44d61ef", + "reference": "1f21f606ce030fd8989eb783f726cf32c44d61ef", "shasum": "" }, "require": { @@ -2716,9 +2716,9 @@ "homepage": "https://www.phpdoc.org", "support": { "issues": "https://github.com/phpDocumentor/guides-core/issues", - "source": "https://github.com/phpDocumentor/guides-core/tree/1.3.10" + "source": "https://github.com/phpDocumentor/guides-core/tree/1.4.1" }, - "time": "2024-09-09T07:04:46+00:00" + "time": "2024-09-25T20:40:25+00:00" }, { "name": "phpdocumentor/guides-restructured-text", diff --git a/config/services.xml b/config/services.xml index e45de2b3..071da136 100644 --- a/config/services.xml +++ b/config/services.xml @@ -160,6 +160,10 @@ + + + + diff --git a/lib/Docs/RST/RSTCopier.php b/lib/Docs/RST/RSTCopier.php index d525d8ff..3a50e660 100644 --- a/lib/Docs/RST/RSTCopier.php +++ b/lib/Docs/RST/RSTCopier.php @@ -28,7 +28,7 @@ class RSTCopier :depth: 3 :glob: - * + ** SIDEBAR; public function __construct( diff --git a/lib/Guides/Compiler/GlobMenuFixerTransformer.php b/lib/Guides/Compiler/GlobMenuFixerTransformer.php new file mode 100644 index 00000000..28e67f08 --- /dev/null +++ b/lib/Guides/Compiler/GlobMenuFixerTransformer.php @@ -0,0 +1,51 @@ + + */ +final class GlobMenuFixerTransformer implements NodeTransformer +{ + public function enterNode(Node $node, CompilerContext $compilerContext): Node + { + return $node; + } + + public function leaveNode(Node $node, CompilerContext $compilerContext): Node|null + { + if ($node->getUrl() === '*') { + return new GlobMenuEntryNode( + '**', + $node->getLevel(), + ); + } + + return $node; + } + + public function supports(Node $node): bool + { + return $node instanceof GlobMenuEntryNode; + } + + public function getPriority(): int + { + // Before GlobMenuEntryNodeTransformer + return 4001; + } +}