-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feature request] - ability to use JavaExpressions in String literale like GString #19
Comments
are you asking to create a another template mechanism in Japid? not sure about that. Escaping: I'll have something for that. In the meantime you can always do ${' |
version 0.8.6 added support for using ~ as the generic escape marker: ~~, ~@, ~#, ~$, etc.. |
Why another template mechanism? I dont understand you. I just want this following: Just a handy way to build up String values in script mode without string-concats. Im porting a Grails app -> Japid + Play!, and my Grails tags ultilize this syntax that much. |
Yea I know that. It's called GString, which internally is a small template engine. |
Exactly, GString. But do you think, is it not easy to implement this feature or somehow to mimic this behavior in Japid? I think, it's one of the most important syntax sugar to avoid the feeling "we are coding views in Java". |
But I don't want to let people feel they're coding in yet another language. I got a a few comments saying using pure Java is an advantage. String.format() in the interim? |
Ok, String.format() + multi-line continuer is good enough. I have totally forgot it. Thank you! |
Hi Bing, After days working with Japid, i feel, im really missing the ability to build simple String template inline, like Goovy GString. All the time i need to use String.format(). And using String.format doesnt seems to help much, the code is still not reader-friendly (ok, abit better than String-concat) and performance of String.format is worse. Because everytime String.format is called, it must be going to create a Fomatter instance first. I think, using of mass String.format could hurt performance and violates Japid's philosophy (raw performance is the King) and Japid's image too. And i think, other users would also like ithis feature, especially if they coming from dynamic script language background.
==> With this features my code would be much cleaner and performanter. Pls target it in your plan Bing! |
Let me think about it, OK? |
Can you use local methods to get the same effect?
would become:
So basically extract all string interpolation logic into local methods and invoke them in your main logic block. Local methods are mini templates. |
ok, with local methods i will not have performance problem as with String.format. But i think, the two other problems are still there:
I think, local methods only makes sense when we ever want to reuse them multiple times. |
OK, version 0.8.8.2 has been specifically built for you. It's really a hack , but it will pre-process the source code and expand anything of pattern $[xxx] to " + xxx + ". It's a pre-processor and does not have any intelligence in parsing the code. |
oh yeah, cool! I was also talking about such a pre-processing of source code, one dont need here some powerful, automagical feature which hurts performance. i will try it right now. |
----> generated code: callbackSnip = "function htmlSuccess_"+id+" (responseText, statusText, xhr, jqForm) {\n var data = responseText;\n $[reRenderSnip(reRender, dataType)]\n "+success+"\n }";// line 30 $[reRenderSnip(reRender, dataType)] was not pre-processed. |
$[testArray[0]] will also not be pre-processed. |
Can you try the refreshed 0.8.8.2? I was too restrict in pattern |
i could not force Play! to install the new refreshed 0.8.8.2. I have tried:
|
remove the japid directory in the modules directory and try again. Depending on how you have specified the dependencies. it's either in the play's modules directory or in the modules directory of your application. |
i also tried both before, no success. At my Play! modules folder there is no Japid-module folder, only in project. |
hhmmm, i will try to find out where Play! local ivy repo is, perhaps the old version is still there. |
Ok, the Play! ivy cache was the problem. With refreshed .0.8.8.2 the |
the array [] thing confused the parser. Let me think a bit. |
get the 0.8.8.3 and start using |
I didnt see any changes with 0.8.8.3. What i see, is, i can still use the syntax Must i use the syntax |
hmm, I refreshed it just now. Can you verify that? Also, go to the japid cache and find the readme there see if you can see a log of it. |
everthing is fine now, confirmed! Thank you very much! |
Handy to use and save us alot of string-concats and the view codes look then abit like "view code" rather than coding view in Servlet :-D, if u know what i mean.
PS: pls also note the ability to escape the tow symbols $ and ~ .
The text was updated successfully, but these errors were encountered: