Skip to content

Commit

Permalink
Fix #19, #20 and #21
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Molenaar authored and Sean Molenaar committed Oct 6, 2016
1 parent eb42269 commit bfcceb3
Show file tree
Hide file tree
Showing 7 changed files with 458 additions and 28 deletions.
41 changes: 37 additions & 4 deletions src/PHPDraft/Model/Elements/DataStructureElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace PHPDraft\Model\Elements;

use Michelf\Markdown;
use PHPDraft\Model\StructureElement;

class DataStructureElement implements StructureElement
Expand Down Expand Up @@ -90,6 +91,8 @@ public function parse($object, &$dependencies)
$this->status =
isset($object->attributes->typeAttributes) ? join(', ', $object->attributes->typeAttributes) : NULL;

$this->description_as_html();

if (!in_array($this->type, self::DEFAULTS))
{
$dependencies[] = $this->type;
Expand All @@ -115,7 +118,18 @@ public function parse($object, &$dependencies)
return $this;
}

$this->value = isset($object->content->value->content) ? $object->content->value->content : NULL;
if (isset($object->content->value->content))
{
$this->value = $object->content->value->content;
}
elseif (isset($object->content->value->attributes->samples))
{
$this->value = join(' | ', $object->content->value->attributes->samples);
}
else
{
$this->value = NULL;
}

return $this;
}
Expand Down Expand Up @@ -157,9 +171,9 @@ function __toString()
}

$type = (!in_array($this->type, self::DEFAULTS)) ?
'<a class="code" href="#object-' . str_replace(' ', '-', strtolower($this->type)). '">' . $this->type . '</a>' : '<code>' . $this->type . '</code>';
'<a class="code" href="#object-' . str_replace(' ', '-', strtolower($this->type)) . '">' . $this->type . '</a>' : '<code>' . $this->type . '</code>';

if (empty($this->value))
if (is_null($this->value))
{
$value = '';
}
Expand All @@ -179,7 +193,16 @@ function __toString()
}
else
{
$value = '<span class="example-value pull-right">' . $this->value . '</span>';
$value = '<span class="example-value pull-right">';
if (is_bool($this->value))
{
$value .= ($this->value) ? 'TRUE' : 'FALSE';
}
else
{
$value .= $this->value;
}
$value .= '</span>';
}
}

Expand All @@ -195,4 +218,14 @@ function __toString()
return $return;
}

/**
* Parse the description to HTML
*
* @return string
*/
public function description_as_html()
{
$this->description = Markdown::defaultTransform($this->description);
}

}
12 changes: 11 additions & 1 deletion src/PHPDraft/Model/Elements/EnumStructureElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace PHPDraft\Model\Elements;

use Michelf\Markdown;
use PHPDraft\Model\StructureElement;

class EnumStructureElement implements StructureElement
Expand Down Expand Up @@ -51,6 +52,7 @@ function parse($item, &$dependencies)
$this->element = (isset($item->element)) ? $item->element : NULL;
$this->description = (isset($item->meta->description)) ? $item->meta->description : NULL;
$this->value = (isset($item->content)) ? $item->content : NULL;
$this->description_as_html();

if (!in_array($this->element, self::DEFAULTS))
{
Expand All @@ -77,5 +79,13 @@ function __toString()
return $return;
}


/**
* Parse the description to HTML
*
* @return string
*/
public function description_as_html()
{
$this->description = Markdown::defaultTransform($this->description);
}
}
1 change: 1 addition & 0 deletions src/PHPDraft/Model/Elements/RequestBodyElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function parse($object, &$dependencies)
$this->key = $object->content->key->content;
$this->type = $object->content->value->element;
$this->description = isset($object->meta->description) ? $object->meta->description : NULL;
$this->description_as_html();
$this->status =
isset($object->attributes->typeAttributes[0]) ? $object->attributes->typeAttributes[0] : NULL;

Expand Down
19 changes: 8 additions & 11 deletions src/PHPDraft/Out/HTML/default.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
/**
* Created by smillernl on 23-8-16.
*/
$(function () {
$('[data-toggle="popover"]').popover()
})
$('[data-toggle="popover"]').popover();
});

$('.collapse.request-panel').on('shown.bs.collapse', function () {
$(this).parent().find("h4.request .glyphicon.indicator").removeClass("glyphicon-menu-up").addClass("glyphicon-menu-down");
$(this).parent().find('h4.request .glyphicon.indicator').removeClass('glyphicon-menu-up').addClass('glyphicon-menu-down');
}).on('hidden.bs.collapse', function () {
$(this).parent().find("h4.request .glyphicon.indicator").removeClass("glyphicon-menu-down").addClass("glyphicon-menu-up");
$(this).parent().find('h4.request .glyphicon.indicator').removeClass('glyphicon-menu-down').addClass('glyphicon-menu-up');
});

