Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

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

Gocom
Plugin Author
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,036
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,036
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
Plugin Author
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
Plugin Author
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

#37 2012-08-24 23:09:21

Gocom
Plugin Author
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: rah_repeat // Split and repeat.

Rah_repeat v0.8 is out. This updated concentrates making things easier for all of us. Changelog:

  • Fixed: made the sort attribute’s direction optional.
  • Added: exclude can now take and exclude empty strings ("") and zeros (0).
  • Added: range attribute. Allows generating automated lists (range="min, max, step").
  • Added: assign attribute. Allows extracting values as variables.
  • Added: escape attribute to <txp:rah_repeat_value />.
  • Added: Support for natural ordering (sort="natural").
  • Changed: Now trim is enabled by default. Previously values weren’t trimmed from white-space by default.
  • Changed: Renamed locale sorting option to LOCALE_STRING.
  • Changed: Order can be reversed with out re-sorting by using sort="desc".
  • Now requires PHP 5.2 (or newer).

See the release article for introduction to the new features, or jump directly to the docs and download here.

Offline

#38 2012-08-25 12:50:04

etc
Developer
Registered: 2010-11-11
Posts: 4,079
Website

Re: rah_repeat // Split and repeat.

I’m getting a weird issue with range (txp 4.4.1 and php 5.3.10 on wamp): whatever values I use, e.g.

<txp:rah_repeat range="4,100" wraptag="p" break=",">
	<txp:rah_repeat_value />
</txp:rah_repeat>

or


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

it outputs 0 , 1 , ... , 10.

Offline

#39 2012-08-25 18:49:25

Gocom
Plugin Author
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: rah_repeat // Split and repeat.

Thanks for the report, Oleg. It’s fixed. It was the array_merge I used to make sure there is a third parameter set. Well, It does recalculate numeric indexes.

Offline

#40 2012-08-25 18:59:40

Gocom
Plugin Author
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: rah_repeat // Split and repeat.

Rah_repeat version v0.8.1 is out. Fixes the range issue.

More info and downloads

Offline

Board footer

Powered by FluxBB