Got questions, comments, patches, etc.?
Contact Jason Woofenden
gitweb
/
wfpl.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
added tem_auto_nonempty()
[wfpl.git]
/
template.php
diff --git
a/template.php
b/template.php
index
3845c7c
..
396819d
100644
(file)
--- a/
template.php
+++ b/
template.php
@@
-53,7
+53,7
@@
function template_file($filename, $data) {
return fill_template(parse_template_file($filename), $data);
}
return fill_template(parse_template_file($filename), $data);
}
-function parse_template_file($filename) {
+function &parse_template_file($filename) {
return parse_template(file_get_contents($filename));
}
return parse_template(file_get_contents($filename));
}
@@
-61,7
+61,7
@@
function parse_template_file($filename) {
# A template is a hash with a name string, a pieces array, and possibly
# an args array.
# A template is a hash with a name string, a pieces array, and possibly
# an args array.
-function parse_template($string) {
+function &parse_template($string) {
$tem =& tem_push();
$tem['pieces'] = array();
$matches = preg_split('/(<!--)?(~[^~]*~)(?(1)-->)/', preg_replace('/<!--(~[^~]*~)-->/', '$1', $string), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
$tem =& tem_push();
$tem['pieces'] = array();
$matches = preg_split('/(<!--)?(~[^~]*~)(?(1)-->)/', preg_replace('/<!--(~[^~]*~)-->/', '$1', $string), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
@@
-163,7
+163,7
@@
function tem_data_as_rows($value) {
if(array_key_exists(0, $value)) return $value;
# key/value pairs -- expand sub-template once.
else return array($value);
if(array_key_exists(0, $value)) return $value;
# key/value pairs -- expand sub-template once.
else return array($value);
- } elseif($value) {
+ } elseif($value || $value === 0 || $value === '0' || $value === '') {
# value -- expand sub-template once using only parent values
return array(array());
} else {
# value -- expand sub-template once using only parent values
return array(array());
} else {
@@
-317,11
+317,19
@@
function tem_auto_first(&$value, $key, $context) {
return $value = true; # show once
}
return $value = true; # show once
}
-# 'show' sections will be shown unless the corresponding data value
-# is false (only false, not 0 or '' or array()).
+# 'show' sections will be shown unless the corresponding data
+# value === false
function tem_auto_show(&$value) {
function tem_auto_show(&$value) {
- if($value !== false) $value = array(array());
+ if($value === null) $value = array(array());
+ return $value;
+}
+
+# 'nonempty' sections will not be shown if the corresponding data
+# value is the empty string
+
+function tem_auto_nonempty(&$value) {
+ if($value === '') $value = null;
return $value;
}
return $value;
}
@@
-424,11
+432,11
@@
class tem {
}
function load_str($str) {
}
function load_str($str) {
- $this->template = parse_template($str);
+ $this->template =& parse_template($str);
}
function load($filename) {
}
function load($filename) {
- $this->template = parse_template_file($filename);
+ $this->template =& parse_template_file($filename);
}
function run($tem = false) {
}
function run($tem = false) {