Skip to content

Commit 61e1dec

Browse files
Sean MolenaarSean Molenaar
Sean Molenaar
authored and
Sean Molenaar
committed
This should fix #14
1 parent bfcceb3 commit 61e1dec

File tree

5 files changed

+37
-24
lines changed

5 files changed

+37
-24
lines changed

src/PHPDraft/Model/Elements/DataStructureElement.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ function __toString()
158158
if (is_string($object)
159159
|| get_class($object) === self::class
160160
|| get_class($object) === ArrayStructureElement::class
161+
|| get_class($object) === RequestBodyElement::class
161162
|| get_class($object) === EnumStructureElement::class
162163
)
163164
{
@@ -171,15 +172,15 @@ function __toString()
171172
}
172173

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

176177
if (is_null($this->value))
177178
{
178179
$value = '';
179180
}
180181
else
181182
{
182-
if (is_object($this->value) && self::class === get_class($this->value))
183+
if (is_object($this->value) && (self::class === get_class($this->value) || RequestBodyElement::class === get_class($this->value)))
183184
{
184185
$value = '<div class="sub-struct">' . $this->value . '</div>';
185186
}

src/PHPDraft/Model/HTTPRequest.php

+4
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ public function parse($object)
7171
if ($value->element === 'dataStructure')
7272
{
7373
$this->parse_structure($value->content);
74+
echo '<pre>';
75+
var_dump($this->struct);
76+
echo '</pre>';
7477
continue;
7578
}
7679
elseif ($value->element === 'asset')
@@ -117,6 +120,7 @@ private function parse_structure($objects)
117120

118121
$this->struct[] = $struct;
119122
}
123+
120124
}
121125

122126
/**

src/PHPDraft/Model/HierarchyElement.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,6 @@ public function get_href()
8484
$seperator = '-';
8585
$prep = ($this->parent !== NULL) ? $this->parent->get_href() . $seperator : '';
8686

87-
return $prep . str_replace(' ', $seperator, strtolower($this->title));
87+
return $prep . str_replace(' ', '__', strtolower($this->title));
8888
}
8989
}

src/PHPDraft/Out/HTML/default.php

+24-21
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class="pull-right <?= $this->get_method_icon($transition->get_method()); ?>"></s
9090
<ul class="list-unstyled">
9191
<?php foreach ($this->base_structures as $key => $structure): ?>
9292
<li>
93-
<a href="#object-<?= str_replace(' ', '_', strtolower($key)); ?>"><?= $key; ?></a>
93+
<a href="#object-<?= $this->strip_link_spaces($key); ?>"><?= $key; ?></a>
9494
</li>
9595
<?php endforeach; ?>
9696
</ul>
@@ -180,9 +180,11 @@ class="value"><?= $value; ?></span>
180180
<?php endif; ?>
181181
<?php if (!empty($transition->request->struct)): ?>
182182
<h5>Structure</h5>
183-
<?php foreach ($transition->request->struct as $value): ?>
184-
<?= $value ?>
185-
<?php endforeach; ?>
183+
<div class="row">
184+
<?php foreach ($transition->request->struct as $value): ?>
185+
<?= $value ?>
186+
<?php endforeach; ?>
187+
</div>
186188
<?php endif; ?>
187189
<?php endif; ?>
188190

@@ -250,7 +252,8 @@ class="value"><?= $value; ?></span>
250252
<?= $key; ?>
251253

252254
</h5>
253-
<pre class="collapse collapsed response-body" id="request-<?= $href ?>"><?= $value; ?></pre>
255+
<pre class="collapse collapsed response-body"
256+
id="request-<?= $href ?>"><?= $value; ?></pre>
254257
</div>
255258
<?php endforeach; ?>
256259
</div>
@@ -262,23 +265,23 @@ class="value"><?= $value; ?></span>
262265
<?php endforeach; ?>
263266
<?php endforeach; ?>
264267
<?php endforeach; ?>
265-
<?php if(count($this->base_structures) > 0):?>
266-
<h2><a id="datastructures">Data structures</a></h2>
267-
<?php foreach ($this->base_structures as $key => $structure): ?>
268-
<div class="panel panel-default object-<?= str_replace(' ', '_', strtolower($key)); ?> structure">
269-
<div class="panel-heading">
270-
<h3 class="panel-title">
271-
<a id="object-<?= str_replace(' ', '_', strtolower($key)); ?>"><?= $key; ?></a>
272-
</h3>
273-
</div>
274-
<div class="panel-body">
275-
<div class="row">
276-
<?= $structure; ?>
268+
<?php if (count($this->base_structures) > 0): ?>
269+
<h2><a id="datastructures">Data structures</a></h2>
270+
<?php foreach ($this->base_structures as $key => $structure): ?>
271+
<div class="panel panel-default object-<?= $this->strip_link_spaces($key); ?> structure">
272+
<div class="panel-heading">
273+
<h3 class="panel-title">
274+
<a id="object-<?= $this->strip_link_spaces($key); ?>"><?= $key; ?></a>
275+
</h3>
276+
</div>
277+
<div class="panel-body">
278+
<div class="row">
279+
<?= $structure; ?>
280+
</div>
277281
</div>
278282
</div>
279-
</div>
280-
<?php endforeach; ?>
281-
<?php endif;?>
283+
<?php endforeach; ?>
284+
<?php endif; ?>
282285
</div>
283286
</div>
284287
</div>
@@ -288,6 +291,6 @@ class="value"><?= $value; ?></span>
288291
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
289292
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
290293
crossorigin="anonymous"></script>
291-
<script><?= Minifier::minify_js( file_get_contents(__DIR__ . '/' . $this->template . '.js')); ?></script>
294+
<script><?= Minifier::minify_js(file_get_contents(__DIR__ . '/' . $this->template . '.js')); ?></script>
292295
</body>
293296
</html>

src/PHPDraft/Out/TemplateGenerator.php

+5
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,9 @@ function get_response_status($response)
170170
}
171171
}
172172

173+
function strip_link_spaces($key)
174+
{
175+
return str_replace(' ', '__', strtolower($key));
176+
}
177+
173178
}

0 commit comments

Comments
 (0)