Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#61 2011-12-30 17:26:01

milosevic
Member
From: Madrid, Spain
Registered: 2005-09-19
Posts: 390

Re: smd_wrap: conditionally wrap stuff with tags and labels

Bloke dijo:

Try transform="split|,||1" (note the extra pipe delimiter). You need that one to signify that you don’t want any join characters — it’s a mandatory second argument if you’re using the third argument to specify which piece(s) you want back.

Thanks, Stef. works perfectly!

I could add some mathematical transforms if it would help: round, absolute, ceiling floor, etc. I’ll consider it for the next version.

I will find it very usefull, in my example case, I’m using adi_calc to round the returning value given by smd_wrap, and appart of my personal interest, I think it can be a very common case of use.


<txp:rocks/>

Offline

#62 2012-01-05 21:46:00

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: smd_wrap: conditionally wrap stuff with tags and labels

Hi Stef.
Although, because of Your Grace, we already have all conditional corners covered with smd_if, I wonder if some basic conditional magic dust could be poured over smd_wrap.

I was thinking on something like this:

<txp:smd_wrap condition='<txp:tag_that_could_return_something_or_empty />'>
... the codez... maybe just a few lines... maybe lotz of them!...
</txp:smd_wrap>

If the imaginary tag returns empty (condition=""), smd_wrap aborts! Else, it does its magic…
I can expand the example & usage case a little more, but will wait until your first feedback :)
Thanks.

PS: let’s momentarily ignore that similar (but not exactly what I’m thinking of) stuff may be achieved with prefix/suffix attributes. ;)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#63 2012-01-05 22:55:18

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,538
Website GitHub

Re: smd_wrap: conditionally wrap stuff with tags and labels

maniqui

Hmmm, interesting. So let me get this straight in my head: instead of using item as a substitute for form/container, you’d like to use such an inline item to test some other condition and then wrap the form/container contents, instead of testing the form/container itself to see if it returned anything?

If that’s the case then I can see the appeal. I’d like to see a solid use case that I can latch onto (also good for testing if I’m swayed by your argument) before I commit to giving this some brain power. But off the top of my head I would probably consider some attribute for switching the ‘item’ attribute to an independent condition instead of as a substitute for form/container.

My reasoning is that you’re unlikely to want to use both item and condition together, since wrapping a form/container is neater than two tags-in-tags monstrosities. So to reuse item for some kind of conditional role seems more logical to me (or maybe it’s just easier to code!). But from a user viewpoint, you’d have to specify two attributes to do the conditional thing — one to turn the mode on and then another for the item you want to test — and I just know you’ll hate that :-)

Tell you what, convince me of the merit behind this with some luscious examples and I’ll mull it over. How’s that sound?

Last edited by Bloke (2012-01-05 22:55:31)


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

#64 2012-01-12 19:38:00

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: smd_wrap: conditionally wrap stuff with tags and labels

Emmm… totally forgot about this… it seems I still owe you a proper reply to the above. Argh.. you will make me think. I’ll come back to that later.

In the meanwhile, Bloke, could you explain the differences (or use cases) between transform="sanitize|url" and transform="sanitize|url_title"?

I will try to answer to myself.
I’ve looked thru the code of smd_wrap, and I see the former uses function sanitizeForUrl, while the latter uses function stripSpace (which also ends up doing the sanitizeForUrl thing). It seems that the url_title transform also takes care of trimming dashes (-) and converting the string to lowercase.

OK, that said, this is why I came here: I was looking for a way to encode an URL to use it on those fancy share buttons.
I thought that transform="sanitize|url" would have also encoded the URL, but it seems that sanitizeForUrl only uses rawurlencode as a last resort, if all previous processing returned empty (or just a dash).

So, should I request for this rawencodeurl functionality on smd_wrap? Or may I just go with rah_function?


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#65 2012-01-13 09:59:57

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,538
Website GitHub

Re: smd_wrap: conditionally wrap stuff with tags and labels

maniqui wrote:

So, should I request for this rawencodeurl functionality on smd_wrap?

Request noted. Makes sense if that’s your desired end result.


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

#66 2012-01-19 19:35:55

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: smd_wrap: conditionally wrap stuff with tags and labels

Thanks for taking note of my requests, Stef.

So… what about adding some rvm_substr capabilities to the available transforms?
A cut transform:

For example, I’m thinking a transform like this: transform="textile,strip_tags,cut|140|...".
That one will take some field that may have textiled content, apply Textile to it, then remove all the HTML generated. At this point, we have a clean, plain text string, and then we cut it at 140 characters, and add some ellipsis.

If the idea has some appeal to you, then, let’s take it one step further: cut transform may be able to cut at a certain amount of characters or words: cut|140|25|.... That one will cut at 140 chars or at 20 words, and then add ellipsis.

Edit: fixed some inconsistencies in the examples (140 != 156) :P

Last edited by maniqui (2012-01-27 01:12:13)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#67 2012-01-27 00:36:30

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,538
Website GitHub

Re: smd_wrap: conditionally wrap stuff with tags and labels

For the curious, v0.20 beta has been altered as follows:

  • Works like chh_if_data by default. Use <txp:smd_wrap_all> for v0.10 behaviour (it’s only 4 chars more!)
  • form / <txp:yield /> support
  • A safer <txp:smd_wrap_info /> tag instead of {smd_wrap_it}. Might have more ideas on this as I test it more thoroughly
  • Added time transform as a convenience (same as date)
  • Added raw and encode sanitization transforms (thanks maniqui)
  • Added currency, round and number transforms (thanks jakob, milosevic)

