Skip to content

Commit eb41fcb

Browse files
committed
Themes: Add experimental material theme
1 parent 3ad9d47 commit eb41fcb

File tree

7 files changed

+336
-14
lines changed

7 files changed

+336
-14
lines changed

src/PHPDraft/Model/Elements/ObjectStructureElement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ function __toString()
214214

215215
if (is_array($this->value))
216216
{
217-
$return = '<table class="table table-striped">';
217+
$return = '<table class="table table-striped mdl-data-table mdl-js-data-table ">';
218218
foreach ($this->value as $object) {
219219
if (is_string($object)
220220
|| in_array(get_class($object), [

src/PHPDraft/Out/HTML/default.phtml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66
* @author Sean Molenaar<[email protected]>
77
*/
88
use PHPDraft\Out\Minifier;
9-
10-
/**
11-
* @var \PHPDraft\Model\HierarchyElement[]
12-
*/
13-
$base = $this->categories;
149
?>
1510
<!DOCTYPE html>
1611
<html lang="en">
@@ -54,7 +49,7 @@ $base = $this->categories;
5449
</div>
5550
<div class="row">
5651
<div class="col-md-2 method-nav">
57-
<?php foreach ($base as $category): ?>
52+
<?php foreach ($this->categories as $category): ?>
5853
<?php if ($category->children !== []): ?>
5954
<div class="panel panel-default">
6055
<div class="panel-heading">
@@ -121,7 +116,7 @@ $base = $this->categories;
121116
<div class="main-url"><?= $this->base_data['HOST']; ?></div>
122117
</div>
123118
<div class="col-md-10">
124-
<?php foreach ($base as $category): ?>
119+
<?php foreach ($this->categories as $category): ?>
125120
<?php if (!empty($category->title)): ?>
126121
<h2><a id="<?= $category->get_href(); ?>"><?= $category->title; ?></a></h2>
127122
<?php endif; ?>

src/PHPDraft/Out/HTML/material.css

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
.demo-layout-transparent {
2+
background: rgba(0,0,0,0) center / cover;
3+
}
4+
.demo-layout-transparent .mdl-layout__header,
5+
.demo-layout-transparent .mdl-layout__drawer-button {
6+
/* This background is dark, so we set text to white. Use 87% black instead if
7+
your background is light. */
8+
color: white;
9+
}
10+
main {
11+
width: 100%;
12+
}
13+
14+
.demo-card-wide.mdl-card {
15+
width: 100%;
16+
margin-bottom: 30px;
17+
}
18+
.demo-card-wide > .mdl-card__title {
19+
color: #fff;
20+
height: 176px;
21+
background: #cccccc center / cover;
22+
}
23+
.demo-card-wide > .mdl-card__menu {
24+
color: #fff;
25+
}
26+
h2.mdl-card__title-text {
27+
display: inline-block;
28+
width: 100%;
29+
}
30+
.page-content {
31+
width: 80%;
32+
margin: 0px auto;
33+
}
34+
.pull-right {
35+
text-align: right !important;
36+
float: right !important;
37+
}
38+
39+
.text-success {
40+
color: #3c763d;
41+
}
42+
43+
.text-warning {
44+
color: #8a6d3b;
45+
}
46+
47+
.text-error {
48+
color: #761c19;
49+
}
50+
51+
table.table p {
52+
margin-bottom: 0px;
53+
}

src/PHPDraft/Out/HTML/material.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/**
2+
* Created by smillernl on 18-5-17.
3+
*/

src/PHPDraft/Out/HTML/material.phtml

Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
1+
<?php
2+
/**
3+
* This file contains the material template
4+
*
5+
* @package PHPDraft\HTML
6+
* @author Sean Molenaar<[email protected]>
7+
*/
8+
use PHPDraft\Out\Minifier;
9+
?>
10+
<!DOCTYPE html>
11+
<html lang="en">
12+
<head>
13+
<title><?= $this->base_data['TITLE']; ?></title>
14+
<meta name="viewport" content="width=device-width, initial-scale=1">
15+
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
16+
<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css">
17+
<script defer src="https://code.getmdl.io/1.3.0/material.min.js"></script>
18+
<?php foreach ($this->css as $style): ?>
19+
<link rel="stylesheet" href="<?= $style ?>">
20+
<?php endforeach; ?>
21+
<style>
22+
<?= Minifier::minify_css(file_get_contents($this->find_include_file($this->template, 'css'), true));?>
23+
</style>
24+
</head>
25+
<body>
26+
<div class="demo-layout-waterfall mdl-layout mdl-js-layout">
27+
<header class="mdl-layout__header mdl-layout__header--waterfall">
28+
<div class="mdl-layout__header-row">
29+
<!-- Title -->
30+
<span class="mdl-layout-title"><?= $this->base_data['TITLE']; ?></span>
31+
<div class="mdl-layout-spacer"></div>
32+
<div class="mdl-textfield mdl-js-textfield mdl-textfield--expandable
33+
mdl-textfield--floating-label mdl-textfield--align-right">
34+
<label class="mdl-button mdl-js-button mdl-button--icon"
35+
for="waterfall-exp">
36+
<i class="material-icons">search</i>
37+
</label>
38+
<div class="mdl-textfield__expandable-holder">
39+
<input class="mdl-textfield__input" type="text" name="sample"
40+
id="waterfall-exp">
41+
</div>
42+
</div>
43+
</div>
44+
</header>
45+
<div class="mdl-layout__drawer">
46+
<span class="mdl-layout-title"><?= $this->base_data['TITLE']; ?></span>
47+
<nav class="mdl-navigation">
48+
<a class="mdl-navigation__link" href="#"><b>Webservices</b></a>
49+
<?php foreach ($this->categories as $category): ?>
50+
<a class="mdl-navigation__link" href="#<?= $category->get_href(); ?>"><?= $category->title; ?></a>
51+
<?php if ($category->children !== []): ?>
52+
<?php foreach ($category->children as $resource): ?>
53+
<a class="mdl-navigation__link" href="#<?= str_replace('-', '/', $resource->get_href()); ?>">
54+
- <?= $resource->title; ?>
55+
</a>
56+
<?php foreach ($resource->children as $transition): ?>
57+
<a class="mdl-navigation__link" href="#<?= str_replace('-', '/', $transition->get_href()); ?>">
58+
-- <?= $transition->title; ?>
59+
<span class="pull-right <?= $this->get_method_icon($transition->get_method()); ?>"></span>
60+
</a>
61+
<?php endforeach; ?>
62+
<?php endforeach; ?>
63+
<?php endif; ?>
64+
<?php endforeach; ?>
65+
<?php if (!empty($this->base_structures)): ?>
66+
<a class="mdl-navigation__link" href="#"><b>Objects</b></a>
67+
<?php foreach ($this->base_structures as $key => $structure): ?>
68+
<a class="mdl-navigation__link" href="#<?= $this->strip_link_spaces($key); ?>"><?= $key; ?></a>
69+
<?php endforeach; ?>
70+
<?php endif; ?>
71+
</nav>
72+
</div>
73+
<main class="mdl-layout__content">
74+
<div class="page-content">
75+
<?php foreach ($this->categories as $category): ?>
76+
<?php if (!empty($category->title)): ?>
77+
<h3><a id="<?= $category->get_href(); ?>"><?= $category->title; ?></a></h3>
78+
<?php endif; ?>
79+
<?php if (!empty($category->description)): ?>
80+
<p><?= $category->description; ?></p>
81+
<?php endif; ?>
82+
<?php foreach ($category->children as $resource): ?>
83+
<h4>
84+
<a id="<?= str_replace('-', '/', $resource->get_href()); ?>"><?= $resource->title; ?></a>
85+
<small><?= $resource->href; ?></small>
86+
</h4>
87+
<p><?php $resource->description; ?></p>
88+
<?php foreach ($resource->children as $transition): ?>
89+
<div class="demo-card-wide mdl-card mdl-shadow--2dp <?= $transition->get_method(); ?>">
90+
<div class="mdl-card__title">
91+
<h2 class="mdl-card__title-text"><var><?= $transition->get_method(); ?></var>
92+
<code><?= $transition->href; ?></code>
93+
<a class="pull-right transition-title"
94+
id="<?= str_replace('-', '/',
95+
$transition->get_href()); ?>"><?= $transition->title; ?></a></h2>
96+
</div>
97+
<div class="mdl-card__supporting-text">
98+
<?= $transition->description; ?>
99+
<?php if (!empty($transition->requests) || !empty($transition->responses)): ?>
100+
<div class="mdl-tabs mdl-js-tabs mdl-js-ripple-effect">
101+
<div class="mdl-tabs__tab-bar">
102+
<?php if (!empty($transition->requests)): ?>
103+
<a href="#<?= $transition->get_href(); ?>-request-panel" class="mdl-tabs__tab is-active">Request</a>
104+
<?php endif;?>
105+
<?php if (!empty($transition->responses)): ?>
106+
<?php foreach ($transition->responses as $key => $response): ?>
107+
<a href="#<?= $transition->get_href() . '-' . $response->statuscode; ?>-panel"
108+
class="mdl-tabs__tab <?= $this->get_response_status($response->statuscode) ?>"><?= $response->statuscode; ?></a>
109+
<?php endforeach;?>
110+
<?php endif;?>
111+
</div>
112+
<?php if (!empty($transition->requests)): ?>
113+
<?php foreach ($transition->requests as $key => $request): ?>
114+
<div class="mdl-tabs__panel is-active" id="<?= $transition->get_href(); ?>-request-panel">
115+
<?= $request->description; ?>
116+
<?php if ($transition->url_variables !== []): ?>
117+
<h5>Example URI</h5>
118+
<span class="base-url"><?= $this->base_data['HOST']; ?></span><em><?= $transition->build_url(); ?></em>
119+
<?php endif; ?>
120+
<?php if ($request->headers !== []): ?>
121+
<h5>Headers</h5>
122+
<ul class="headers mdl-list">
123+
<?php foreach ($request->headers as $name => $value): ?>
124+
<li class="mdl-list__item">
125+
<code>
126+
<span class="attr"><?= $name; ?></span>: <span class="value"><?= $value; ?></span>
127+
</code>
128+
</li>
129+
<?php endforeach; ?>
130+
</ul>
131+
<?php endif; ?>
132+
<?php if (!empty($request->body)): ?>
133+
<h5>Body</h5>
134+
<?php foreach ($request->body as $value): ?>
135+
<?php if (is_string($value)): ?>
136+
<code class="request-body"><?= $value; ?></code>
137+
<?php else: ?>
138+
<?php $type = (isset($request->headers['Content-Type'])) ? $request->headers['Content-Type'] : null; ?>
139+
<?= $value->print_request($type); ?>
140+
<?= $value ?>
141+
<?php endif; ?>
142+
<?php endforeach; ?>
143+
<?php endif; ?>
144+
<?php if (!empty($request->struct)): ?>
145+
<h5>Structure</h5>
146+
<?= $request->struct ?>
147+
<?php endif; ?>
148+
<?php if ($transition->url_variables !== null): ?>
149+
<h5>URI Parameters</h5>
150+
<?= $transition->url_variables; ?>
151+
<?php endif; ?>
152+
<?php if ($transition->data_variables !== null): ?>
153+
<h5>Data object</h5>
154+
<?= $transition->data_variables ?>
155+
<?php endif; ?>
156+
</div>
157+
<?php endforeach; ?>
158+
<?php endif; ?>
159+
<?php if (!empty($transition->responses)): ?>
160+
<?php foreach ($transition->responses as $key => $response): ?>
161+
<div class="mdl-tabs__panel" id="<?= $transition->get_href() . '-' . $response->statuscode; ?>-panel">
162+
<?= $response->description; ?>
163+
<?php if ($response->headers !== []): ?>
164+
<h5>Headers</h5>
165+
<ul class="headers mdl-list">
166+
<?php foreach ($response->headers as $name => $value): ?>
167+
<li class="mdl-list__item">
168+
<code>
169+
<span class="attr"><?= $name; ?></span>: <span class="value"><?= $value; ?></span>
170+
</code>
171+
</li>
172+
<?php endforeach; ?>
173+
</ul>
174+
<?php endif; ?>
175+
<?php if ($response->structure !== []): ?>
176+
<h5>Data Structure</h5>
177+
<div class="row">
178+
<?php foreach ($response->structure as $value): ?>
179+
<?= $value; ?>
180+
<?php endforeach; ?>
181+
</div>
182+
<?php endif; ?>
183+
<?php foreach ($response->content as $key => $value): ?>
184+
<div>
185+
<?php $href =
186+
$transition->get_href() . '-' . $response->statuscode . '-' . str_replace([
187+
'/',
188+
'+',
189+
], '-', $key); ?>
190+
<h5 class="response-body"
191+
data-toggle="collapse"
192+
data-target="#request-<?= $href ?>">
193+
<span class="glyphicon indicator glyphicon-menu-up"></span>
194+
<?= $key; ?>
195+
196+
</h5>
197+
<pre class="collapse collapsed response-body"
198+
id="request-<?= $href ?>"><?= $value; ?></pre>
199+
</div>
200+
<?php endforeach; ?>
201+
</div>
202+
</div>
203+
<?php endforeach; ?>
204+
<?php endif; ?>
205+
<?php endif;?>
206+
</div>
207+
<div class="mdl-card__menu">
208+
<button id="<?=$transition->get_href();?>" class="mdl-button mdl-button--icon mdl-js-button mdl-js-ripple-effect">
209+
<i class="material-icons">bug_report</i>
210+
</button>
211+
<div class="mdl-tooltip" for="<?=$transition->get_href();?>">
212+
<?= $transition->get_curl_command($this->base_data['HOST'], []); ?>
213+
</div>
214+
</div>
215+
</div>
216+
<?php endforeach;?>
217+
<?php endforeach;?>
218+
<?php endforeach;?>
219+
<?php if (count($this->base_structures) > 0): ?>
220+
<h3><a id="datastructures">Data structures</a></h3>
221+
<?php foreach ($this->base_structures as $key => $structure): ?>
222+
<div class="demo-card-wide mdl-card mdl-shadow--2dp">
223+
<div class="mdl-card__title">
224+
<h2 class="mdl-card__title-text"><a id="object-<?= $this->strip_link_spaces($key); ?>"><?= $key; ?></a></h2>
225+
</div>
226+
<div class="mdl-card__supporting-text">
227+
<?= $structure; ?>
228+
</div>
229+
</div>
230+
<?php endforeach; ?>
231+
<?php endif; ?>
232+
</div>
233+
</main>
234+
</div>
235+
<?php $extras = array_filter($this->base_data, function ($value) {
236+
return !in_array($value, ['HOST', 'TITLE', 'ALT_HOST', 'FORMAT', 'DESC']);
237+
}, ARRAY_FILTER_USE_KEY);
238+
if (!empty($extras)):
239+
$extras['host'] = $this->base_data['HOST']; ?>
240+
<button
241+
type="button"
242+
class="mdl-button mdl-js-button mdl-button--fab mdl-js-ripple-effect mdl-button--colored"
243+
data-toggle="popover"
244+
title="Extra info"
245+
data-placement="top"
246+
data-html="true"
247+
data-content="<?php foreach ($extras as $key => $value): ?><p><?= $key; ?>: <?= $value; ?></p><?php endforeach; ?>">
248+
<i class="material-icons">help outline</i>
249+
</button>
250+
<?php endif; ?>
251+
<?php foreach ($this->js as $js): ?>
252+
<script src="<?= $js ?>"></script>
253+
<?php endforeach; ?>
254+
<script src="https://code.jquery.com/jquery-2.2.4.min.js"
255+
integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
256+
crossorigin="anonymous"></script>
257+
<script><?= Minifier::minify_js(file_get_contents($this->find_include_file($this->template, 'js'), true)); ?></script>
258+
</body>
259+
</html>

0 commit comments

Comments
 (0)