Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: Add an attribute "trim" or "join" to "<txp:variable />"
Bloke wrote:
If it’s always going to be 1/0 then maybe a truthy/falsy system isn’t necessary after all. It’s just one thing people may have to learn when using Textpattern that 1 = yes and 0 = no.
Yes. I wasn’t really trying to do any type of dedicated truthy/falsy system, but types. So that the parser itself offers the needed security, casting boolean attributes as booleans, integers as integers and so on. You know, so that the comparisons if/else logic are byte-wise safe and so that you don’t need to explicitly cast/process the values in the tag functions.
But I dunno. As a pseudo like code written in couple seconds;
/**
* Process tag attributes
*/
class TagAttrPrefixes
{
public $prefix;
public $attribute;
public $value;
/**
* Constructor
*/
public function __construct($prefix, $attribute, $value)
{
$this->prefix = $prefix; // prefix could also be split here from the attribute name
$this->attribute = $attribute;
$this->value = $value;
}
/**
* Handles third-party callback functions
*/
public function __call()
{
callback_event_ref('tag.prefix', $this->prefix, $this->attribute, $this->value);
return $this->value;
}
/**
* Handles booleans. Normalizes true, 1, y and yes as TRUE.
*
* @return bool
*/
public function bool()
{
return $this->value === '1' || $this->value === 'true' || $this->value === 'y' || $this->value === 'yes';
}
/**
* Handles integers
*
* @return int
*/
public function int()
{
return (int) $this->value;
}
/**
* Handles a list
*
* @return array
*/
public function ls() {
return do_list($this->value);
}
}
Which then also allows plugins do crazy things as registering json prefix which converts the attributes contents to an object and so forth. But, I dunno.
Last edited by Gocom (2012-07-22 10:47:25)
Offline