Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#25 2010-11-07 15:23:40

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

Re: rah_repeat // Split and repeat.

@Jakob, I think you could easily solve this situation using smd_if, configured for OR logic.

<txp:smd_if field='species' operator="contains|contains" value=",|and" param_delim="|" logic="OR">
Plural
<txp:else />
Singular
</txp:smd_if>

I haven’t tested it, but I think that should work.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#26 2010-11-07 17:53:06

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,578
Website

Re: rah_repeat // Split and repeat.

Thank you both of you. strikes forehead with hand of course, you are both right, it would be much easier to test for the existence of a “comma” or “and”. In that particular case, smd_if works well. Weirdly, Julián’s example didn’t work (txp 4.3 with smd_if 0.9) although it looks absolutely right to me. I checked the docs and slimmed it down further and further until I was testing for a simple known phrase still with no luck. In the end I had to use '<txp:custom_field name="species" />' instead of just "species". Is that possibly a bug in smd_if (the only other difference to the sample here is that my custom field begins with a capital letter)?

<txp:smd_if field='<txp:custom_field name="species" />' operator="contains|contains" value=",|and" param_delim="|" logic="OR">
Plural
<txp:else />
Singular
</txp:smd_if>

TXP Builders – finely-crafted code, design and txp

Offline

#27 2011-12-02 11:23:20

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

Re: rah_repeat // Split and repeat.

Rah_repeat v0.7 released. Changes:

  • Added attribute trim. When set to 1, provided values are trimmed from surrounding whitespace.
  • Fixed: “locale” sorting option. Previously it sorted values as a string, not by locale options.
  • Changed: limit’s default to NULL. Leave limit unset if you only want offset without limit, or use a high value.
  • Improved: Better offset and limit functionality. Now slices the list of values before staring to build the markup.

More info and downloads

Offline

#28 2012-02-02 12:10:28

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

Re: rah_repeat // Split and repeat.

Hi Gocom,
what do you think of adding a “range” attribute?
Not sure if there is something similar in PHP, but I’m thinking about something like range in Python.

Code examples:

<txp:rah_repeat value="00,66,aa,ff" range="10">
  <txp:rah_repeat_iteration />:  <txp:rah_repeat_value />
</txp:rah_repeat>

That will loop over the values 10 times.

<txp:rah_repeat value="00,66,aa,ff" range="a-z">
  <txp:rah_repeat_iteration />:  <txp:rah_repeat_value />
</txp:rah_repeat>

That will loop over the values, 26 times (from a to z).

Will expand (if needed) later, if you think the idea has some merit :)
PS: may x-post this request to smd_each too :)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#29 2012-02-02 14:31:46

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

Re: rah_repeat // Split and repeat.

maniqui wrote:

what do you think of adding a “range” attribute?

Check out the rah_repeat’s repository and the latest commit ;) (or couple commits ago).

range="min, max [, step]"

Where min and max are required and step is optional. Because combining range and value is very limiting (and also adds complexity to the code), I’ve made range and value VIPs, and the club only has one VIP room. Either it’s one or the other, which gives both the same power; excluding, sorting etc. Nesting can be used to combine their powers. E.g.

<txp:rah_repeat range="0,10">
	<txp:rah_repeat_value />
	<txp:rah_repeat value="00,66,aa,ff"><txp:rah_repeat_value /></txp:rah_repeat>
</txp:rah_repeat>

Last edited by Gocom (2012-02-02 14:48:42)

Offline

#30 2012-02-02 20:45:31

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,578
Website

Re: rah_repeat // Split and repeat.

I’d love to see some real-world usage examples for this and the code it produces as I don’t really understand the example above.


TXP Builders – finely-crafted code, design and txp

Offline

#31 2012-02-02 23:34:56

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

Re: rah_repeat // Split and repeat.

jakob wrote:

I’d love to see some real-world usage examples for this and the code it produces as I don’t really understand the example above.

Not exactly real life example, but the README.textile has the attribute explained and some examples.

Basically range creates a range of elements, as an array. It takes minimum value, and maximum value and creates a list of those values. In programming languages range is especially cool as it’s freaking fast. It has size limitation (memory), but it’s fast.

Now, let’s say you wanted to build page numbers of some sorts. Nine pages, nine links.

<txp:rah_repeat range="1, 9, 1" break=", "><txp:rah_repeat_value /></txp:rah_repeat>

Returns: 1, 2, 3, 4, 5, 6, 7, 8, 9

Or you wanted to print out alphabet (just basic a-z, it doesn’t support anything else).

<txp:rah_repeat range="a, z, 1" break=", "><txp:rah_repeat_value /></txp:rah_repeat>

Returns: a, b, c, d, [...]

Huh, but there are three parameters, that anonymous 1. It’s step. You bad at math, need every fourth integer:

<txp:rah_repeat range="12, 24, 4" break=", "><txp:rah_repeat_value /></txp:rah_repeat>

Returns: 12, 16, 20, 24

It’s doesn’t do that much. It just creates list of numbers or characters automatically, from min to max. Might be useful for iterating over something multiple times, or to generate page links or something else that needs known integers. Honestly speaking, If it weren’t so easy to add (adding no new code), I wouldn’t have added it. But as it is, well, why not.

Last edited by Gocom (2012-02-02 23:36:08)

Offline

#32 2012-02-03 07:37:37

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,578
Website

