Move rendering into private templates
Add an explicit template renderer with HTML views and partials for the app, bootstrap, package, and catalog pages. Move shared reporting setup into config/reporting.php and relocate stylesheet assets under css/.
This commit is contained in:
+41
-77
@@ -23,10 +23,7 @@
|
||||
* - Eén next-id per gegenereerde HTML-pagina.
|
||||
*/
|
||||
|
||||
ini_set('display_errors', '1');
|
||||
ini_set('display_startup_errors', '1');
|
||||
ini_set('log_errors', '1');
|
||||
error_reporting(E_ALL);
|
||||
require_once __DIR__ . '/config/reporting.php';
|
||||
|
||||
require_once __DIR__ . '/private/nexttoken.php';
|
||||
|
||||
@@ -40,6 +37,7 @@ require_once __DIR__ . '/private/b64parts.php';
|
||||
require_once __DIR__ . '/private/base64config.php';
|
||||
require_once __DIR__ . '/private/lib/catalog-http.php';
|
||||
require_once __DIR__ . '/private/lib/racket-data.php';
|
||||
require_once __DIR__ . '/private/Template.php';
|
||||
|
||||
define('DATA_DIR', __DIR__ . '/data');
|
||||
define('CATALOG_PACKAGE_BASE', 'https://pkgs.racket-lang.org/pkg/');
|
||||
@@ -123,11 +121,10 @@ function text_response($text, $status = 200)
|
||||
function fail_html($message, $status = 500)
|
||||
{
|
||||
html_response(
|
||||
'<!doctype html><html><head><meta charset="utf-8">' .
|
||||
'<title>Package error</title></head><body>' .
|
||||
'<h1>Package error</h1>' .
|
||||
'<pre>' . h($message) . '</pre>' .
|
||||
'</body></html>',
|
||||
RacketSandboxTemplate::renderFile('protocol-error.html', array(
|
||||
'title' => 'Package error',
|
||||
'message' => $message,
|
||||
)),
|
||||
$status
|
||||
);
|
||||
}
|
||||
@@ -362,79 +359,46 @@ function serve_package_page()
|
||||
'part' => $n,
|
||||
));
|
||||
|
||||
$rows .=
|
||||
'<tr>' .
|
||||
'<td>' . h($n) . '</td>' .
|
||||
'<td>' . h((string)$part['base64_bytes']) . '</td>' .
|
||||
'<td><a href="' . h($url) . '">' . h($url) . '</a></td>' .
|
||||
'</tr>' . "\n";
|
||||
$rows .= RacketSandboxTemplate::renderFile('partials/package-part-row.html', array(
|
||||
'number' => $n,
|
||||
'base64_bytes' => (string)$part['base64_bytes'],
|
||||
'url' => $url,
|
||||
)) . "\n";
|
||||
}
|
||||
|
||||
html_response('<!doctype html>
|
||||
<html lang="nl">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Package ' . h($package) . '</title>
|
||||
<link rel="stylesheet" href="/styles.css">
|
||||
</head>
|
||||
<body class="simple-doc">
|
||||
$sourceRows = '';
|
||||
$sourceValues = array(
|
||||
'catalog source' => $info['source'],
|
||||
'repo url' => $info['repo_url'],
|
||||
'fetch status' => $zipInfo['status'] ?? '',
|
||||
'default branch' => $zipInfo['default_branch'] ?? '',
|
||||
'head sha' => $zipInfo['head_sha'] ?? '',
|
||||
'zip file' => $zipInfo['zip_file'] ?? '',
|
||||
'zip bytes' => (string)($zipInfo['zip_bytes'] ?? ''),
|
||||
'zip sha256' => $zipInfo['zip_sha256'] ?? '',
|
||||
'parts status' => $manifest['parts_status'] ?? '',
|
||||
'max base64 part size' => '<code>' . h((string)PACKAGE_ZIP_MAX_BASE64_KB) . '</code> KiB (<code>' . h((string)PACKAGE_ZIP_MAX_BASE64_BYTES) . '</code> bytes)',
|
||||
'binary chunk size' => '<code>' . h((string)($manifest['binary_chunk_bytes'] ?? '')) . '</code> bytes',
|
||||
'part count' => (string)$manifest['part_count'],
|
||||
'next id' => $NEXT_ID,
|
||||
);
|
||||
|
||||
<h1>Package ' . h($package) . '</h1>
|
||||
foreach ($sourceValues as $label => $value) {
|
||||
$valueHtml = strpos((string)$value, '<code>') !== false
|
||||
? (string)$value
|
||||
: '<code>' . h((string)$value) . '</code>';
|
||||
|
||||
<p>
|
||||
Deze pagina is HTML. Alle part-links hieronder geven <code>text/plain</code>
|
||||
met base64-inhoud terug. Dezelfde <code>next</code> wordt gebruikt voor alle
|
||||
part-links op deze pagina.
|
||||
</p>
|
||||
$sourceRows .= RacketSandboxTemplate::renderFile('partials/package-source-row.html', array(
|
||||
'label' => $label,
|
||||
'value_html' => $valueHtml,
|
||||
)) . "\n";
|
||||
}
|
||||
|
||||
<h2>Bron</h2>
|
||||
|
||||
<table>
|
||||
<tr><th>catalog source</th><td><code>' . h($info['source']) . '</code></td></tr>
|
||||
<tr><th>repo url</th><td><code>' . h($info['repo_url']) . '</code></td></tr>
|
||||
<tr><th>fetch status</th><td><code>' . h($zipInfo['status'] ?? '') . '</code></td></tr>
|
||||
<tr><th>default branch</th><td><code>' . h($zipInfo['default_branch'] ?? '') . '</code></td></tr>
|
||||
<tr><th>head sha</th><td><code>' . h($zipInfo['head_sha'] ?? '') . '</code></td></tr>
|
||||
<tr><th>zip file</th><td><code>' . h($zipInfo['zip_file'] ?? '') . '</code></td></tr>
|
||||
<tr><th>zip bytes</th><td><code>' . h((string)($zipInfo['zip_bytes'] ?? '')) . '</code></td></tr>
|
||||
<tr><th>zip sha256</th><td><code>' . h($zipInfo['zip_sha256'] ?? '') . '</code></td></tr>
|
||||
<tr><th>parts status</th><td><code>' . h($manifest['parts_status'] ?? '') . '</code></td></tr>
|
||||
<tr><th>max base64 part size</th><td><code>' . h((string)PACKAGE_ZIP_MAX_BASE64_KB) . '</code> KiB (<code>' . h((string)PACKAGE_ZIP_MAX_BASE64_BYTES) . '</code> bytes)</td></tr>
|
||||
<tr><th>binary chunk size</th><td><code>' . h((string)($manifest['binary_chunk_bytes'] ?? '')) . '</code> bytes</td></tr>
|
||||
<tr><th>part count</th><td><code>' . h((string)$manifest['part_count']) . '</code></td></tr>
|
||||
<tr><th>next id</th><td><code>' . h($NEXT_ID) . '</code></td></tr>
|
||||
</table>
|
||||
|
||||
<h2>Base64 parts</h2>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>part</th>
|
||||
<th>base64 bytes</th>
|
||||
<th>text/plain URL</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
' . $rows . '
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h2>Reconstructie in de sandbox</h2>
|
||||
|
||||
<pre>
|
||||
# download alle links als:
|
||||
# ' . h($package) . '.part.000001.b64
|
||||
# ' . h($package) . '.part.000002.b64
|
||||
# enz.
|
||||
|
||||
cat ' . h($package) . '.part.*.b64 > ' . h($package) . '.zip.b64
|
||||
base64 -d ' . h($package) . '.zip.b64 > ' . h($package) . '.zip
|
||||
raco pkg install --auto ./' . h($package) . '.zip
|
||||
</pre>
|
||||
|
||||
</body>
|
||||
</html>');
|
||||
html_response(RacketSandboxTemplate::renderFile('package.html', array(
|
||||
'package' => $package,
|
||||
'source_rows_html' => $sourceRows,
|
||||
'part_rows_html' => $rows,
|
||||
)));
|
||||
}
|
||||
|
||||
function serve_package_part()
|
||||
|
||||
Reference in New Issue
Block a user