Skip to content

Commit

Permalink
This should fix #14
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 bfcceb3 commit 61e1dec
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 24 deletions.
5 changes: 3 additions & 2 deletions src/PHPDraft/Model/Elements/DataStructureElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ function __toString()
if (is_string($object)
|| get_class($object) === self::class
|| get_class($object) === ArrayStructureElement::class
|| get_class($object) === RequestBodyElement::class
|| get_class($object) === EnumStructureElement::class
)
{
Expand All @@ -171,15 +172,15 @@ 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 (is_null($this->value))
{
$value = '';
}
else
{
if (is_object($this->value) && self::class === get_class($this->value))
if (is_object($this->value) && (self::class === get_class($this->value) || RequestBodyElement::class === get_class($this->value)))
{
$value = '<div class="sub-struct">' . $this->value . '</div>';
}
Expand Down
4 changes: 4 additions & 0 deletions src/PHPDraft/Model/HTTPRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ public function parse($object)
if ($value->element === 'dataStructure')
{
$this->parse_structure($value->content);
echo '<pre>';
var_dump($this->struct);
echo '</pre>';
continue;
}
elseif ($value->element === 'asset')
Expand Down Expand Up @@ -117,6 +120,7 @@ private function parse_structure($objects)

$this->struct[] = $struct;
}

}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/PHPDraft/Model/HierarchyElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@ public function get_href()
$seperator = '-';
$prep = ($this->parent !== NULL) ? $this->parent->get_href() . $seperator : '';

return $prep . str_replace(' ', $seperator, strtolower($this->title));
return $prep . str_replace(' ', '__', strtolower($this->title));
}
}
45 changes: 24 additions & 21 deletions src/PHPDraft/Out/HTML/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,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(' ', '_', strtolower($key)); ?>"><?= $key; ?></a>
<a href="#object-<?= $this->strip_link_spaces($key); ?>"><?= $key; ?></a>
</li>
<?php endforeach; ?>
</ul>
Expand Down Expand Up @@ -180,9 +180,11 @@ class="value"><?= $value; ?></span>
<?php endif; ?>
<?php if (!empty($transition->request->struct)): ?>
<h5>Structure</h5>
<?php foreach ($transition->request->struct as $value): ?>
<?= $value ?>
<?php endforeach; ?>
<div class="row">
<?php foreach ($transition->request->struct as $value): ?>
<?= $value ?>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php endif; ?>

Expand Down Expand Up @@ -250,7 +252,8 @@ 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 @@ -262,23 +265,23 @@ class="value"><?= $value; ?></span>
<?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-heading">
<h3 class="panel-title">
<a id="object-<?= str_replace(' ', '_', strtolower($key)); ?>"><?= $key; ?></a>
</h3>
</div>
<div class="panel-body">
<div class="row">
<?= $structure; ?>
<?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-<?= $this->strip_link_spaces($key); ?> structure">
<div class="panel-heading">
<h3 class="panel-title">
<a id="object-<?= $this->strip_link_spaces($key); ?>"><?= $key; ?></a>
</h3>
</div>
<div class="panel-body">
<div class="row">
<?= $structure; ?>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
<?php endif;?>
<?php endforeach; ?>
<?php endif; ?>
</div>
</div>
</div>
Expand All @@ -288,6 +291,6 @@ class="value"><?= $value; ?></span>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
crossorigin="anonymous"></script>
<script><?= Minifier::minify_js( file_get_contents(__DIR__ . '/' . $this->template . '.js')); ?></script>
<script><?= Minifier::minify_js(file_get_contents(__DIR__ . '/' . $this->template . '.js')); ?></script>
</body>
</html>
5 changes: 5 additions & 0 deletions src/PHPDraft/Out/TemplateGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,9 @@ function get_response_status($response)
}
}

function strip_link_spaces($key)
{
return str_replace(' ', '__', strtolower($key));
}

}

0 comments on commit 61e1dec

Please sign in to comment.