Skip to content

Commit

Permalink
Out: Add material color picker
Browse files Browse the repository at this point in the history
  • Loading branch information
SMillerDev committed Oct 4, 2017
1 parent 6997f05 commit 9f0fef4
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/PHPDraft/Out/HTML/default.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ use Enjoy\HttpStatusCode\Statuscodes;
</div>
</div>
<?php $extras = array_filter($this->base_data, function ($value) {
return !in_array($value, ['HOST', 'TITLE', 'ALT_HOST', 'FORMAT', 'DESC']);
return !in_array($value, ['HOST', 'TITLE', 'ALT_HOST', 'FORMAT', 'DESC', 'COLOR_1', 'COLOR_2']);
}, ARRAY_FILTER_USE_KEY);
if (!empty($extras)):
$extras['host'] = $this->base_data['HOST']; ?>
Expand Down
4 changes: 2 additions & 2 deletions src/PHPDraft/Out/HTML/material.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use Enjoy\HttpStatusCode\Statuscodes;
<title><?= $this->base_data['TITLE']; ?></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.blue_grey-blue.min.css" />
<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.<?= $this->base_data['COLOR_1']?>-<?= $this->base_data['COLOR_2']?>.min.css" />
<script defer src="https://code.getmdl.io/1.3.0/material.min.js"></script>
<script src="https://code.jquery.com/jquery-2.2.4.min.js"
integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
Expand Down Expand Up @@ -237,7 +237,7 @@ use Enjoy\HttpStatusCode\Statuscodes;
</main>
</div>
<?php $extras = array_filter($this->base_data, function ($value) {
return !in_array($value, ['HOST', 'TITLE', 'ALT_HOST', 'FORMAT', 'DESC']);
return !in_array($value, ['HOST', 'TITLE', 'ALT_HOST', 'FORMAT', 'DESC', 'COLOR_1', 'COLOR_2']);
}, ARRAY_FILTER_USE_KEY);
if (!empty($extras)):
$extras['host'] = $this->base_data['HOST']; ?>
Expand Down
9 changes: 6 additions & 3 deletions src/PHPDraft/Out/TemplateGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,12 @@ class TemplateGenerator
*/
public function __construct($template, $image)
{
$this->template = $template;
$this->image = $image;
$this->http_status = new Httpstatus();
$template_parts = explode('__', $template);
$this->template = $template_parts[0];
$this->base_data['COLOR_1'] = isset($template_parts[1]) ? $template_parts[1] : 'green';
$this->base_data['COLOR_2'] = isset($template_parts[2]) ? $template_parts[2] : 'light_green';
$this->image = $image;
$this->http_status = new Httpstatus();
}

/**
Expand Down
32 changes: 27 additions & 5 deletions src/PHPDraft/Out/UI.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,19 @@ public static function main($argv = [])
define('DRAFTER_ONLINE_MODE', 1);
}

$template = (isset($options['t']) && $options['t']) ? $options['t'] : 'default';
$image = (isset($options['i']) && $options['i']) ? $options['i'] : NULL;
$css = (isset($options['c']) && $options['c']) ? $options['i'] : NULL;
$js = (isset($options['j']) && $options['j']) ? $options['i'] : NULL;
$template = (new self())->var_or_default($options['t'], 'default');
$image = (new self())->var_or_default($options['i']);
$css = (new self())->var_or_default($options['c']);
$js = (new self())->var_or_default($options['j']);
$color1 = getenv('COLOR_PRIMARY') === FALSE ? NULL : getenv('COLOR_PRIMARY');
$color1 = (new self())->var_or_default($color1);
$color2 = getenv('COLOR_SECONDARY') === FALSE ? NULL : getenv('COLOR_SECONDARY');
$color2 = (new self())->var_or_default($color2);
$colors = (is_null($color1) || is_null($color2)) ? '' : '__' . $color1 . '__' . $color2;

return [
'file' => $file,
'template' => $template,
'template' => $template . $colors,
'image' => $image,
'css' => $css,
'js' => $js,
Expand All @@ -119,6 +124,23 @@ public function help()
echo "\t-h\tDisplays this text." . PHP_EOL;
}

/**
* Check if a variable exists, otherwise return a default.
*
* @param mixed $var
* @param mixed $default
*
* @return mixed
*/
private function var_or_default(&$var, $default = NULL)
{
if (!isset($var) || is_null($var)) {
return $default;
}

return $var;
}

/**
* Return the version.
*
Expand Down
2 changes: 1 addition & 1 deletion tests/statics/drafter/html_material
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title>Tesla Model S JSON API</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.blue_grey-blue.min.css" />
<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.green-light_green.min.css" />
<script defer src="https://code.getmdl.io/1.3.0/material.min.js"></script>
<script src="https://code.jquery.com/jquery-2.2.4.min.js"
integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
Expand Down

0 comments on commit 9f0fef4

Please sign in to comment.