[Proposal] Use standard structure for ejs
See original GitHub issueOverview of the issue
Today, it’s kind of complicated to contribute to gen-jhipster, every pattern uses its own way for putting conditionals and loop so that patterns are hardly readable. I suggest to make a pass on every of them applying the same formatting standards
Motivation for or Use Case
This would ease pattern detection (to extract and reuse some code parts) as well as ease contribution. Also I think that this will ease modularization work. Using a no-brainer approach to manipulate ejs will help to concentrate only on the added value of jhipster: the generated code (as opposed to code format, which I find difficult to deal with in some patterns.
Reproduce the error
Take a look at one pattern: some conditional are inlined (using <% %>
and some other aren’t, using <%_ _%>
). There are some mental exercises to make in order to understand.
I propose to systematically put conditional and loops alone on a line (using the right indentation), and using a line slurp when code need to to be inlined (empty <% -%>
)
Related issues
No
Suggest a Fix
I can take some time to (incrementally) format all the generator-jhipster code base in order to use the same pattern everywhere (see below)
JHipster Version(s)
4.10.2
JHipster configuration
Not concerned.
Entity configuration(s) entityName.json
files generated in the .jhipster
directory
not concerned
Browsers and Operating System
Intellij on MacOs, but does it matter 😉
- [X ] Checking this box is mandatory (this is just to show you read everything)
Let’s take the entity/templates/server/src/main/java/package/common/delete_template.ejs as example
<% if (!viaService) {
if (databaseType === 'sql' || databaseType === 'mongodb' || databaseType === 'couchbase') { %>
<%= entityInstance %>Repository.delete(id);<% } %><% if (databaseType === 'cassandra') { %>
<%= entityInstance %>Repository.delete(UUID.fromString(id));<% } %><% if (searchEngine === 'elasticsearch') { %><% if (databaseType === 'sql' || databaseType === 'mongodb' || databaseType === 'couchbase') { %>
<%= entityInstance %>SearchRepository.delete(id);<% } %><% if (databaseType === 'cassandra') { %>
<%= entityInstance %>SearchRepository.delete(UUID.fromString(id));<% } %><% }
} else { %>
<%= entityInstance %>Service.delete(id);<% } %>
it will become:
<%_ if (!viaService) { _%>
<%_ if (databaseType === 'sql' || databaseType === 'mongodb' || databaseType === 'couchbase') { _%>
<%= entityInstance %>Repository.delete(id<% -%>// I volontary put the parenthesis and caret after the conditional to illustrate the case, but shouldn't be done like this
<%_ } else if (databaseType === 'cassandra') { _%>
<%= entityInstance %>Repository.delete(UUID.fromString(id)<% -%>
<%_ } _%>);
<%_ if (searchEngine === 'elasticsearch') { _%>
<%_ if (databaseType === 'sql' || databaseType === 'mongodb' || databaseType === 'couchbase') { _%>
<%= entityInstance %>SearchRepository.delete(id);
<%_ } _%>
<%_ if (databaseType === 'cassandra') { _%>
<%= entityInstance %>SearchRepository.delete(UUID.fromString(id));
<%_ } _%>
<%_ } _%>
<%_} else { _%>
<%= entityInstance %>Service.delete(id);
<%_ } _%>
Which is a little more verbsose, but IMHO easier to read.
Are you interested by this contrib?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:5 (5 by maintainers)
I thought of doing this multiple times and even refactored quite a bit of it over the time, but to completely rewrite everything is just too much effort as we have too many template files and the chance for a mistake is very high. As you said if we have a solid automated way of testing before and after of the generated templates for various options then we could attempt this otherwise I’ll prefer to continue changing them gradually as today.
Thanks & Regards, Deepu
On Tue, Nov 14, 2017 at 10:47 AM, Julien Dubois notifications@github.com wrote:
So, I think we can close this issue, as it is covered by #6687 and #6379