I’ve got some more stuff to consider yet (maniqui’s cut transform is one of them) though this beta may well constitute the final release and I might fold the other stuff into later versions. I’d appreciate some feedback on this version, particularly the new transforms and how successful the form/yield is. Ta!

Last edited by Bloke (2012-01-27 00:39:34)


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

#68 2012-01-27 10:33:17

milosevic
Member
From: Madrid, Spain
Registered: 2005-09-19
Posts: 390

Re: smd_wrap: conditionally wrap stuff with tags and labels

Thanks Stef:

I’m playing with the new transform=“round” param, maybe I’m doing somethig the wrong way, but no value is returned in any case. I’m testing with this code lines:

<p><txp:smd_wrap transform="round" item="97.856" /></p> 
<p><txp:smd_wrap transform="round">97.856</txp:smd_wrap></p> <-- item wrapped-->
<p><txp:smd_wrap transform="round" item="97,856" /></p> <-- trying with comma istead of dot -->
<p><txp:smd_wrap transform="round|up" item="-97.856" /></p> <-- item and "up" param" -->
<p><txp:smd_wrap transform="round|up" item="-97,856" /></p> <---item and "up" param with comma -->

…and one question: do you autodetect the floating point separator character (in spanish and other languages people use comma instead of a dot) or must we use allways a dot?

Last edited by milosevic (2012-01-27 10:34:03)


<txp:rocks/>

Offline

#69 2012-01-27 15:24:23

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,538
Website GitHub

Re: smd_wrap: conditionally wrap stuff with tags and labels

milosevic wrote:

no value is returned in any case.

Blame maniqui :-p

He told me that nobody would ever want to wrap stuff that didn’t contain Txp tags in it, so I should make the default behaviour only work with content that contains Txp tags!

Seriously though, if you want it to work in this case you should use <txp:smd_wrap_all> instead. Note also that if you’re doing this in an article, beware that item="-97.856" actually presents <del>97.856 to the plugin because, for some reason, Textile treats the dash as a strikethrough. So remember to escape anything like that with == around the smd_wrap_all tag.

do you autodetect the floating point separator character

Yes it’s supposed to use the current locale. But I canot test it here so I’d be interested to hear if it works as it should. If it’s a problem, you can always chain the number transform first like this to ‘force’ the locale:

<txp:smd_wrap_all transform="number|es_es, round|up" item="97,856" />

Although if it doesn’t work properly I’ll change it so it does take the locale into account. Please let me know.

Last edited by Bloke (2012-01-27 15:25:18)


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

#70 2012-01-27 21:58:06

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,538
Website GitHub

Re: smd_wrap: conditionally wrap stuff with tags and labels

Oh ok, so I couldn’t resist sneaking in the cut transform (thanks maniqui). It’s certainly no substitute for rvm_substr, but it’s a cheap and quick chopper at either N characters (the default) or M words. Or both. Continuation chars supported.

Also spruced up the debug output so you can see what’s going on at each step of a chained transform.


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

#71 2012-01-28 07:06:35

milosevic
Member
From: Madrid, Spain
Registered: 2005-09-19
Posts: 390

Re: smd_wrap: conditionally wrap stuff with tags and labels

Bloke, You are right, sorry! Focused on trying the new “round” I forgot this plugin is conceived for wrapping tags, no fixed data. I use to try thinks with fixed data before and, when check that it runs, then apply variables, tags in tags, etc.

Last edited by milosevic (2012-01-28 07:07:31)


<txp:rocks/>

Offline

#72 2012-02-15 18:26:46

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: smd_wrap: conditionally wrap stuff with tags and labels

Two findings:

First finding: if you want to replace something with a blank space, you have to add an extra param_delim at the end of last argument (the to):
So, this two won’t get the desired result (ie. the replace will take place, although the replaced string won’t be replaced by a blank space, but just by an empty string).

<txp:smd_wrap_all transform="replace||3| ">12345</txp:smd_wrap_all>

Output: 1245

While this:

<txp:smd_wrap_all transform="replace||3| |">12345</txp:smd_wrap_all>
// notice the extra pipe (param_delim) at the end

Output: 12 45

Same happens when using regex.

Second finding: I couldn’t find a way to avoid the wrapping p when using the Textile transform. Or, in other words, I couldn’t find a way to apply Textile to a string, while escaping the wrapping p tag at the same time.

<txp:smd_wrap_all transform="textile">This one will get *wrapped* by a p tag!</txp:smd_wrap>

This one will output: <p>This one will get <strong>wrapped</strong> by a p tag</p>, which is correct.

Then:

<txp:smd_wrap_all transform="textile"> This one will get *wrapped* by a p tag _too_, but I wish it won't!</txp:smd_wrap>

This one will output: <p>This one will get <strong>wrapped</strong> by a p tag <em>too</em>, but I wish it won’t!</p>.
As you can see, the p tag is there, even if I tried to escape it with a leading blank space.

For the record, upm_textile plugin lets you avoid the wrapping paragraph (while still applying Textile to the string) by just adding the leading blank space.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB