Skip to content

Commit

Permalink
update seo and generator
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Oct 12, 2024
1 parent c3e40cf commit 38344c4
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 16 deletions.
23 changes: 21 additions & 2 deletions www/resources/template/generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,30 @@
<textarea id="schema" name="schema" rows="24" class="form-control"><?php echo htmlspecialchars($schema); ?></textarea>
</div>
<input type="submit" value="Generate" class="btn btn-primary">
<input type="submit" value="Download" class="btn btn-secondary">
</form>
</div>
<div class="col-6">
<div><pre><code class="<?php echo $type ?? ''; ?>"><?php echo isset($output) ? htmlspecialchars($output) : ''; ?></code></pre></div>
<?php if(isset($output)): ?>
<form method="post" action="<?php echo $router->getAbsolutePath([\App\Controller\Generator::class, 'download'], ['type' => $type]); ?>">
<input type="hidden" name="namespace" value="<?php echo htmlspecialchars($namespace ?? ''); ?>">
<input type="hidden" name="schema" value="<?php echo htmlspecialchars($schema); ?>">
<input type="submit" value="Download" class="btn btn-primary">
</form>
<hr>
<?php if ($output instanceof stdClass): ?>
<?php foreach ($output as $fileName => $chunk): ?>
<div class="psx-object">
<h1><?php echo $fileName; ?></h1>
<div class="example-box"><pre><code class="<?php echo $type; ?>"><?php echo htmlspecialchars($chunk); ?></code></pre></div>
</div>
<?php endforeach; ?>
<?php else: ?>
<div class="psx-object">
<h1>Output</h1>
<div class="example-box"><pre><code class="<?php echo $type; ?>"><?php echo htmlspecialchars($output); ?></code></pre></div>
</div>
<?php endif; ?>
<?php endif; ?>
</div>
</div>
</div>
Expand Down
6 changes: 4 additions & 2 deletions www/resources/template/generator_overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

<div class="container">
<h1 class="display-4">DTO Generator</h1>
<p>fsdfsdf</p>

