Hi,
I want to write this code: function() { if ($(this).val().length == 0) { return false; } return true; } but I want to use seaside javascript dsl to do that... I suppose the code should be something like this: (((html javascript return: false) condition: (html jQuery this find: 'input'; value; access: 'length'; equals: 0)), (html javascript return: true)) asFunction the problem is: it does not exists an "#equals:" message (not a greater:, etc. ) so, I wonder how you do this using the DSL... is there a way? or I need to add that protocol? thanks, Esteban _______________________________________________ seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
Hi Esteban,
This should work right out of the box: (JSStream on: '$(this).val().length == 0') then: (html javascript return: false) else: (html javascript return: true) although you might want to shrink that to: (html javascript return: (JSStream on: '$(this).val().length != 0')) And, indeed, there are some gaps in the javascript DSL. Although I prefer to push as much javascript out to separate files, instead of using strings or the DSL itself. We have nevertheless implemented some modest extensions for our own purpose, but if there is interest to seeing the DSL expanded, I would happily contribute them. For '==' in JS, just add this method: JSObject>>equals: anObject self addDecoration: (JSBinary new operator: '=='; statement: anObject) Also mind that the #then:else: only accepts a single javascript statement in each branch. I think the DSL is good to combine JS statements that you really need to generate (such as the jQuery ajax callbacks). For everything else, I use JSStream or external files. cheers Johan On 08 Apr 2011, at 16:39, Esteban Lorenzano wrote: > Hi, > I want to write this code: > > function() { > if ($(this).val().length == 0) { > return false; > } > return true; > } > > but I want to use seaside javascript dsl to do that... > I suppose the code should be something like this: > > (((html javascript return: false) > condition: (html jQuery this find: 'input'; value; access: 'length'; equals: 0)), > (html javascript return: true)) > asFunction > > the problem is: it does not exists an "#equals:" message (not a greater:, etc. ) > > so, I wonder how you do this using the DSL... is there a way? or I need to add that protocol? > > thanks, > Esteban > > > _______________________________________________ > seaside mailing list > [hidden email] > http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside _______________________________________________ seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
Hi Johan,
Thanks for the response... I think I will go through adding #equals: protocol :) I also prefer to put the javascript into separated files, but in this case it is a dynamic generated one, with a lot of possible statements (I was just simplifying the example... that's why I cannot use also then:else: :P) Cheers, Esteban El 08/04/2011, a las 12:03p.m., Johan Brichau escribió: > Hi Esteban, > > This should work right out of the box: > > (JSStream on: '$(this).val().length == 0') > then: (html javascript return: false) > else: (html javascript return: true) > > although you might want to shrink that to: (html javascript return: (JSStream on: '$(this).val().length != 0')) > > And, indeed, there are some gaps in the javascript DSL. Although I prefer to push as much javascript out to separate files, instead of using strings or the DSL itself. > We have nevertheless implemented some modest extensions for our own purpose, but if there is interest to seeing the DSL expanded, I would happily contribute them. > > For '==' in JS, just add this method: > > JSObject>>equals: anObject > self addDecoration: (JSBinary new operator: '=='; statement: anObject) > > Also mind that the #then:else: only accepts a single javascript statement in each branch. > > I think the DSL is good to combine JS statements that you really need to generate (such as the jQuery ajax callbacks). For everything else, I use JSStream or external files. > > cheers > Johan > > On 08 Apr 2011, at 16:39, Esteban Lorenzano wrote: > >> Hi, >> I want to write this code: >> >> function() { >> if ($(this).val().length == 0) { >> return false; >> } >> return true; >> } >> >> but I want to use seaside javascript dsl to do that... >> I suppose the code should be something like this: >> >> (((html javascript return: false) >> condition: (html jQuery this find: 'input'; value; access: 'length'; equals: 0)), >> (html javascript return: true)) >> asFunction >> >> the problem is: it does not exists an "#equals:" message (not a greater:, etc. ) >> >> so, I wonder how you do this using the DSL... is there a way? or I need to add that protocol? >> >> thanks, >> Esteban >> >> >> _______________________________________________ >> seaside mailing list >> [hidden email] >> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside > > _______________________________________________ > seaside mailing list > [hidden email] > http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside _______________________________________________ seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
On 08 Apr 2011, at 17:21, Esteban Lorenzano wrote: > I also prefer to put the javascript into separated files, but in this case it is a dynamic generated one, with a lot of possible statements (I was just simplifying the example... that's why I cannot use also then:else: :P) okay ;-) Just make a subclass JSFullIfThenElse of JSIfThenElse with the following method override: javascriptContentOn: aStream aStream nextPutAll: 'if('. self owner javascriptContentOn: aStream. aStream nextPutAll: '){'. aStream javascript: self trueStatement. aStream nextPutAll: '} else {'. aStream javascript: self falseStatement. aStream nextPutAll: '}'. _______________________________________________ seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
Hi there,
I wonder why we should subclass JsIfThenElse instead of extending it. The situation and problem is as follows: if trueStatement or falseStatement in JsIfThenElse is a JsConcatenation, it should output itself surrounded by curla braces - and that should be it. So why not either ask trueStatement and falseStatement if they are JSConcatenations and if so surround them with Braces. It might be even cleaner to introduce a new JSDecoration for JavaScriptBlocks, a specialisation of JSConcatenation that not only concatenates, but also puts curly braces around the javascript output. Of course this could also be a flag in JSConcatenation that is set in methods like then: and then:else: Joachim |
Thinking about it a little, the simplest thing that could possible work is to drop the short form for if completely and change JsIfThenElse>>#javascriptOn: to:
javascriptContentOn: aStream aStream nextPutAll: 'if('. super javascriptContentOn: aStream. aStream nextPutAll: ') {'. aStream javascript: self trueStatement. aStream nextPutAll: '} else {'. aStream javascript: self falseStatement. aStream nextPut: $}. It does, admittedly, add syntactic sugar to many if-statements but at least they are always correct and there is no need for decisions based on the number of statements for true and false. |
Free forum by Nabble | Edit this page |