question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Proposal] Use standard structure for ejs

See original GitHub issue
Overview 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:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
deepu105commented, Nov 14, 2017

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:

XML and Gradle are not big issues: we don’t have a lot of them, and using <%_ _%> is good enough for them. My real issue with Prettier is that we need Java support, indeed. That’s probably a lot of work, but that would be so useful for us.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jhipster/generator-jhipster/issues/6683#issuecomment-344202288, or mute the thread https://github.com/notifications/unsubscribe-auth/ABDlF58fX3uibmckVATCi5KDqryoYHnqks5s2WHAgaJpZM4Qc_xH .

0reactions
Tcharlcommented, Nov 15, 2017

So, I think we can close this issue, as it is covered by #6687 and #6379

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Use EJS to Template Your Node Application
Step 1 — Configuring with server.js ... With all of the dependencies installed, let's configure the application to use EJS and set up...
Read more >
Folder Structure for NodeJS & ExpressJS project
That's a pretty standard scenario for any application out there. ... Here's how I structure my NodeJS App. I'll be explaining some of...
Read more >
Bulletproof node.js project architecture 🛡️ - Softwareontheroad
Here is the node.js project structure that I'm talking about. I use this in every node.js REST API service that I build, let's...
Read more >
adding .css file to ejs - node.js - Stack Overflow
// using app.use to serve up static CSS files in public/assets/ folder when /public link is called in ejs files // app.use(" ...
Read more >
Better Express Routing & Architecture for Node.js
Given that Express is one of the most popular web frameworks for NodeJS, I am going to use this as the main basis...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found