Suggestion for conditional

0 views
Skip to first unread message

jck...@gmail.com

unread,
May 2, 2015, 12:59:42 AM5/2/15
to Pure-Unobtrusive...@googlegroups.com


following the selector@attribute syntax we could have:


"selector?classname" : "dataname".

shorthand for
"selector@class+" : function(){ this.dataname? " classname" : "" }
(ideal world, remove class if present)

"?classname" : "dataname". would behave like " @attribute" : value


"selector?" : "dataname"

shorthand for
"selector@style+" : function(){ this.dataname? " display:none" : "" }

--

"selector@?property" : "dataname"
conditional include property. Like "checked" "disabled" or [data-decoration] attribute. 


"selector??" : "dataname"
conditional skip the element from output

-------

for the two first rule (shorthand part) this could mean something like

selRx = /^(\+)?([^\@\+\?]+)?(\@)?(\?])?([^\+]+)?(\+)?$/,
m = sel.match(selRx);

prepend = !! m[1];
selector = m[2];
isattr = !!m[3]
iscond = !!m[4]
attr = m[5];
append = !! m[6];

if( iscond &&  !isattr){

   if(attr.length){
        cond_data = " "+attr
        attr = "class"
        append = true
   }else{
        cond_data = " display:none"
        attr = "style"
        append = true
   }

}

Mic (BeeBole)

unread,
May 11, 2015, 4:08:11 AM5/11/15
to Pure-Unobtrusive...@googlegroups.com, jck...@gmail.com, jck...@gmail.com
Returning an empty string to an attribute, will make it disappear.
Or the filter in a loop will prevent a node to be repeated.
These are two kinds of conditionals already there.

What is missing is a conditional to output a node or not.
The style='display:none' is ok but not clean.

I'm not convinced by an additional notation for conditionals.
If you browse the group, you'll find some existing talks about it.

But if we would start something, I would put the question mark on the right side.

1) 'a@class+' : 'dataname ?'
=> would return the value of dataname if positive(true or !=="") otherwise an empty string.

2) 'a@class+' : 'dataname ? " classname":""'
=> would return " classname" if dataname is positive(true or !=="") otherwise an empty string
But that means a parsing/eval of the ? which is a pain

3) 'a' : 'dataname ?'
=> would add a style=display:none if dataname is negative(false, 0, empty string, etc.)

jck...@gmail.com

unread,
May 14, 2015, 12:51:19 PM5/14/15
to Pure-Unobtrusive...@googlegroups.com, jck...@gmail.com
Ok you can do it rigth hand side.

Then it would require that dataname do not have a ? wich is reasonable.
The problem would be the : that could be valid inside a string

if you decide to go that route, here's a regexp that could help you.
it'll split the three part of a?b:c for you.

it's probably slow, but you can search for "?" then for ":" then try to make sens of string escape sequence.


([^?]+)\?((?:[^:'"]+|"[^"\\]*(?:\\.[^"\\]*)*"|'[^'\\]*(?:\\.[^'\\]*)*')*):([\s\S]*)

hello?world:hello
hello?wor":"ld:hello
hello?wor':'ld:hello
hello?wor"\":"ld:hello
hello?:hello
hello?:
Reply all
Reply to author
Forward
0 new messages