Skip to content

Commit

Permalink
Improved option handling
Browse files Browse the repository at this point in the history
  • Loading branch information
noccy80 committed Dec 15, 2016
1 parent c50ea02 commit 3223961
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 7 additions & 2 deletions lib/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,27 @@ function config_read() {

function config_write() {
assert(PHPL_CONFIG);
global $_CONFIG;
global $_CONFIG, $_MODULES;

$root = new SdlTag();

$items = $root->createChild("items");
foreach ($_CONFIG['items'] as $item) {
$opts = array_map(function ($opt) { return $opt->name; }, $_MODULES[$item[0]]->opts);
$conf = $items->createChild($item[0]);
$conf->setValue($item[1]);
foreach ($item[2] as $k=>$v) {
$conf->setAttribute($k,$v);
if (in_array($k,$opts)) {
$conf->setAttribute($k,$v);
} else
printf("Warning: No such option %s for %s\n", $k, $item[0]);
}
}

$root->createChild("theme")->setValue($_CONFIG['theme']);

file_put_contents(PHPL_CONFIG, $root->encode());
config_read();
}

function config_item_delete($name) {
Expand Down
6 changes: 4 additions & 2 deletions modules/text.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php

define("TEXT_TEXT", "text");
define("TEXT_CLASS", "class");

function _text(array $opts) {
$attr = [];
if ($opts['class']) $attr['class'] = $opts['class'];
return panel($opts['text'], $attr, 'text');
if ($opts[TEXT_CLASS]) $attr['class'] = $opts[TEXT_CLASS];
return panel($opts[TEXT_TEXT], $attr, 'text');
}
module("text", "Show a text");
option("text", TEXT_TEXT, "string", "The text to dispaly", "Text");
option("class", TEXT_CLASS, "string", "The class to use", "");

0 comments on commit 3223961

Please sign in to comment.