Skip to content

Commit bfcceb3

Browse files
Sean MolenaarSean Molenaar
Sean Molenaar
authored and
Sean Molenaar
committed
Fix #19, #20 and #21
1 parent eb42269 commit bfcceb3

7 files changed

+458
-28
lines changed

src/PHPDraft/Model/Elements/DataStructureElement.php

+37-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace PHPDraft\Model\Elements;
1010

11+
use Michelf\Markdown;
1112
use PHPDraft\Model\StructureElement;
1213

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

94+
$this->description_as_html();
95+
9396
if (!in_array($this->type, self::DEFAULTS))
9497
{
9598
$dependencies[] = $this->type;
@@ -115,7 +118,18 @@ public function parse($object, &$dependencies)
115118
return $this;
116119
}
117120

118-
$this->value = isset($object->content->value->content) ? $object->content->value->content : NULL;
121+
if (isset($object->content->value->content))
122+
{
123+
$this->value = $object->content->value->content;
124+
}
125+
elseif (isset($object->content->value->attributes->samples))
126+
{
127+
$this->value = join(' | ', $object->content->value->attributes->samples);
128+
}
129+
else
130+
{
131+
$this->value = NULL;
132+
}
119133

120134
return $this;
121135
}
@@ -157,9 +171,9 @@ function __toString()
157171
}
158172

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

162-
if (empty($this->value))
176+
if (is_null($this->value))
163177
{
164178
$value = '';
165179
}
@@ -179,7 +193,16 @@ function __toString()
179193
}
180194
else
181195
{
182-
$value = '<span class="example-value pull-right">' . $this->value . '</span>';
196+
$value = '<span class="example-value pull-right">';
197+
if (is_bool($this->value))
198+
{
199+
$value .= ($this->value) ? 'TRUE' : 'FALSE';
200+
}
201+
else
202+
{
203+
$value .= $this->value;
204+
}
205+
$value .= '</span>';
183206
}
184207
}
185208

@@ -195,4 +218,14 @@ function __toString()
195218
return $return;
196219
}
197220

221+
/**
222+
* Parse the description to HTML
223+
*
224+
* @return string
225+
*/
226+
public function description_as_html()
227+
{
228+
$this->description = Markdown::defaultTransform($this->description);
229+
}
230+
198231
}

src/PHPDraft/Model/Elements/EnumStructureElement.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace PHPDraft\Model\Elements;
1010

11+
use Michelf\Markdown;
1112
use PHPDraft\Model\StructureElement;
1213

1314
class EnumStructureElement implements StructureElement
@@ -51,6 +52,7 @@ function parse($item, &$dependencies)
5152
$this->element = (isset($item->element)) ? $item->element : NULL;
5253
$this->description = (isset($item->meta->description)) ? $item->meta->description : NULL;
5354
$this->value = (isset($item->content)) ? $item->content : NULL;
55+
$this->description_as_html();
5456

5557
if (!in_array($this->element, self::DEFAULTS))
5658
{
@@ -77,5 +79,13 @@ function __toString()
7779
return $return;
7880
}
7981

80-
82+
/**
83+
* Parse the description to HTML
84+
*
85+
* @return string
86+
*/
87+
public function description_as_html()
88+
{
89+
$this->description = Markdown::defaultTransform($this->description);
90+
}
8191
}

src/PHPDraft/Model/Elements/RequestBodyElement.php

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public function parse($object, &$dependencies)
4141
$this->key = $object->content->key->content;
4242
$this->type = $object->content->value->element;
4343
$this->description = isset($object->meta->description) ? $object->meta->description : NULL;
44+
$this->description_as_html();
4445
$this->status =
4546
isset($object->attributes->typeAttributes[0]) ? $object->attributes->typeAttributes[0] : NULL;
4647

src/PHPDraft/Out/HTML/default.js

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
1-
/**
2-
* Created by smillernl on 23-8-16.
3-
*/
41
$(function () {
5-
$('[data-toggle="popover"]').popover()
6-
})
2+
$('[data-toggle="popover"]').popover();
3+
});
74

85
$('.collapse.request-panel').on('shown.bs.collapse', function () {
9-
$(this).parent().find("h4.request .glyphicon.indicator").removeClass("glyphicon-menu-up").addClass("glyphicon-menu-down");
6+
$(this).parent().find('h4.request .glyphicon.indicator').removeClass('glyphicon-menu-up').addClass('glyphicon-menu-down');
107
}).on('hidden.bs.collapse', function () {
11-
$(this).parent().find("h4.request .glyphicon.indicator").removeClass("glyphicon-menu-down").addClass("glyphicon-menu-up");
8+
$(this).parent().find('h4.request .glyphicon.indicator').removeClass('glyphicon-menu-down').addClass('glyphicon-menu-up');
129
});
1310

