function gendoc2($src, $readmelst, $yaml, $prefix = null) { if (!is_array($readmelst)) { $readmelst = [$readmelst]; } if ($prefix === null) { $prefix = SRCDIR; } $snippets = analyze_tree($src); foreach ($readmelst as $readme) { if ($readme[0] != "/") { $readme = SRCDIR . $readme; } if (!file_exists($readme)) { die("{$readme}: file not found\n"); } $otxt = file_get_contents($readme); $ntxt = analyze_doc(explode("\n", $otxt)); $ntxt = expand_tags2($ntxt, $snippets, $yaml); $ntxt = implode("\n", $ntxt); if ($otxt != $ntxt) { file_put_contents($readme, $ntxt); echo "Updated " . basename($readme) . "\n"; } } }
function gendoc($readme, $yaml) { global $apitable; if (!file_exists($readme)) { die("{$readme}: file not found\n"); } $otxt = file_get_contents($readme); $txt = parse_readme(explode("\n", $otxt)); $db = analyze_tree(dirname($readme)); $out = expand_tags($txt, $db, $yaml); $ntxt = implode("\n", $out); /** Fix header entries */ foreach (['/(\\* Summary:\\s)\\s*.*\\n/' => "description", '/(\\* Dependency Plugins:\\s)\\s*.*\\n/' => "depend", '/(\\* Optional Plugins:\\s)\\s*.*\\n/' => "softdepend", '/(\\* PocketMine-MP version:\\s)\\s*.*\\n/' => "api", '/(\\* WebSite:\\s)\\s*.*\\n/' => "website"] as $re => $attr) { if (!isset($yaml[$attr])) { continue; } if (preg_match($re, $ntxt, $mv)) { if ($attr == "api") { // API is a special case... $items = []; $api = is_array($yaml[$attr]) ? $yaml[$attr] : [$yaml[$attr]]; foreach ($api as $j) { if (isset($apitable[$j])) { $items[] = $apitable[$j]; } else { $items[] = $j; } } $ntxt = preg_replace($re, $mv[1] . implode(", ", $items) . "\n", $ntxt); continue; } $item = $mv[1]; if (is_array($yaml[$attr])) { $item .= implode(", ", $yaml[$attr]); } else { $item .= $yaml[$attr]; } $item .= "\n"; $ntxt = preg_replace($re, $item, $ntxt); } } if (isset($yaml["website"])) { $re = '/\\[github\\]\\([^\\)]+\\)/'; if (preg_match($re, $ntxt, $mv)) { $ntxt = preg_replace($re, '[github](' . $yaml["website"] . ')', $ntxt); } } if ($otxt != $ntxt) { file_put_contents($readme, $ntxt); echo "Updated " . basename($readme) . "\n"; } }