Skip to content
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

Local variable declareation in templates. #26

Closed
ismail-codar opened this issue May 2, 2016 · 5 comments
Closed

Local variable declareation in templates. #26

ismail-codar opened this issue May 2, 2016 · 5 comments

Comments

@ismail-codar
Copy link

ismail-codar commented May 2, 2016

My template like this:

fetch(url).then(function(response) {
    response.json().then(function (@raw(SwaggerUtil.responseTypeName(entryValue.getJsonObject("responses")) == "void" ? "" : data)) {
        resolve(@raw(SwaggerUtil.responseTypeName(entryValue.getJsonObject("responses")) == "void" ? "" : data));
    });
})

But SwaggerUtil.responseTypeName(.. function calling 2 times.
Can I use it like following

@localvar rParam = @SwaggerUtil.responseTypeName(entryValue.getJsonObject("responses"))  == "void" ? "" : data
fetch(url).then(function(response) {
    response.json().then(function (rParam )) {
        resolve(rParam );
    });
})
@jjlauer
Copy link
Member

jjlauer commented May 3, 2016

Local variable assignment would be a useful feature. If you wanted to take
a stab at implementing it, I'd be happy to review the PR.

Just one comment on your included code though -- seems like a lot of logic
to put inside a template. Wouldn't it be cleaner to fetch(url)... in a
controller, get the response, and then call your template with the result?

On Mon, May 2, 2016 at 5:42 PM, ismail-codar notifications@github.com
wrote:

My template like this:

fetch(url).then(function(response) {
response.json().then(function (@raw(SwaggerUtil.responseTypeName(entryValue.getJsonObject("responses")) == "void" ? "" : data)) {
resolve(@raw(SwaggerUtil.responseTypeName(entryValue.getJsonObject("responses")) == "void" ? "" : data));
});
})

But SwaggerUtil.responseTypeName(.. function calling 2 times.
Can I use it like following

@localvar rType = SwaggerUtil.responseTypeName(entryValue.getJsonObject("responses"))fetch(url).then(function(response) {
response.json().then(function (rType == "void" ? "" : data)) {
resolve(rType == "void" ? "" : data);
});
})


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#26

@ismail-codar
Copy link
Author

ismail-codar commented May 4, 2016

I looked at your code. It looks hard for me. I am not ANTLR family. Some developer documentation may be usefull.

I have used rocker in one project. A swagger schema to client generator template is here.

I want to share my views.I also would like to hear your thoughts.

Rocker is very fast and very easy to use. Thanks your work. Especially hot reloading support helped me while developing templates. Otherwise it takes a lot of time.

According to me {% %} like delimiter used template is more readable. For example

@args (String packageName, String className, Map itemMap)
class YourClass {
@if(some logic) {
some code
}
}

{ and } are intermixing and readability is falling.

Mostly templates aims multi language usability. Like https://mustache.github.io/ And rocker syntax looks can be adopted different platform. If the authors is not the purpose of this! embedding java codes in template feature would be very useful. Thinking wider than local variable assignment. Loops, if else conditions and variable declerations, assigments etc can be used with embedding java code.

@jjlauer
Copy link
Member

jjlauer commented May 5, 2016

Appreciate your feedback. It's cool you're using Rocker to help generate a
template that outputs a Java class.

In my opinion, templates should not have much actual logic. Rocker
supports for loops against your data model, but it sounds like you want for
loops running in embedded Java code as well. I think that only encourages
putting more logic in your templates than you should. Plus, templates can
already just call out to other Java code already, so you could pretty
easily put that type of logic in a standard Java utility class as well.
That encourages a better design in my opinion, since it makes unit testing
that kind of logic much easier. I can see the advantage of supporting
local variable assignment, but I'd be a hard sell on much other embedded
Java code like you suggested.

On Wed, May 4, 2016 at 1:07 AM, ismail-codar notifications@github.com
wrote:

I looked at your code. It looks hard to me. I am not antlr family. Some
developer documentation may be usefull.

I have used rocker in one project. A swagger schema to client generator
template is here
https://github.com/ismail-codar/codegen-maven/blob/master/src/main/resources/views/swagger/qbit/client/typescript/ServiceClient.rocker.html.

I want to share my views.I also would like to hear your thoughts.

Rocker is very fast and very easy to use. Thanks your work. Especially hot
reloading support helped me while developing templates. Otherwise it takes
a lot of time.

According to me {% %} like delimiter used template is more readable. For
example

@Args (String packageName, String className, Map itemMap)class YourClass {@if(some logic) {
some code
}
}

{ and } are intermixing and readability is falling.

Mostly templates aims multi language usability. Like
https://mustache.github.io/ And rocker syntax looks can be adopted
different platform. If the authors is not the purpose of this! embedding
java codes in template feature would be very useful. Thinking wider rather
than local variable assignment. Loops, if else conditions can be used with
embedding java code.


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#26 (comment)

@localvar
Copy link

localvar commented May 6, 2016

hmmm, just to check why I was @.

@jjlauer
Copy link
Member

jjlauer commented Jul 15, 2016

@ismail-codar latest version includes a new @with feature that lets you define variables.

@jjlauer jjlauer closed this as completed Jul 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants