[TOOLS][DOCUMENTATION] Improvements to entity generation script

This commit is contained in:
Hugo Sales 2020-04-20 14:51:53 +00:00 committed by Hugo Sales
parent cbbdae6831
commit 06b5fe2cdf
Signed by untrusted user: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
5 changed files with 26 additions and 26 deletions

2
.gitignore vendored
View File

@ -23,4 +23,4 @@
/file
DOCUMENTATION/database/*
!DOCUMENTATION/database/diagram.pdf
!DOCUMENTATION/database/database.pdf

Binary file not shown.

Binary file not shown.

View File

@ -11,30 +11,13 @@ use App\Util\HTML as H;
use Functional as F;
$template = '
\documentclass{article}
\paperheight=120cm
\paperwidth=100cm
\usepackage[pdf]{graphviz}
\title{GNU social database diagram}
\author{Hugo Sales}
\date{\today}
\begin{document}
\maketitle
\neatograph{database}{
node [shape=plaintext]
graph database {
%tables%
%edges%
}
\end{document}
';
$files = glob(INSTALL_DIR . '/src/Entity/*.php');
@ -76,11 +59,9 @@ foreach ($files as $file) {
F\map($fields, $cell)),
];
$tables[] = Common::indent("{$table} [label=<\n" . Common::indent(H::html($html)) . "\n>]");
$tables[] = Common::indent("{$table} [shape=none, label=<\n" . Common::indent(H::html($html)) . "\n>]");
}
$outfile = INSTALL_DIR . '/DOCUMENTATION/database/diagram.tex';
$replace = [
'/%tables%/' => Common::indent(implode("\n", $tables)),
'/%edges%/' => Common::indent(implode("\n", $edges)),
@ -92,11 +73,11 @@ foreach ($replace as $from => $to) {
$out = preg_replace($from, $to, $out);
}
file_put_contents($outfile, $out);
$path = dirname(__DIR__) . '/DOCUMENTATION/database';
system("cd {$path} && pdflatex diagram.tex > /dev/null");
$outfile = $path . '/database.dot';
file_put_contents($outfile, $out);
system("neato -Goverlap=false -Gsplines=true -Tpdf {$path}/database.dot -o {$path}/database.pdf");
echo "Generated database diagram. See {$path}/database.pdf\n";

View File

@ -131,4 +131,23 @@ abstract class Common
{
return implode('', F\map(preg_split('/[\b_]/', $str), self::arity('ucfirst', 1)));
}
/**
* Indent $in, a string or array, $level levels
*
* @param array|string $in
*/
public static function indent($in, int $level = 1, int $count = 2): string
{
if (is_string($in)) {
return self::indent(explode("\n", $in), $level, $count);
} elseif (is_array($in)) {
$indent = str_repeat(' ', $count * $level);
return implode("\n", F\map(F\select($in,
self::arity(function ($s) { return $s != ''; }, 1)),
function ($val) use ($indent) {
return F\concat($indent . $val);
}));
}
}
}