Sunday 18 March 2012 12:43:39 am - 7 replies
First post in a series of "crazy ideas to explore at nighttime", this is dedicated to a new friend of mine: jQuery.
I never used that framework very much (I remain a backend coder at heart), but having been recently involved in whipping up some interactive and cool-looking web pages, I was impressed by the ease with which it allows to select sets of html elements and retrieve / alter their values.
The next (il)logical step was asking myself: can we reproduce such conciseness and ease of use in the eZ template language, where fetch functions are a staple? After all the "content/list" fetch function is used to select a set of nodes from a tree, with some filters applied. And, hey, nodes have attributes too, just like html elements!
Read on for more senseless drivel, erm, detailed analysis...
Sunday 18 March 2012 2:15:55 pm
just for the record, most of those selectors are actually CSS3 selectors (nothing specific to jQuery), see http://www.w3.org/TR/selectors/#selectors
CSS selectors are basically designed to easily query a HTML/XML tree. So if you have a tree containing objects with attributes, it's not surprising that the concept can fit
You might also think of a syntax based on XPath that provides more features (you have functions in XPath) but it feels (and it is) way more complicated than syntax ala CSS selectors.
Sunday 18 March 2012 7:35:49 pm
@Damien I know most of those are just css selectors, I guess just not all of them. It is good to have a link to the css selectors spec though, so that we can strive not to implement anything that goes against it (eg. usage of "+" seems to be reserved for other stuff).
As for xpath, I never really tried to use it, but from reading here and there, it seems to me:
- based on a more sound mathematical structure than css selectors (which are all but universal in fact)
- not really friendly (this might be a biased opinion though, since css selectors I've used for ages)
Wednesday 21 March 2012 7:11:43 pm
+1
Loving the idea. As far as I'm concerned, it's not that less readable than the default fetch functions, you just need to get used to use it.
I also see great auto-completion plugins for our IDE, plus it might help new comers to use this query builder (how would you name it ?).
Let me know if you want me to join your forces.
Cheers,
Arnaud
Monday 16 April 2012 2:51:54 pm
@Arnaud great to have you onboard, a team of 2 is surely enough to get this started.
Before I rush off to github, let's agree on a name for this baby: "ezquery", and "ezselector" being the 1st 2 that come to my mind.
As for the rest:
- template operators "q" (query) and "qc" (query count) [alternative: "f" and "fc", but it looks like it's fottbla related
]
- components: a parser of the "q" string; 2 backends that translate the parsed representation into requests to current and ezp-net content models; optional an in-built cache so that calling "q" many times over with the same parameters does not destroy your performances
- choice: we should agree in detail about the syntax we support. It can be imho either more jquery-like or more ez-like (using one way to denote matching on attributes and another one, generic, to match everything else)
Tuesday 17 April 2012 2:37:46 pm
Quote from Gaetano Giunta :@Arnaud great to have you onboard, a team of 2 is surely enough to get this started.
Before I rush off to github, let's agree on a name for this baby: "ezquery", and "ezselector" being the 1st 2 that come to my mind.
As for the rest:
- template operators "q" (query) and "qc" (query count) [alternative: "f" and "fc", but it looks like it's fottbla related
]
- components: a parser of the "q" string; 2 backends that translate the parsed representation into requests to current and ezp-net content models; optional an in-built cache so that calling "q" many times over with the same parameters does not destroy your performances
- choice: we should agree in detail about the syntax we support. It can be imho either more jquery-like or more ez-like (using one way to denote matching on attributes and another one, generic, to match everything else)
ezquery sounds good
I like the backend implementation and I see at least 3 backends :
Regarding the query operator, there's a need to configurate (via a kind of dependency injection) the query builder before making the request. I mean that we might want to fetch different types of entity such as content nodes, objects, etc. Plus, why we need that ? If we follow the jQuery concept, the # selector will be used used together with an ID value and that's the issue. A content object has 2 ids : his node_id and his contentobject_id. We could think of a "#" selector used with a node_id and "##" with the contentobject_id, but... well, what I have in mind looks like :
{def $ezq_config = qconfig( 'node', 'v2' ) $items = q( $ezq_config, "#2" )}
That way, 'node' might be used to select which backends are used. We could also have default request parser and query builder, and they should be extendable so anybody could create its own backend and provide it as an extension ![]()
Furthermore (writing and thinking at the same time...), I would like the q() operator not to return the results directly, but I'd prefer something like an eZQueryObject with attributes we can inspect within a template :
Then usage might looks like :
{def $ezq_config = qconfig( 'node', 'v2' ) $ezq = q( $ezq_config, "#2" ) $items = $ezq.results}
What do you think ?
I suggest that you start a github project called ezquery and that we use the wiki to write down our ideas, concepts, etc before writing a single piece of code (I know you Gaetano !!!
)
Cheers,
Arnaud
Modified on Tuesday 17 April 2012 2:39:18 pm by Arnaud Lafon
Tuesday 17 April 2012 7:27:21 pm
Mmm, lots of bread on the table my friend...
One thing I do not want to loose is the ease for writing this line:
{q('#2').name} has {q('#2').children|count} children
Tuesday 24 April 2012 10:17:03 am
Hi Gaetano,
I definitely agree with you when it comes to keep it simple (following your last piece of template code).
Last but not least, we forgot a very important feature to be implemented : limiting the query result set with offset and limit parameters. My opinion is that these parameters should be set using the configuration object (as the 2nd operator's parameter) because using it in the query string would be too much...
Regarding the configuration object, we should also be able to create it on the fly using a hash :
{def $limit = 10} The {$limit} first articles below your root node are : <ul> {foreach q("#2 .article", hash('limit',10)) as $node} <li>{$node.name|wash}</li> {/foreach} </ul>
Note the iterator concept ![]()
Modified on Tuesday 24 April 2012 12:34:39 pm by Arnaud Lafon
You must be logged in to post messages in this topic!