Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ API_URL=http://example.com/api
SOURCE=
DIST=
THEME=
HIGHTLIGHT=
HIGHTLIGHT=
NAME_OUTPUT=
VERSION=v1
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,19 @@ SOURCE=
DIST=
THEME=
HIGHTLIGHT=
```

| Variable | Description | Default |
|------------|-------------------------|------------------|
| API_URL | Base URL of requests | |
| SOURCE | Path the markdown files | ./docs |
| DIST | Destination folder | ./public |
| THEME | Theme name | ./themes/default |
| HIGHTLIGHT | Highlight style | dark |
NAME_OUTPUT=
VERSION=
```

| Variable | Description | Default |
|-------------|-------------------------|------------------|
| API_URL | Base URL of requests | |
| SOURCE | Path the markdown files | ./docs |
| DIST | Destination folder | ./public |
| THEME | Theme name | ./themes/default |
| HIGHTLIGHT | Highlight style | dark |
| NAME_OUTPUT | Name output file | index.html |
| VERSION | Version doc output | |

The `API_URL` variable is used to not repeat the complete URL of the request in all markdown files. You can use it `{{API_URL}}`, for example:

Expand Down
12 changes: 6 additions & 6 deletions src/Vaneves/Apirus/Filesystem.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
<?php

namespace Vaneves\Apirus;

use \FilesystemIterator;
use \League\CLImate\CLImate;
use FilesystemIterator;
use League\CLImate\CLImate;

class Filesystem
{
Expand All @@ -24,7 +24,7 @@ public function getStructure()
{
$iterator = new FilesystemIterator($this->path);
$structure = [];
foreach($iterator as $folder) {
foreach ($iterator as $folder) {
if ($folder->isDir() && !preg_match($this->ignoreRegex, $folder->getFilename())) {
if (!$folder->isReadable()) {
$this->console->error("Directory {$folder->getPathname()} not is readable");
Expand All @@ -38,7 +38,7 @@ public function getStructure()

$subiterator = new FilesystemIterator($folder->getPathname());
$files = [];
foreach($subiterator as $file) {
foreach ($subiterator as $file) {
if ($file->isFile()) {
if (!$file->isReadable()) {
$this->console->error("File {$file->getPathname()} not is readable");
Expand All @@ -57,4 +57,4 @@ public function getStructure()

return $structure;
}
}
}
39 changes: 23 additions & 16 deletions src/Vaneves/Apirus/Markdown.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
<?php

namespace Vaneves\Apirus;

use \Parsedown;
use \Symfony\Component\Yaml\Yaml;
use Parsedown;
use Symfony\Component\Yaml\Yaml;

class Markdown
{
Expand Down Expand Up @@ -33,75 +33,82 @@ public function parse($markdown)
$responses = $this->responses($markdown);

return new Section(
$meta
, $content
, $params
, $requests
, $responses
$meta,
$content,
$params,
$requests,
$responses
);
}

protected function variable($text)
{
$text = preg_replace_callback($this->regex['variable'], function ($matches) {
if (isset($matches[2])) {
return env($matches[2]);
}

return $matches[1];
}, $text);

return $text;
}

protected function meta($text)
protected function meta($text)
{
preg_match($this->regex['meta'], $text, $matches);
if (isset($matches[2])) {
return Yaml::parse(trim($matches[2]));
}

return [];
}

protected function params($text)
protected function params($text)
{
preg_match_all($this->regex['param'], $text, $matches);
if (isset($matches[3]) && isset($matches[4])) {
if (count($matches[3]) == count($matches[4])) {
return array_combine($matches[3], $matches[4]);
}
}

return [];
}

protected function requests($text)
protected function requests($text)
{
preg_match_all($this->regex['request'], $text, $matches);
if (isset($matches[3]) && isset($matches[4])) {
if (count($matches[3]) == count($matches[4])) {
return array_combine($matches[3], $matches[4]);
}
}

return [];
}

protected function responses($text)
protected function responses($text)
{
preg_match_all($this->regex['response'], $text, $matches);
if (isset($matches[3]) && isset($matches[6])) {
if (count($matches[3]) == count($matches[6])) {
$result = [];
foreach ($matches[3] as $i => $code) {
$result[$code . $matches[5][$i]] = [
$result[$code.$matches[5][$i]] = [
'code' => $code,
'lang' => $matches[5][$i],
'body' => $matches[6][$i],
];
}

return $result;
}
}

return [];
}

protected function removeMeta($text)
{
return preg_replace($this->regex['meta'], '', $text);
Expand All @@ -121,4 +128,4 @@ protected function removeResponses($text)
{
return preg_replace($this->regex['response'], '', $text);
}
}
}
Loading