added examples shortcode

This commit is contained in:
Fred 2020-12-07 06:37:19 +08:00
parent 92f6e190dc
commit 8d4b6efe34
5 changed files with 91 additions and 1 deletions

View File

@ -3,6 +3,45 @@
class APIgoatDoc extends APIgoatTemplate
{
static function getExamples(array $data, array $headers)
{
$content = '';
$menu = '';
foreach ($data as $row) {
if (!empty($row['name'])) {
$menu .= li(href($row['name'], '#' . $row['name']), "class='page_item wd-state-closed'");
$content .= div(
anchor($row['name'])
. h2($row['name'], "class='entry-title'")
. p(trim($row['text']))
. ((!empty($row['json'])) ? div(span("Example:") . $row['json']) : ''),
"",
"class='doc-item'"
);
}
}
foreach ($headers as $name => $header) {
$menu = h3($header) . $menu;
}
return div(
div(
ul($menu, "class='doc-nav-list'"),
'',
"class='wedocs-sidebar wedocs-hide-mobile'"
) . div(
$content,
'',
"class='wedocs-single-content'"
),
'',
"class='wedocs-single-wrap'"
);
}
static function getDocs(array $data, array $headers)
{
$content = '';

View File

@ -68,6 +68,31 @@ class APIgoatFetchAPI
}
}
public function fetchExamples()
{
$clientOptions = $this->clientOptions;
$clientOptions['query'] = [
"query" => [
"select" => [
"name", ["description", "text"], ["example_category.name", "category_name"], "json"
],
"join" => ["example_category"]
]
];
//$clientOptions['debug'] = true;
$response = $this->client->get('Example', $clientOptions);
$body = json_decode($response->getBody()->getContents(), true);
//$body['debug'][] = $clientOptions['query'];
if ($response->getStatusCode() == 200) {
return $body;
} else {
$body = json_decode($response->getBody(), true);
return $body;
}
}
private function saveCredentials()
{
if (!empty($this->jwt_pubkey)) {

View File

@ -0,0 +1,25 @@
<?php
class APIgoatListExamples
{
static function init($atts, $content = null)
{
$APIgoatFetchAPI = new APIgoatFetchAPI();
$Behaviors = $APIgoatFetchAPI->fetchExamples();
if (isset($Behaviors['debug'])) {
echo "<br>" . preprint($Behaviors['debug']) . "<br>";
}
if (isset($Behaviors['messages'])) {
echo "<br>" . preprint($Behaviors['messages']) . "<br>";
}
if ($Behaviors['data']) {
$table = APIgoatDoc::getExamples($Behaviors['data'], ['Code' => 'Examples']);
return $content . div($table, '', "class='site-main'");
} else {
return $content . "<br>Error" . preprint($Behaviors);
}
}
}

View File

@ -15,7 +15,7 @@ class APIgoatListModifiers
echo "<br>" . preprint($Behaviors['messages']) . "<br>";
}*/
if ($Behaviors['data']) {
$table = APIgoatDoc::getDocs($Behaviors['data'], ['Code' => 'Parameters']);
$table = APIgoatDoc::getDocs($Behaviors['data'], ['Code' => 'Modifiers']);
return $content . div($table, '', "class='site-main'");
} else {

View File

@ -125,6 +125,7 @@ class apigoat_doc
require_once plugin_dir_path(dirname(__FILE__)) . 'public/class-apigoat_doc-public.php';
require plugin_dir_path(dirname(__FILE__)) . 'classes/APIgoatListModifiers.php';
require plugin_dir_path(dirname(__FILE__)) . 'classes/APIgoatListExamples.php';
$this->loader = new apigoat_doc_Loader();
}