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.

[feature] include should preserve indention

See original GitHub issue

If someone does

<p>
  <%- include('other.ejs') %>
</p>

and other.ejs is

<div>
  <b>HELLO</b>
</div>

Then it should look like

<p>
  <div>
    <b>HELLO</b>
  </div>
</p>

Instead of

<p>
  <div>
  <b>HELLO</b>
</div>
</p>

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:13
  • Comments:17

github_iconTop GitHub Comments

7reactions
RyanZimcommented, Jun 13, 2016

BTW, you could also write your own function, like this:

<%
function indent(text, depth) {
  var output='';
  text.split("\n").foreach(function(line, num){
    // To avoid indenting the first line
    if(num>0){
      for(var i=0;i<depth;i++){
        line=line+' ';
      }
    }
    output+=line;
  });
}
-%>

Then you could do something like <%- indent(include('filename'), 4) %> if you wanted the include to be indented 4 spaces.

4reactions
TimothyGucommented, Jun 14, 2016

@SBoudrias said:

FWIW, the reason was keeping compatibility with underscore templates.

Hmm. https://github.com/mde/ejs/issues/55#issuecomment-72275752.

Also, I don’t agree ejs doesn’t care about indentation (also for performance reason is total bollocks come on). Right now you have a ton of whitespace and indentation related features like whitespace trim or the slurp mode.

Just wanted to apologize for my tone in my last comment. I just realized that EJS right now was very different from the EJS I worked on a year ago.

A year ago, I was optimizing EJS as if it was a finished product, i.e. literally to the last inch, including replace costly .replace() calls with less costly ones and with even less ones. At the end, the template performance was on par with the fastest template engines out there, but the compilation performance still not so.

I approached this issue as if EJS still cared about compilation performance, but seems like we don’t any more. More specifically, features like <%_ _%> came along that basically added to the already slow compilation process with a bunch of unconditional .replace calls.

So again, I apologize. EJS has become something I didn’t think it was, and that anachronism in my head led to my comment.

On a more technical side, yes, those features might be doable, but will be hard to implement nevertheless. If dynamic inclusion is used, then a run-time solution like the one posed by @RyanZim would be much easier to use.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to preserve whitespace indentation of text enclosed in ...
PRE is intended to preserve whitespace exactly as it appears (unless altered by white-space in CSS, which doesn't have enough flexibility to support ......
Read more >
Preserve Indentation when inserting variable lists in a template
Say I have an octopus variable that has a list of items in it. For example, the variable is called ContainerEnvironmentVariables and it...
Read more >
Adjust indents and spacing - Microsoft Support
Use Paragraph settings to change indentation, line spacing, and alignment.
Read more >
Google Docs: Using Indents and Tabs - GCF Global
A great way to draw attention to important areas within your document is to add an indent or tab. There are several ways...
Read more >
Indentation | IntelliJ IDEA Documentation - JetBrains
Click the widget and select Configure Indents for 'Language'. · In the dialog that opens, you can change settings for tabs and indents...
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