Skip to content

Conversation

@tcha-tcho
Copy link

Hello!

This small change will include absolute paths on 'includes'. Using <% include 'strings' %> ejs will use the relative path to the project root instead of relative to the file. Tests, Readme, and other changes were made.

Thank you for every thing, this code is great! :)

Best Regards
Tcha-Tcho

@ForbesLindesay
Copy link
Contributor

If you started absolute paths with / and then also based them off of the dirname option rather than path.dirname(filename) then it would be consistent with the way jade supports this :)

@tcha-tcho
Copy link
Author

Good point @ForbesLindesay !! :) I did the change! Much better! Thanks!

lib/ejs.js Outdated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is equivalent to if (name[0] === '/') no need to match against a regex.

I also think instead of process.cwd() it's better to have resolveInclude take an extra argument of basedir and pass options.basedir as the value of that argument.

The code we use for jade is: https://github.com/visionmedia/jade/blob/master/lib/parser.js#L421-L428

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That way it's up to the user to specify what the "root" of an application is, which might not always be the current working directory.

…in different path of current working directory of the process - jade pattern.
@tcha-tcho
Copy link
Author

Hi @ForbesLindesay ! I followed your suggestions with the difference of instead of raise an error we use the working directory as default. Maybe this pattern could be applied to jade too. What do you think?

@ForbesLindesay
Copy link
Contributor

Almost there, but it should be basedir not baseDir to match up with jade. The reasoning behind using basedir is that it matches the filename option that is already pretty standard among a huge number of templating engines.

Personally I don't like defaulting to process.cwd(). For most use cases in node, using the current working directory is approximately the same as using a random directory. There is no guarantee it corresponds to anything. In addition to this, it's not difficult for the user to explicitly set the basedir value to process.cwd().

@aysiscore
Copy link

This does not work. I installed EJS but it does not accept absolute paths. What do I need to do?

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

Successfully merging this pull request may close these issues.

3 participants