forked from GNUsocial/gnu-social
[TOOLS][DOCUMENTATION] Improvements to entity generation script
This commit is contained in:
parent
cbbdae6831
commit
06b5fe2cdf
2
.gitignore
vendored
2
.gitignore
vendored
@ -23,4 +23,4 @@
|
||||
/file
|
||||
|
||||
DOCUMENTATION/database/*
|
||||
!DOCUMENTATION/database/diagram.pdf
|
||||
!DOCUMENTATION/database/database.pdf
|
BIN
DOCUMENTATION/database/database.pdf
Normal file
BIN
DOCUMENTATION/database/database.pdf
Normal file
Binary file not shown.
Binary file not shown.
@ -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";
|
||||
|
@ -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);
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user