Respect / Template

Experimental, HTML-only templating engine
Other
38 stars 6 forks source link

Allow Pseudo Selectors #32

Closed malukenho closed 10 years ago

malukenho commented 10 years ago

I think that cover pseudo selectors in css template engine Respect is very handy. To do this, I created 2 methods in the class Query that comes if there is a pseudo selector in css selector and passes to a factory that will return the instance of a pseudo selector and will call the apply to "filter" the dial, leaving compatible with xpath.

Only did the 'first-child', do not know if this is the best way for such a task. Hopefully opinions and suggestions.

nickl- commented 10 years ago

I am not following, please excuse me.

@malukenho can you please add some unit tests as examples of what you implemented.

malukenho commented 10 years ago

@nickl- excuse for not writing test. Just wondering if this would be a valid way to implement the pseudo selectors. I will write the tests :)

nickl- commented 10 years ago

@malukenho even just an example here would help? I don't understand what you intend to use it for.

How will you use a:hover in a templating context?

malukenho commented 10 years ago

@nickl- I think :hover does not apply, because it is an action of a selector. But pseudo selectors like :nth-child(), :first-child, :last-child, etc ... should be implemented, because these working-level selection of node elements

nickl- commented 10 years ago

Mind showing us an example snippet of what you have in mind please.

I can't help but think think this is something which should be catered for by the supporting libraries i.e. xpath or simple_html_dom and that it is out of scope for Respect/Template. What this project should be focusing on is the injection, iteration, exposure as per the template context. Is enhancing xpath in benefit of the core purpose?

But I am not sure what we're aiming at with this PR hence the request for an example which might shed bore light. Please don't let this hinder your enthusiasm its awesome to see some action around here =)

Have you looked at the simple_html_dom branch? It uses a modified version of simple_html_dom and I tried getting the changes in upstream, some were eventually added but the project lead got it into his head that we are trying to do something which was not what he intended and although i don't understand what he means I eventually gave up.

I am keen to take simple_html_dom further, it is already awesome in its simplicity but it will benefit alot from an OOP redesign/refactor and perhaps the features you need can be implemented there? Again I am punching in the dark without an example. Please help clarify these...

malukenho commented 10 years ago

I think not expresei me well.

There are two types of pseudo-selectors in CSS. By behavior (such as the hover), and element (pseudo-selectors that will help you select an element).

For example, if I want to select only the first item in an ordered list, i would like this:

ul li:fisrt-child

Could understand what I do @nickl- ?

Sorry for my English

malukenho commented 10 years ago

@nickl- @augustohp ??