Skip to content

Commit

Permalink
Automate Function-by-Name and Function-by-Category Docs (#3818)
Browse files Browse the repository at this point in the history
* Automate Function-by-Name and Function-by-Category Docs

Examining whether it is possible to analyze the 2 Php scripts in the bin directory even though they lack a .php extension, I found that the docs generated by `generate-document` had not been updated in over a year even though support for a number of functions (e.g. ARRAYTOTEXT) had long ago been implemented. The files generated by the other script `generate-locales` are automatically generated as part of the unit test suite, and I can't see any reason not to do the same for `generate-document`.

It isn't totally clear that the 2 scripts in bin are needed any more now that each has an equivalent in the unit test suite. For now, I'm keeping them, and allowing them to be analyzed by phpcs, php-cs-fixer, and phpstan.

* Reflection Not Required

Remove it from bin scripts and DocumentGeneratorTest.

* Better Html/Css Display for Function Lists

* Redesign Features Cross Reference Doc

It was inaccurate, and pretty much impossible to read in entirety. This version should be easier to read, and to correct. That's important, because there are almost certainly new inaccuracies in this version.

* Add Html to Features Cross-Reference Readers
  • Loading branch information
oleibman authored Dec 11, 2023
1 parent 27d3f09 commit 0cd725d
Show file tree
Hide file tree
Showing 10 changed files with 1,317 additions and 1,062 deletions.
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
$finder = PhpCsFixer\Finder::create()
->exclude('vendor')
->notPath('src/PhpSpreadsheet/Writer/ZipStream3.php')
->name('/(\.php|^generate-document|^generate-locales)$/')
->in(__DIR__);

$config = new PhpCsFixer\Config();
Expand Down
2 changes: 2 additions & 0 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<file>src</file>
<file>tests</file>
<file>infra</file>
<file>bin/generate-document</file>
<file>bin/generate-locales</file>

<exclude-pattern>samples/Header.php</exclude-pattern>
<exclude-pattern>*/tests/Core/*/*Test\.(inc|css|js)$</exclude-pattern>
Expand Down
26 changes: 10 additions & 16 deletions bin/generate-document
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,14 @@ use PhpOffice\PhpSpreadsheetInfra\DocumentGenerator;

require_once 'vendor/autoload.php';

try {
$phpSpreadsheetFunctionsProperty = (new ReflectionClass(Calculation::class))
->getProperty('phpSpreadsheetFunctions');
$phpSpreadsheetFunctionsProperty->setAccessible(true);
$phpSpreadsheetFunctions = $phpSpreadsheetFunctionsProperty->getValue();
ksort($phpSpreadsheetFunctions);
$phpSpreadsheetFunctions = Calculation::getFunctions();
ksort($phpSpreadsheetFunctions);

file_put_contents(__DIR__ . '/../docs/references/function-list-by-category.md',
DocumentGenerator::generateFunctionListByCategory($phpSpreadsheetFunctions)
);
file_put_contents(__DIR__ . '/../docs/references/function-list-by-name.md',
DocumentGenerator::generateFunctionListByName($phpSpreadsheetFunctions)
);
} catch (ReflectionException $e) {
fwrite(STDERR, (string) $e);
exit(1);
}
file_put_contents(
__DIR__ . '/../docs/references/function-list-by-category.md',
DocumentGenerator::generateFunctionListByCategory($phpSpreadsheetFunctions)
);
file_put_contents(
__DIR__ . '/../docs/references/function-list-by-name.md',
DocumentGenerator::generateFunctionListByName($phpSpreadsheetFunctions)
);
24 changes: 8 additions & 16 deletions bin/generate-locales
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,12 @@ use PhpOffice\PhpSpreadsheetInfra\LocaleGenerator;

require_once 'vendor/autoload.php';

try {
$phpSpreadsheetFunctionsProperty = (new ReflectionClass(Calculation::class))
->getProperty('phpSpreadsheetFunctions');
$phpSpreadsheetFunctionsProperty->setAccessible(true);
$phpSpreadsheetFunctions = $phpSpreadsheetFunctionsProperty->getValue();
$phpSpreadsheetFunctions = Calculation::getFunctions();

$localeGenerator = new LocaleGenerator(
realpath(__DIR__ . '/../src/PhpSpreadsheet/Calculation/locale/'),
'Translations.xlsx',
$phpSpreadsheetFunctions,
true
);
$localeGenerator->generateLocales();
} catch (\Exception $e) {
fwrite(STDERR, (string) $e);
exit(1);
}
$localeGenerator = new LocaleGenerator(
__DIR__ . '/../src/PhpSpreadsheet/Calculation/locale/',
'Translations.xlsx',
$phpSpreadsheetFunctions,
true
);
$localeGenerator->generateLocales();
11 changes: 11 additions & 0 deletions docs/extra/extra.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,14 @@ table.features-cross-reference {
.rst-content table.features-cross-reference.docutils td {
background-color: white;
}

/* https://github.com/mkdocs/mkdocs/discussions/3035#discussioncomment-7237037 */
.wy-table-responsive table td, .wy-table-responsive table th {
white-space: normal !important;
}
.wy-table-responsive {
overflow : visible !important;
}

/* https://github.com/readthedocs/sphinx_rtd_theme/issues/295#issuecomment-455226058 */
.wy-nav-content {max-width: none;}
Loading

0 comments on commit 0cd725d

Please sign in to comment.