Re: rah_repeat // Split and repeat.

Thanks for the infos. I groked the range attribute and step var fairly easily but the combination example had me flummoxed. Your infos on github (excellent by the way) filled me in, although I’m still a bit confused by the above example:

<txp:rah_repeat range="0,10">
	<txp:rah_repeat_value />:
	<txp:rah_repeat value="00,66,aa,ff"><txp:rah_repeat_value /></txp:rah_repeat>
</txp:rah_repeat>

… which, as far as I can tell, returns 0: 0066aaff 1: 0066aaff 2: 0066aaff 2: 0066aaff .... Now I just need to think of somewhere where that kind of pattern might be useful.


TXP Builders – finely-crafted code, design and txp

Offline

#33 2012-02-03 07:56:09

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,578
Website

Re: rah_repeat // Split and repeat.

Off Topic: Jukka, your new github repo is most informative and you have a couple of things in there I’d not seen before that look like they could be useful as potential more flexible or more secure alternatives for other much-used plugins. I’m thinking of rah_flat (for cnk_versioning?), rah_backup (for rss_db_admin?) and rah_gps (for adi_gps). Whenever you get the time, I’d love to see some more infos if only to hear whether they are release-ready.

Last edited by jakob (2012-02-03 08:55:00)


TXP Builders – finely-crafted code, design and txp

Offline

#34 2012-02-03 08:04:15

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

Re: rah_repeat // Split and repeat.

jakob wrote:

which, as far as I can tell, returns

Yes.

Now I just need to think of somewhere where that kind of pattern might be useful.

I have no idea. I was just replying to Julián’s question, without actually even knowing in which order the iteration should be executed. More suitable realization might be:

<txp:rah_repeat range="0,10">
	<txp:variable name="i">
		<txp:rah_repeat_value />
	</txp:variable>

	<txp:rah_repeat value="00,66,aa,ff">
		<txp:variable name="i" />: <txp:rah_repeat_value />
	</txp:rah_repeat>
</txp:rah_repeat>

Which returns 0 : 00 0: 66 0: aa 0: ff 1: 00 1: 66 ....

Or perhaps:

<txp:rah_repeat value="00,66,aa,ff">
	<txp:variable name="i">
		<txp:rah_repeat_value />
	</txp:variable>

	<txp:rah_repeat range="0, 10">
		<txp:variable name="i" />
	</txp:rah_repeat>
</txp:rah_repeat>

Which returns 00 00 00 00 00 ... 66 66 66 66 66 ... aa aa.

Last edited by Gocom (2012-02-03 08:06:12)

Offline

#35 2012-02-03 13:10:18

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

Re: rah_repeat // Split and repeat.

Regarding the example, it was just a dummy one, a non-sense at all.
I did something similar while wireframing a website that allowed me to generate some placeholder thumbnails on the fly with different colors (using placehold.it/).

<txp:rah_repeat value="00,66,aa,ff,00,66,aa,ff,00,66,aa,ff,00,66,aa,ff">
  <img src="http://placehold.it/100x100/e1bb<txp:rah_repeat_value />/" />
</txp:rah_repeat> 

At the time I wrote it, I thought that a range="12" or times="12" attribute would have helped in avoiding the long list of repeated values. Then, Gocom provided it :) (although, as he make it clear, both can’t be used in the same rah_repeat tag).


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#36 2012-02-25 08:13:41

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

Re: rah_repeat // Split and repeat.

jakob wrote:

I’d love to see some more infos if only to hear whether they are release-ready.

Super-late reply, I know. I didn’t originally see your post (sorry, I wasn’t ignoring you). Fun times skimming through the forum (I didn’t google myself or anything ha-ha — truth is that I actually did google rah_backup — I’m one of those idiots that use google to open web pages).

Well, so, there is a refactoring of Rah website going (as we know it as rahforum.biz in it’s current form). Once that is done, some of the plugin will be released there as usual in compiled package format. For example rah_backup will be released as a normal plugin in the usual manner and is easy to notice from .org and forum spam.

Rah_backup it’s current state it’s stable, but it might not be good idea to use; it’s dev branch after all. I know that the next push will change the code a bit and drop number of preferences (useless ones to stream line it), making the code OOP.

Other projects as rah_gps, rah_global, mck_login are patches/forks. Most of the time one time deals. Will likely never be updated or compiled as installable packages. Adi updated adi_gps, so that there too.

Rah_flat on the other hand is very complicated plugin. It will be released as git repo, and that is probably it. First stable release will be the v0.1 tag that comes in sometime 2012. I’m very eager to not put out any forum topic for it either (it can be rather dangerous plugin for “end-users” — it can suck the single copy of the database). Cnk_version has eated my database, and I’m not willing to feed lions yet.

One thing you may have noticed that there are plugins missing from GitHub. Except for few, those missing ones are dropped projects. As the new Rah site goes up, they won’t be part of it as they are now. Instead you will be greeted with deprecated notices, instructions and alternatives, and a realllllyyyy tiny download button for those that do not fear germs.

It may seem that a lot have changed, but that just make up. The difference is that I’m using git instead of SVN (I don’t have a soul), and that the repository is public. Now there is easy to use issue tracker too (GitHub is amazing). Well kept secret (or is it? :wink:) is that plugins like rah_backup or new improved rah_post_versions in reality were started while ago. Maybe as far ago as a year.

Offline

Board footer

Powered by FluxBB