Textpattern CMS support forum

You are not logged in. Register | Login | Help

#41 2017-12-18 16:52:45

etc
Developer
Registered: 2010-11-11
Posts: 3,203
Website

Re: Poll: useful 'escape' transforms

Bloke wrote #308329:

If there’s the possiblity of interplay between transforms, we could certainly use that to our advantage … tidy is a good name, though. It’s generic enough that we could apply it to ‘prepare’ other transforms in future or it could just tidy spaces up if used on its own.

Agreed. Now tidy tidies spaces and modifies the action of number, integer and textile:

<txp:variable name="amount" value="Price: £1 234.78" />
<txp:variable name="amount" escape="tidy, number" />

Outputs 1234.78 (and 0 without tidy).

<txp:variable name="test" value="*This* is a _test_" />
<txp:variable name="test" escape="tidy, textile" />

Outputs <strong>This</strong> is a <em>test</em> (wrapped in <p /> without tidy).


etc_[ query | search | pagination | date | tree | cache ]

Offline

#42 2017-12-18 16:54:27

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,678
Website

Re: Poll: useful 'escape' transforms

Looks like tidy is the winner which is great as it means it’s also been applied as follows:

  • escape="tidy": remove spaces/newlines from the content.
  • escape="number": format the content as a number.
  • escape="tidy, number": remove spaces/newlines and format the content as a stricter number (force to float or fraction first).
  • escape="integer": format the content as an int.
  • escape="tidy, integer": remove spaces/newlines and format the content as a stricter int: ensure it adheres to an integer first.
  • escape="textile": Textile the content.
  • escape="tidy, textile": remove spaces/newlines, prepend a single space to remove the surrounding ‘p’ tag, then Textile the content.
  • escape="some-tag": strip any self-closing <some-tag />, or unwrap any container <some-tag>...</some-tag> in the content.
  • escape="tidy, some-tag": remove spaces/newlines, escape any regex characters, then strip any self-closing <some-tag />, or unwrap any container <some-tag>...</some-tag> in the content.

Winner!

EDIT: And what Oleg said above :-)

Last edited by Bloke (2017-12-18 17:01:02)


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

#43 2017-12-18 17:07:42

etc
Developer
Registered: 2010-11-11
Posts: 3,203
Website

Re: Poll: useful 'escape' transforms

Bloke wrote #308332:

Looks like tidy is the winner which is great

Thanks, have fun! :-)

  • escape="tidy, number": remove spaces and format the content as a stricter number (force to float, fraction, or scientific first).
  • escape="tidy, some-tag": remove spaces, escape any regex characters, then strip any self-closing <some-tag />, or unwrap any container <some-tag>...</some-tag> in the content.

I have removed scientific, it converts Price: £1 234.78 to a meaningless e1234.78, sorry.

If you need regex characters, e.g. \w+ to unwrap all top-level tags first, then you can tidy after it: escape="\w+, tidy".


etc_[ query | search | pagination | date | tree | cache ]

Offline

#44 2017-12-18 17:11:53

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,678
Website

Re: Poll: useful 'escape' transforms

etc wrote #308333:

I have removed scientific

Yep, I edited my post after I saw your following commit… but not quick enough!

If you need regex characters, e.g. \w+ to unwrap all top-level tags first, then you can tidy after it: escape="\w+, tidy".

Great tip. This escape feature is a fabulous addition to Txp’s processing arsenal.


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

#45 2017-12-18 17:43:47

philwareham
Core designer
From: Farnham, Surrey, UK
Registered: 2009-06-11
Posts: 3,196
Website

Re: Poll: useful 'escape' transforms

As per txp:evaluate this will need thorough documentation. I have no idea what it this right now but I’m sure it’ll be good when I do know. Cheers!

Offline

#46 2017-12-18 22:45:30

etc
Developer
Registered: 2010-11-11
Posts: 3,203
Website

Re: Poll: useful 'escape' transforms

philwareham wrote #308335:

As per txp:evaluate this will need thorough documentation. I have no idea what it this right now but I’m sure it’ll be good when I do know.

Hi Phil! I’m slowly documenting what I can, but find it waaay harder than coding or answering questions. Stef has nicely outlined the escape usage (see also these examples), the fastest way would be to compile them and extend later. But I’m not sure where should this go: tags cross-reference? A separate topic?


etc_[ query | search | pagination | date | tree | cache ]

Offline

#47 2017-12-19 06:52:07

Dragondz
Moderator
From: Algérie
Registered: 2005-06-12
Posts: 1,314
Website

Re: Poll: useful 'escape' transforms

Great job guys, that will open great possibilities for outputting things without a lot of txp:php.

Offline

#48 2017-12-19 08:56:56

philwareham
Core designer
From: Farnham, Surrey, UK
Registered: 2009-06-11
Posts: 3,196
Website

Re: Poll: useful 'escape' transforms

etc wrote #308336:

…but find it waaay harder than coding or answering questions.

You’re doing great with the documentation additions. I just step in and do some minimal editorial work on your text and it’s looking ace. Thanks, I know documentation isn’t easy.

Stef has nicely outlined the escape usage (see also these examples), the fastest way would be to compile them and extend later. But I’m not sure where should this go: tags cross-reference? A separate topic?

Hmmm, I’ll think about it. It’d probably be wise to have a section at the top of tag attribute cross-reference to list all the global attributes first (just checking: these attributes can be used on any tag, yes?). I’d also be keen to have the global attributes at least mentioned on the attributes section of tag docs (not necessarily listed, but mentioned). It may even be good to have another page on tag basics explaining global attributes too (as I assume this list of globals will only get bigger in future releases). Same for escape – it probably merits another page on tag basics and mentions on tag doc pages.

Offline

#49 2017-12-19 12:11:02

etc
Developer
Registered: 2010-11-11
Posts: 3,203
Website

Re: Poll: useful 'escape' transforms

philwareham wrote #308339:

just checking: these (global) attributes can be used on any tag, yes?

Almost: they are recognized by all tags, but their action can be different if the tag implements its own attribute processing. But most core tags are aligned, save for <txp:author /> etc where, say, escape="number" is of little use.

I’d also be keen to have the global attributes at least mentioned on the attributes section of tag docs (not necessarily listed, but mentioned). It may even be good to have another page on tag basics explaining global attributes too (as I assume this list of globals will only get bigger in future releases). Same for escape – it probably merits another page on tag basics and mentions on tag doc pages.

From users POV it makes no difference whether an attribute is global or not, save for processing order. If escape merits another page, it probably is only because of its abilities, but then some tags are also more powerful than others. Dunno how to structure the docs atm…

I would suggest that we keep attributes descriptions in some central place (tags cross-reference?) and pull it from there (via jQuery or etc_query or something, with a cache) on individual tags pages, to avoid text duplication. Ignore me, they act differently depending on tags.


etc_[ query | search | pagination | date | tree | cache ]

Offline

#50 2017-12-19 17:48:14

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,400

Re: Poll: useful 'escape' transforms

This is all very exciting, but the longer the discussion goes on, the less I understand.

I think many people, like me, will need detailed instructions for the large number of new features in version 4.7.

Thank you for your great work.

Offline

Board footer

Powered by FluxBB