~ghost08/ratt

5 2

[Question] Reverse the order of items

Mubashir Haroon
Details
Message ID
<eb495bcb-d651-feb1-25bf-719b578d47f7@gmail.com>
DKIM signature
pass
Download raw message
I was writing a config for a website and there the items are listed in 
ascending order, which makes sense on the site but in rss feed, the new 
one should be on top. Or at least that is what I want.

So is there a way to reverse the order of the items using lua.
Details
Message ID
<CCHJYWGAZNQ3.Z23D4U7HPS6J@micro-pc>
In-Reply-To
<eb495bcb-d651-feb1-25bf-719b578d47f7@gmail.com> (view parent)
DKIM signature
fail
Download raw message
DKIM signature: fail
There isn't now a way to order the items. But it's a good note.

Maybe there could be a new attribute on the `item`, something like
go's *sort.Interface* (https://golang.org/pkg/sort/#Interface).
But we don't need the Len() and Swap(i,j) functions. So there will be
just the Less(i,j) function. Something like:

	selectors:
		feed:
			...
		item:
			...
			less: |-
				--i and j are the item objects (lua tables)
				print(i.created < j.created)

Or another approach would be to add a `sort` attribute to the selectors,
where it will receive the full array of items and will sort it however
it likes.

	selectors:
		...
		sort: |-
			--items is the array of items
			table.sort(items, function(i, j) 
				return i.created < j.created
			end)

But now ratt just creates the items and just some things are converted
to lua. This would mean, that items have to be converted to lua tables,
then sorted in lua and when returned, again converted to a go struct.

So I don't know. What do you think?
Mubashir Haroon
Details
Message ID
<de60c905-dc53-6591-9cda-3e1b04d9a8ac@gmail.com>
In-Reply-To
<CCHJYWGAZNQ3.Z23D4U7HPS6J@micro-pc> (view parent)
DKIM signature
pass
Download raw message
I think the `sort` attribute in selectors method is better, as sorting
is something that is not really related to item extraction and should be
handled separately.

Another thing that can be done is that a `sort` attribute in selectors
is used to specify some default sorting methods like reverse sort or
alphabetic order etc, without the option to write lua code. It will
remove the need to convert items to `lua tables` and back to `go
struct`. A new function which takes the value of `sort` and the items
array as parameters and modify the order of the array items based on the
predefined sorting type specified.

This certainly will not be as powerful as having the ability to sort
however one wants to with lua script but thinking about it, there are
not that many types of sorting that one might want to apply.

What do you think about this?
Details
Message ID
<CCHTEALIU6C3.3FZANO0J1O44C@micro-pc>
In-Reply-To
<de60c905-dc53-6591-9cda-3e1b04d9a8ac@gmail.com> (view parent)
DKIM signature
fail
Download raw message
DKIM signature: fail
> Another thing that can be done is that a `sort` attribute in selectors
> is used to specify some default sorting methods like reverse sort or
> alphabetic order etc, without the option to write lua code. It will
> remove the need to convert items to `lua tables` and back to `go
> struct`. A new function which takes the value of `sort` and the items
> array as parameters and modify the order of the array items based on the
> predefined sorting type specified.
>
> This certainly will not be as powerful as having the ability to sort
> however one wants to with lua script but thinking about it, there are
> not that many types of sorting that one might want to apply.

Ok that's a good argument, you're rights. It can be a enum like REVERSE,
CREATED, TITLE and so. Also it will be quicker to implement. Maybe tomorow
I will have a look at it.

Will infrom you on how it goes.
Details
Message ID
<CCNI2VGF1R21.2S6VTS19HB7SF@micro-pc>
In-Reply-To
<CCHTEALIU6C3.3FZANO0J1O44C@micro-pc> (view parent)
DKIM signature
fail
Download raw message
DKIM signature: fail
So it took a while longer, but I got to it. Now the selectors have a
`sort` attribute which is a enum with values:
REVERSE, CREATED_ASD, CREATED_DESC, TITLE_ASD, TITLE_DESC

Maybe later I will add other values as well.

So try it and report if something doesn't work.
Mubashir Haroon
Details
Message ID
<03f280e0-e72b-ea06-2a8b-6f49319cd4a2@gmail.com>
In-Reply-To
<CCNI2VGF1R21.2S6VTS19HB7SF@micro-pc> (view parent)
DKIM signature
pass
Download raw message
Thank you very much.
Reply to thread Export thread (mbox)