$('.collapse.response-panel').on('shown.bs.collapse', function () {
$(this).parent().find("h4.response .glyphicon.indicator").removeClass("glyphicon-menu-up").addClass("glyphicon-menu-down");
$(this).parent().find('h4.response .glyphicon.indicator').removeClass('glyphicon-menu-up').addClass("glyphicon-menu-down");
}).on('hidden.bs.collapse', function () {
$(this).parent().find("h4.response .glyphicon.indicator").removeClass("glyphicon-menu-down").addClass("glyphicon-menu-up");
$(this).parent().find('h4.response .glyphicon.indicator').removeClass('glyphicon-menu-down').addClass("glyphicon-menu-up");
});

$('pre.collapse.response-body').on('shown.bs.collapse', function () {
$(this).parent().find("h5.response-body .glyphicon.indicator").removeClass("glyphicon-menu-up").addClass("glyphicon-menu-down");
$(this).parent().find('h5.response-body .glyphicon.indicator').removeClass('glyphicon-menu-up').addClass('glyphicon-menu-down');
}).on('hidden.bs.collapse', function () {
$(this).parent().find("h5.response-body .glyphicon.indicator").removeClass("glyphicon-menu-down").addClass("glyphicon-menu-up");
$(this).parent().find('h5.response-body .glyphicon.indicator').removeClass('glyphicon-menu-down').addClass('glyphicon-menu-up');
});
22 changes: 11 additions & 11 deletions src/PHPDraft/Out/HTML/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
* @package PHPDraft\HTML
* @author Sean Molenaar<[email protected]>
*/
use PHPDraft\Out\Minifier;

/**
* @var \PHPDraft\Model\APIBlueprintElement[]
* @var \PHPDraft\Model\HierarchyElement[]
*/
$base = $this->categories;
?>
Expand All @@ -19,7 +20,7 @@
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<style>
<?= file_get_contents(__DIR__ . '/'.$this->template.'.css');?>
<?= Minifier::minify_css(file_get_contents(__DIR__ . '/'.$this->template.'.css'));?>
</style>
</head>
<body>
Expand Down Expand Up @@ -89,7 +90,7 @@ class="pull-right <?= $this->get_method_icon($transition->get_method()); ?>"></s
<ul class="list-unstyled">
<?php foreach ($this->base_structures as $key => $structure): ?>
<li>
<a href="#object-<?= str_replace(' ', '_', $key); ?>"><?= $key; ?></a>
<a href="#object-<?= str_replace(' ', '_', strtolower($key)); ?>"><?= $key; ?></a>
</li>
<?php endforeach; ?>
</ul>
Expand Down Expand Up @@ -249,11 +250,7 @@ class="value"><?= $value; ?></span>
<?= $key; ?>

</h5>
<pre
class="collapse collapsed response-body"
id="request-<?= $href ?>">
<?= $value; ?>
</pre>
<pre class="collapse collapsed response-body" id="request-<?= $href ?>"><?= $value; ?></pre>
</div>
<?php endforeach; ?>
</div>
Expand All @@ -265,11 +262,13 @@ class="collapse collapsed response-body"
<?php endforeach; ?>
<?php endforeach; ?>
<?php endforeach; ?>
<?php if(count($this->base_structures) > 0):?>
<h2><a id="datastructures">Data structures</a></h2>
<?php foreach ($this->base_structures as $key => $structure): ?>
<div class="panel panel-default object-<?= str_replace(' ', '-', strtolower($key)); ?> structure">
<div class="panel panel-default object-<?= str_replace(' ', '_', strtolower($key)); ?> structure">
<div class="panel-heading">
<h3 class="panel-title">
<a id="object-<?= str_replace(' ', '-', strtolower($key)); ?>"><?= $key; ?></a>
<a id="object-<?= str_replace(' ', '_', strtolower($key)); ?>"><?= $key; ?></a>
</h3>
</div>
<div class="panel-body">
Expand All @@ -279,6 +278,7 @@ class="collapse collapsed response-body"
</div>
</div>
<?php endforeach; ?>
<?php endif;?>
</div>
</div>
</div>
Expand All @@ -288,6 +288,6 @@ class="collapse collapsed response-body"
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
crossorigin="anonymous"></script>
<script><?= file_get_contents(__DIR__ . '/' . $this->template . '.js'); ?></script>
<script><?= Minifier::minify_js( file_get_contents(__DIR__ . '/' . $this->template . '.js')); ?></script>
</body>
</html>
Loading

0 comments on commit bfcceb3

Please sign in to comment.