Skip to content

Commit

Permalink
Add option to select host
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Molenaar authored and Sean Molenaar committed Oct 28, 2016
1 parent 00183d5 commit 24fd9f9
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 11 deletions.
6 changes: 6 additions & 0 deletions src/PHPDraft/Out/HTML/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ body .media h1.media-heading {
margin-top: 20px;
margin-bottom: 10px;
}
body .media h1.media-heading .form-control{
display: flex;
width: auto;
float: right;
}


.panel-title var, h4.response var {
padding: 6px 12px;
Expand Down
13 changes: 13 additions & 0 deletions src/PHPDraft/Out/HTML/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ $(function () {
}
});
});
var selectedhost = $('h1.media-heading select.form-control').val();
$('h1.media-heading select.form-control').on('change', function () {
var html = $('body>div>div.row').html();
var re = new RegExp(escapeRegExp(selectedhost), 'g');
html = html.replace(re, $('h1.media-heading select.form-control').val());
selectedhost = $('h1.media-heading select.form-control').val();
$('body>div>div.row').html(html);
$('[data-toggle="popover"]').popover();
});

function escapeRegExp(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
};
});

$('.collapse.request-panel').on('shown.bs.collapse', function () {
Expand Down
32 changes: 22 additions & 10 deletions src/PHPDraft/Out/HTML/default.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,16 @@ $base = $this->categories;
<div class="media">
<div class="media-body">
<h1 class="media-heading"><?= $this->base_data['TITLE']; ?>
<small><?= $this->base_data['HOST']; ?></small>
<?php if (isset($this->base_data['ALT_HOST'])): ?>
<select class="form-control">
<option selected><?= $this->base_data['HOST']; ?></option>
<?php foreach (explode(',', $this->base_data['ALT_HOST']) as $host): ?>
<option><?= $host; ?></option>
<?php endforeach; ?>
</select>
<?php else: ?>
<small><?= $this->base_data['HOST']; ?></small>
<?php endif; ?>
</h1>
<p class="lead"><?= $this->base_data['DESC']; ?></p>
</div>
Expand Down Expand Up @@ -151,7 +160,7 @@ $base = $this->categories;
</a>
<p class="lead"><?= $transition->description; ?></p>
<?php if (!empty($transition->requests)): ?>
<?php foreach ($transition->requests as $key=>$request): ?>
<?php foreach ($transition->requests as $key => $request): ?>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="request panel-title"
Expand All @@ -162,9 +171,10 @@ $base = $this->categories;
</h4>
</div>

<div class="collapse <?php if ($key<1):?>in<?php endif;?> request-panel panel-body"
id="request-coll-<?= $transition->get_href(); ?>">
<?= $request->description;?>
<div
class="collapse <?php if ($key < 1): ?>in<?php endif; ?> request-panel panel-body"
id="request-coll-<?= $transition->get_href(); ?>">
<?= $request->description; ?>
<?php if ($transition->url_variables !== []): ?>
<h5>Example URI</h5>
<span class="base-url"><?= $this->base_data['HOST']; ?></span>
Expand Down Expand Up @@ -219,7 +229,7 @@ $base = $this->categories;
<?php endforeach; ?>
<?php endif; ?>
<?php if (isset($transition->responses)): ?>
<?php foreach ($transition->responses as $key=>$response): ?>
<?php foreach ($transition->responses as $key => $response): ?>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title response"
Expand All @@ -231,9 +241,10 @@ $base = $this->categories;
class="glyphicon indicator glyphicon-menu-down pull-right"></span>
</h4>
</div>
<div class="panel-body collapse <?php if ($key<1):?>in<?php endif;?> response-panel"
id="request-coll--<?= $transition->get_href() . '-' . $response->statuscode; ?>">
<?=$response->description;?>
<div
class="panel-body collapse <?php if ($key < 1): ?>in<?php endif; ?> response-panel"
id="request-coll--<?= $transition->get_href() . '-' . $response->statuscode; ?>">
<?= $response->description; ?>
<?php if ($response->headers !== []): ?>
<h5>Headers</h5>
<ul class="headers list-unstyled">
Expand Down Expand Up @@ -310,6 +321,7 @@ $base = $this->categories;
<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>-->
<script><?= file_get_contents(__DIR__ . '/' . $this->template . '.js'); ?></script>
</body>
</html>
2 changes: 1 addition & 1 deletion src/PHPDraft/Out/UI.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static function help()
echo "\t-s\tSort displayed values [All|None|Structures|Webservices] (defaults to the way the objects are in the file)\n";
echo "\t-i\tSpecifies an image to display in the header.\n";
echo "\t-c\tSpecifies a CSS file to include (value is put in a link element without checking).\n";
echo "\t-c\tSpecifies a JS file to include (value is put in a script element without checking).\n";
echo "\t-j\tSpecifies a JS file to include (value is put in a script element without checking).\n";
echo "\t-h\tDisplays this text.\n";
}

Expand Down

0 comments on commit 24fd9f9

Please sign in to comment.