<p class="lead">This list gives you access to our reference code generator implementation.
For more advanced integration options like an REST API, CLI or GitHub action please take a look
at the <a href="https://sdkgen.app/">SDKgen project</a>.
</p>
<div class="row">
<?php foreach ($types as $chunk): ?>
<div class="col-6">
Expand Down
9 changes: 3 additions & 6 deletions www/resources/template/inc/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="TypeSchema is a JSON format to describe data models in a language neutral format. A TypeSchema can be easily transformed into specific code for almost any programming language.">
<meta name="keywords" content="JSON Schema, TypeSchema, Data, Model, Specification, Code Generation">
<title>TypeSchema</title>
<meta name="description" content="TypeSchema is a JSON specification to describe data models in a programming language neutral format.">
<meta name="keywords" content="JSON Schema, TypeSchema, Data, Model, Specification, Code Generation, Code Generator">
<title><?php if(isset($title)): ?><?php echo $title; ?><?php else: ?>TypeSchema<?php endif; ?></title>
<link rel="preload" href="<?php echo $base; ?>/css/app.min.css" as="style" />
<link rel="preload" href="<?php echo $base; ?>/js/app.min.js" as="script" />
<link rel="stylesheet" href="<?php echo $base; ?>/css/app.min.css">
Expand Down Expand Up @@ -33,9 +33,6 @@ function gtag(){dataLayer.push(arguments);}
<li class="nav-item">
<a class="nav-link" href="<?php echo $router->getAbsolutePath([\App\Controller\Generator::class, 'show']); ?>">Generator</a>
</li>
<li class="nav-item">
<a class="nav-link" href="<?php echo $router->getAbsolutePath([\App\Controller\Developer::class, 'show']); ?>">Developer</a>
</li>
<li class="nav-item">
<a class="nav-link" href="<?php echo $router->getAbsolutePath([\App\Controller\Ecosystem::class, 'show']); ?>">Ecosystem</a>
</li>
Expand Down
1 change: 1 addition & 0 deletions www/src/Controller/Changelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function __construct(ReverseRouter $reverseRouter, SchemaManagerInterface
public function show(): mixed
{
$data = [
'title' => 'Changelog | TypeSchema',
'method' => explode('::', __METHOD__),
'left' => $this->getLeft(),
'right' => $this->getRight(),
Expand Down
1 change: 1 addition & 0 deletions www/src/Controller/Developer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function __construct(ReverseRouter $reverseRouter)
public function show(): mixed
{
$data = [
'title' => 'Developer | TypeSchema',
'method' => explode('::', __METHOD__),
];

Expand Down
1 change: 1 addition & 0 deletions www/src/Controller/Ecosystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function __construct(ReverseRouter $reverseRouter)
public function show(): mixed
{
$data = [
'title' => 'Ecosystem | TypeSchema',
'method' => explode('::', __METHOD__),
];

Expand Down
1 change: 1 addition & 0 deletions www/src/Controller/Example.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function show(string $type): mixed
}

$data = [
'title' => TypeName::getDisplayName($type) . ' Example | TypeSchema',
'method' => explode('::', __METHOD__),
'parameters' => ['type' => $type],
'type' => TypeName::getDisplayName($type),
Expand Down
1 change: 1 addition & 0 deletions www/src/Controller/Faq.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function __construct(ReverseRouter $reverseRouter)
public function show(): mixed
{
$data = [
'title' => 'FAQ | TypeSchema',
'method' => explode('::', __METHOD__),
];

Expand Down
56 changes: 50 additions & 6 deletions www/src/Controller/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@
use PSX\Api\Attribute\Get;
use PSX\Api\Attribute\Path;
use PSX\Api\Attribute\Post;
use PSX\Framework\Config\ConfigInterface;
use PSX\Framework\Controller\ControllerAbstract;
use PSX\Framework\Http\Writer\Template;
use PSX\Framework\Loader\ReverseRouter;
use PSX\Http\Environment\HttpResponse;
use PSX\Http\Exception\BadRequestException;
use PSX\Http\Writer\File;
use PSX\Schema\Generator\Code\Chunks;
use PSX\Schema\Generator\Config;
use PSX\Schema\Generator\FileAwareInterface;
use PSX\Schema\GeneratorFactory;
use PSX\Schema\Parser\TypeSchema;
use PSX\Schema\SchemaManagerInterface;

class Generator extends ControllerAbstract
{
private ReverseRouter $reverseRouter;
private SchemaManagerInterface $schemaManager;

public function __construct(ReverseRouter $reverseRouter, SchemaManagerInterface $schemaManager)
public function __construct(private ReverseRouter $reverseRouter, private SchemaManagerInterface $schemaManager, private ConfigInterface $config)
{
$this->reverseRouter = $reverseRouter;
$this->schemaManager = $schemaManager;
}

#[Get]
Expand All @@ -37,6 +37,7 @@ public function show(): mixed
}

$data = [
'title' => 'DTO Generator | TypeSchema',
'method' => explode('::', __METHOD__),
'schema' => $this->getSchema(),
'types' => array_chunk($types, 9, true),
Expand All @@ -55,6 +56,7 @@ public function showType(string $type): mixed
}

$data = [
'title' => TypeName::getDisplayName($type) . ' DTO Generator | TypeSchema',
'method' => explode('::', __METHOD__),
'parameters' => ['type' => $type],
'schema' => $this->getSchema(),
Expand Down Expand Up @@ -92,6 +94,7 @@ public function generate(string $type, Generate $generate): mixed
}

$data = [
'title' => TypeName::getDisplayName($type) . ' DTO Generator | TypeSchema',
'method' => explode('::', __METHOD__),
'parameters' => ['type' => $type],
'namespace' => $namespace,
Expand All @@ -105,6 +108,47 @@ public function generate(string $type, Generate $generate): mixed
return new Template($data, $templateFile, $this->reverseRouter);
}

#[Post]
#[Path('/generator/:type/download')]
public function download(string $type, Generate $generate): mixed
{
$namespace = $generate->getNamespace();
$schema = $generate->getSchema() ?? throw new \RuntimeException('Provided no schema');

$config = new Config();
if (!empty($namespace)) {
$config->put(Config::NAMESPACE, $namespace);
}

if (!in_array($type, GeneratorFactory::getPossibleTypes())) {
throw new BadRequestException('Provided an invalid type');
}

try {
$result = (new TypeSchema($this->schemaManager))->parse($schema);
$generator = (new GeneratorFactory())->getGenerator($type, $config);

$output = $generator->generate($result);

if ($output instanceof Chunks && $generator instanceof FileAwareInterface) {
$zipFile = $this->config->get('psx_path_cache') . '/typeschema_gen_' . sha1($schema) . '.zip';

$result = new Chunks();
foreach ($output as $identifier => $code) {
$result->append($generator->getFileName($identifier), $generator->getFileContent($code));
}

$result->writeToZip($zipFile);

return new File($zipFile, 'typeschema_' . $type . '.zip', 'application/zip');
} else {
return new HttpResponse(200, ['Content-Type' => 'text/plain'], (string) $output);
}
} catch (\Throwable $e) {
return new HttpResponse(500, ['Content-Type' => 'text/plain'], $e->getMessage());
}
}

private function getSchema(): string
{
return <<<'JSON'
Expand Down
1 change: 1 addition & 0 deletions www/src/Controller/Hash.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function __construct(ReverseRouter $reverseRouter, SchemaManagerInterface
public function show(): mixed
{
$data = [
'title' => 'Hash | TypeSchema',
'method' => explode('::', __METHOD__),
'schema' => $this->getSchema(),
];
Expand Down
1 change: 1 addition & 0 deletions www/src/Controller/Specification.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function __construct(ReverseRouter $reverseRouter)
public function show(): mixed
{
$data = [
'title' => 'Specification | TypeSchema',
'method' => explode('::', __METHOD__),
];

Expand Down

0 comments on commit 38344c4

Please sign in to comment.