1411
$('.collapse.response-panel').on('shown.bs.collapse', function () {
15-
$(this).parent().find("h4.response .glyphicon.indicator").removeClass("glyphicon-menu-up").addClass("glyphicon-menu-down");
12+
$(this).parent().find('h4.response .glyphicon.indicator').removeClass('glyphicon-menu-up').addClass("glyphicon-menu-down");
1613
}).on('hidden.bs.collapse', function () {
17-
$(this).parent().find("h4.response .glyphicon.indicator").removeClass("glyphicon-menu-down").addClass("glyphicon-menu-up");
14+
$(this).parent().find('h4.response .glyphicon.indicator').removeClass('glyphicon-menu-down').addClass("glyphicon-menu-up");
1815
});
1916

2017
$('pre.collapse.response-body').on('shown.bs.collapse', function () {
21-
$(this).parent().find("h5.response-body .glyphicon.indicator").removeClass("glyphicon-menu-up").addClass("glyphicon-menu-down");
18+
$(this).parent().find('h5.response-body .glyphicon.indicator').removeClass('glyphicon-menu-up').addClass('glyphicon-menu-down');
2219
}).on('hidden.bs.collapse', function () {
23-
$(this).parent().find("h5.response-body .glyphicon.indicator").removeClass("glyphicon-menu-down").addClass("glyphicon-menu-up");
20+
$(this).parent().find('h5.response-body .glyphicon.indicator').removeClass('glyphicon-menu-down').addClass('glyphicon-menu-up');
2421
});

src/PHPDraft/Out/HTML/default.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
* @package PHPDraft\HTML
66
* @author Sean Molenaar<[email protected]>
77
*/
8+
use PHPDraft\Out\Minifier;
89

910
/**
10-
* @var \PHPDraft\Model\APIBlueprintElement[]
11+
* @var \PHPDraft\Model\HierarchyElement[]
1112
*/
1213
$base = $this->categories;
1314
?>
@@ -19,7 +20,7 @@
1920
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
2021
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
2122
<style>
22-
<?= file_get_contents(__DIR__ . '/'.$this->template.'.css');?>
23+
<?= Minifier::minify_css(file_get_contents(__DIR__ . '/'.$this->template.'.css'));?>
2324
</style>
2425
</head>
2526
<body>
@@ -89,7 +90,7 @@ class="pull-right <?= $this->get_method_icon($transition->get_method()); ?>"></s
8990
<ul class="list-unstyled">
9091
<?php foreach ($this->base_structures as $key => $structure): ?>
9192
<li>
92-
<a href="#object-<?= str_replace(' ', '_', $key); ?>"><?= $key; ?></a>
93+
<a href="#object-<?= str_replace(' ', '_', strtolower($key)); ?>"><?= $key; ?></a>
9394
</li>
9495
<?php endforeach; ?>
9596
</ul>
@@ -249,11 +250,7 @@ class="value"><?= $value; ?></span>
249250
<?= $key; ?>
250251

251252
</h5>
252-
<pre
253-
class="collapse collapsed response-body"
254-
id="request-<?= $href ?>">
255-
<?= $value; ?>
256-
</pre>
253+
<pre class="collapse collapsed response-body" id="request-<?= $href ?>"><?= $value; ?></pre>
257254
</div>
258255
<?php endforeach; ?>
259256
</div>
@@ -265,11 +262,13 @@ class="collapse collapsed response-body"
265262
<?php endforeach; ?>
266263
<?php endforeach; ?>
267264
<?php endforeach; ?>
265+
<?php if(count($this->base_structures) > 0):?>
266+
<h2><a id="datastructures">Data structures</a></h2>
268267
<?php foreach ($this->base_structures as $key => $structure): ?>
269-
<div class="panel panel-default object-<?= str_replace(' ', '-', strtolower($key)); ?> structure">
268+
<div class="panel panel-default object-<?= str_replace(' ', '_', strtolower($key)); ?> structure">
270269
<div class="panel-heading">
271270
<h3 class="panel-title">
272-
<a id="object-<?= str_replace(' ', '-', strtolower($key)); ?>"><?= $key; ?></a>
271+
<a id="object-<?= str_replace(' ', '_', strtolower($key)); ?>"><?= $key; ?></a>
273272
</h3>
274273
</div>
275274
<div class="panel-body">
@@ -279,6 +278,7 @@ class="collapse collapsed response-body"
279278
</div>
280279
</div>
281280
<?php endforeach; ?>
281+
<?php endif;?>
282282
</div>
283283
</div>
284284
</div>
@@ -288,6 +288,6 @@ class="collapse collapsed response-body"
288288
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
289289
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
290290
crossorigin="anonymous"></script>
291-
<script><?= file_get_contents(__DIR__ . '/' . $this->template . '.js'); ?></script>
291+
<script><?= Minifier::minify_js( file_get_contents(__DIR__ . '/' . $this->template . '.js')); ?></script>
292292
</body>
293293
</html>

0 commit comments

Comments
 (0)