Skip to content

Commit

Permalink
preparing initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
erikaheidi committed Sep 6, 2023
1 parent 94b989b commit 4a15ebe
Show file tree
Hide file tree
Showing 21 changed files with 267 additions and 175 deletions.
10 changes: 0 additions & 10 deletions Autodocs.php

This file was deleted.

3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
}
},
"require": {
"minicli/minicli": "^4.2"
"minicli/minicli": "^4.2",
"minicli/stencil": "^0.2.1"
},
"require-dev": {
"pestphp/pest": "^2.16",
Expand Down
46 changes: 45 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/DataFeed/DataFeedInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Autodocs\DataFeed;

interface DataFeedInterface
{
public function load(string $data): void;
public function save(string $path): void;
}
16 changes: 4 additions & 12 deletions src/DataFeed.php → src/DataFeed/JsonDataFeed.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
<?php

namespace Autodocs;
namespace Autodocs\DataFeed;

use Autodocs\Exception\NotFoundException;

class DataFeed
class JsonDataFeed implements DataFeedInterface
{
public string $identifier;

public string $data;

public array $json = [];

public function __construct(string $identifier)
{
$this->identifier = $identifier;
}

/**
* @throws NotFoundException
*/
Expand Down Expand Up @@ -44,8 +36,8 @@ public function loadFromArray(array $data): void
$this->data = json_encode($data);
}

public function save(string $filePath): void
public function save(string $path): void
{
file_put_contents($filePath, $this->data);
file_put_contents($path, $this->data);
}
}
2 changes: 1 addition & 1 deletion src/Mark/Mark.php → src/Mark.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Autodocs\Mark;
namespace Autodocs;

class Mark
{
Expand Down
17 changes: 6 additions & 11 deletions src/Page/ExamplePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

namespace Autodocs\Page;

use Autodocs\DataFeed;
use Autodocs\DataFeed\JsonDataFeed;

class ExamplePage extends ReferencePage
{
public function loadData(): void
public JsonDataFeed $dataFeed;
public function loadData(array $parameters = []): void
{
$datafeed = new DataFeed('example');
$datafeed->loadFromArray([
$this->dataFeed = new JsonDataFeed();
$this->dataFeed->loadFromArray([
'title' => 'example',
'description' => 'description'
]);
$this->registerDataFeed($datafeed);
}

public function getName(): string
Expand All @@ -23,12 +23,7 @@ public function getName(): string

public function getContent(): string
{
$data = $this->getDataFeed('example');
if ($data == null) {
return "";
}

return $data->json['title'] . ' - ' . $data->json['description'];
return $this->dataFeed->json['title'] . ' - ' . $this->dataFeed->json['description'];
}

public function getSavePath(): string
Expand Down
30 changes: 6 additions & 24 deletions src/Page/ReferencePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,13 @@

namespace Autodocs\Page;

use Autodocs\DataFeed;
use Autodocs\Service\AutodocsService;

abstract class ReferencePage
abstract class ReferencePage implements ReferencePageInterface
{
public array $dataFeeds = [];

public function registerDataFeed(DataFeed $dataFeed): void
{
$this->dataFeeds[] = $dataFeed;
}

public function getDataFeed(string $identifier): ?DataFeed
public AutodocsService $autodocs;
public function __construct(AutodocsService $autodocs)
{
foreach ($this->dataFeeds as $dataFeed) {
if ($dataFeed->identifier === $identifier) {
return $dataFeed;
}
}
$this->autodocs = $autodocs;
}

abstract public function loadData(): void;

abstract public function getName(): string;

abstract public function getSavePath(): string;

abstract public function getContent(): string;
}
}
17 changes: 17 additions & 0 deletions src/Page/ReferencePageInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Autodocs\Page;

use Autodocs\DataFeed\JsonDataFeed;
use Autodocs\Service\AutodocsService;

interface ReferencePageInterface
{
public function loadData(array $parameters = []): void;

public function getName(): string;

public function getSavePath(): string;

public function getContent(): string;
}
16 changes: 5 additions & 11 deletions src/Page/TestPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

namespace Autodocs\Page;

use Autodocs\DataFeed;
use Autodocs\DataFeed\JsonDataFeed;

class TestPage extends ReferencePage
{
public function loadData(): void
public function loadData(array $parameters = []): void
{
$datafeed = new DataFeed('test');
$datafeed->loadFile(__DIR__ . '/../../tests/Resources/images-tags.json');
$this->registerDataFeed($datafeed);
//
}

public function getName(): string
Expand All @@ -21,12 +19,8 @@ public function getName(): string
public function getContent(): string
{
$content = "";
$data = $this->getDataFeed('test');
if ($data == null) {
return "";
}

foreach ($data->json as $item) {
$dataFeed = $this->autodocs->getDataFeed('images-tags.json');
foreach ($dataFeed->json as $item) {
$content .= "Image Name: " . $item['repo']['name'] . "\n";
}

Expand Down
37 changes: 3 additions & 34 deletions src/PageBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,12 @@

namespace Autodocs;

use Autodocs\Page\ReferencePage;
use Autodocs\Page\ReferencePageInterface;
use Autodocs\Storage\FileStorage;

class PageBuilder
{
public Storage $storage;
public array $referencePages = [];

public function __construct(Storage $storage)
{
$this->storage = $storage;
}

public function registerPages(array $referencePages): void
{
foreach ($referencePages as $referencePage) {
$this->registerPage($referencePage);
}
}

public function registerPage(ReferencePage $page): void
{
$page->loadData();
$this->referencePages[] = $page;
}

public function buildPages(string $pages="all"): void
{
$buildPages = explode(",", $pages);
/** @var ReferencePage $referencePage */
foreach ($this->referencePages as $referencePage) {
if ($pages === "all" || in_array($referencePage->getName(), $buildPages)) {
$this->storage->saveFile($referencePage->getSavePath(), $this->buildPage($referencePage));
}
}
}

public function buildPage(ReferencePage $page): string
public function buildPage(ReferencePageInterface $page): string
{
return $page->getContent();
}
Expand Down
Loading

0 comments on commit 4a15ebe

Please sign in to comment.