Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2012-07-22 08:34:12

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,271
Website GitHub

Re: Add an attribute "trim" or "join" to "<txp:variable />"

ruud wrote:

I suspect the people who don’t understand that, have problems understanding if/else constructs and for that matter the whole concept of TXP tags ;)

Hehe, true. I think my use of “understands” was unduly harsh. What I meant was that some attributes seem to lend themselves to a yes/no response while others make more sense as 1/0. I didn’t realise we’d standardised on 1/0 — good to know, thanks. In which case the docs can be updated to reflect that.

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.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#14 2012-07-22 09:38:59

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: Add an attribute "trim" or "join" to "<txp:variable />"

At the risk of hijacking this thread, I’d rather see the fucking ridiculous ‘form’ attribute also be useable if you used ‘partial’, so both options work – keeps backwards compat and also means we can stop using that terminology. That’s a lot more of a problem than whether a 1 or a y or a yes is a yes.

Rant over.

Offline

#15 2012-07-22 10:20:32

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Add an attribute "trim" or "join" to "<txp:variable />"

philwareham wrote:

I’d rather see the fucking ridiculous ‘form’ attribute also be useable if you used ‘partial’

I kinda do like the form attribute and I want to keep it or have just something else. Adding an alternative syntax is never good. Look at the fucking ridiculous thing called PHP. PHP is trapped in its own inconsistencies, b/c hell and polluted code base.

(PHP is the shittiest language I love and work with).

ruud wrote:

Probably. It’ll affect parsing speed. Not sure by how much. You’d have to benchmark.

Yeah, it unfortunately does. But, well, performance isn’t always the all there is.

At some point we probably should do that one particularly important thing which is a long overdue: a tag registering and use of callbacks instead of the current a tag to a straight PHP function approach. Due to security, extensibility and compatibility. This alone will have an impact (which it shouldn’t in this scale, but Textpattern uses this particularly fun language, PHP).

Last edited by Gocom (2012-07-22 10:20:54)

Offline

#16 2012-07-22 10:44:49

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

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

Board footer

Powered by FluxBB