Skip to content

Commit faf970e

Browse files
authored
Merge pull request #44 from SMillerDev/material/colors
Out: Add material color picker
2 parents 6997f05 + 9f0fef4 commit faf970e

File tree

5 files changed

+37
-12
lines changed

5 files changed

+37
-12
lines changed

src/PHPDraft/Out/HTML/default.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ use Enjoy\HttpStatusCode\Statuscodes;
312312
</div>
313313
</div>
314314
<?php $extras = array_filter($this->base_data, function ($value) {
315-
return !in_array($value, ['HOST', 'TITLE', 'ALT_HOST', 'FORMAT', 'DESC']);
315+
return !in_array($value, ['HOST', 'TITLE', 'ALT_HOST', 'FORMAT', 'DESC', 'COLOR_1', 'COLOR_2']);
316316
}, ARRAY_FILTER_USE_KEY);
317317
if (!empty($extras)):
318318
$extras['host'] = $this->base_data['HOST']; ?>

src/PHPDraft/Out/HTML/material.phtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use Enjoy\HttpStatusCode\Statuscodes;
1414
<title><?= $this->base_data['TITLE']; ?></title>
1515
<meta name="viewport" content="width=device-width, initial-scale=1">
1616
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
17-
<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.blue_grey-blue.min.css" />
17+
<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.<?= $this->base_data['COLOR_1']?>-<?= $this->base_data['COLOR_2']?>.min.css" />
1818
<script defer src="https://code.getmdl.io/1.3.0/material.min.js"></script>
1919
<script src="https://code.jquery.com/jquery-2.2.4.min.js"
2020
integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
@@ -237,7 +237,7 @@ use Enjoy\HttpStatusCode\Statuscodes;
237237
</main>
238238
</div>
239239
<?php $extras = array_filter($this->base_data, function ($value) {
240-
return !in_array($value, ['HOST', 'TITLE', 'ALT_HOST', 'FORMAT', 'DESC']);
240+
return !in_array($value, ['HOST', 'TITLE', 'ALT_HOST', 'FORMAT', 'DESC', 'COLOR_1', 'COLOR_2']);
241241
}, ARRAY_FILTER_USE_KEY);
242242
if (!empty($extras)):
243243
$extras['host'] = $this->base_data['HOST']; ?>

src/PHPDraft/Out/TemplateGenerator.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,12 @@ class TemplateGenerator
7979
*/
8080
public function __construct($template, $image)
8181
{
82-
$this->template = $template;
83-
$this->image = $image;
84-
$this->http_status = new Httpstatus();
82+
$template_parts = explode('__', $template);
83+
$this->template = $template_parts[0];
84+
$this->base_data['COLOR_1'] = isset($template_parts[1]) ? $template_parts[1] : 'green';
85+
$this->base_data['COLOR_2'] = isset($template_parts[2]) ? $template_parts[2] : 'light_green';
86+
$this->image = $image;
87+
$this->http_status = new Httpstatus();
8588
}
8689

8790
/**

src/PHPDraft/Out/UI.php

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,19 @@ public static function main($argv = [])
8686
define('DRAFTER_ONLINE_MODE', 1);
8787
}
8888

89-
$template = (isset($options['t']) && $options['t']) ? $options['t'] : 'default';
90-
$image = (isset($options['i']) && $options['i']) ? $options['i'] : NULL;
91-
$css = (isset($options['c']) && $options['c']) ? $options['i'] : NULL;
92-
$js = (isset($options['j']) && $options['j']) ? $options['i'] : NULL;
89+
$template = (new self())->var_or_default($options['t'], 'default');
90+
$image = (new self())->var_or_default($options['i']);
91+
$css = (new self())->var_or_default($options['c']);
92+
$js = (new self())->var_or_default($options['j']);
93+
$color1 = getenv('COLOR_PRIMARY') === FALSE ? NULL : getenv('COLOR_PRIMARY');
94+
$color1 = (new self())->var_or_default($color1);
95+
$color2 = getenv('COLOR_SECONDARY') === FALSE ? NULL : getenv('COLOR_SECONDARY');
96+
$color2 = (new self())->var_or_default($color2);
97+
$colors = (is_null($color1) || is_null($color2)) ? '' : '__' . $color1 . '__' . $color2;
9398

9499
return [
95100
'file' => $file,
96-
'template' => $template,
101+
'template' => $template . $colors,
97102
'image' => $image,
98103
'css' => $css,
99104
'js' => $js,
@@ -119,6 +124,23 @@ public function help()
119124
echo "\t-h\tDisplays this text." . PHP_EOL;
120125
}
121126

127+
/**
128+
* Check if a variable exists, otherwise return a default.
129+
*
130+
* @param mixed $var
131+
* @param mixed $default
132+
*
133+
* @return mixed
134+
*/
135+
private function var_or_default(&$var, $default = NULL)
136+
{
137+
if (!isset($var) || is_null($var)) {
138+
return $default;
139+
}
140+
141+
return $var;
142+
}
143+
122144
/**
123145
* Return the version.
124146
*

tests/statics/drafter/html_material

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<title>Tesla Model S JSON API</title>
55
<meta name="viewport" content="width=device-width, initial-scale=1">
66
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
7-
<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.blue_grey-blue.min.css" />
7+
<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.green-light_green.min.css" />
88
<script defer src="https://code.getmdl.io/1.3.0/material.min.js"></script>
99
<script src="https://code.jquery.com/jquery-2.2.4.min.js"
1010
integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="

0 commit comments

Comments
 (0)