Closed Vadorequest closed 9 years ago
I believe this cannot be merged as it yet, but I also believe you'll tell me what to change here, I don't like the global __config stuff, it was just a way to make it work quickly based on my own issue. I'm not sure what would be the best way to handle it though.
I cancel the PR, anyway it's never gonna get merged. I better to make my own implementation of ejs-locals
I've made too much changes anyway. https://github.com/Vadorequest/ejs-locals/tree/2.0.0
Load files using absolute path
I've added a way to load files (I tried with partials only) using an absolute path because the relative fails when loading files loaded from a file that has been itself loaded through
include/partial
functions. (somehow the path happens to be wrong, sometimes correct depending on which file I save in last and some other weird stuff)This is a feature that has been asked many times.
Examples
1. Absolute with global config
It is possible to set a
__config
global object that would look like this:partial('test/fixtures/partials/box.ejs', {_useAbsolute: true, box_title: 'test'})
Where
__config.path.base
would contain the basepath of the application, or the basepath from where you want to load files, but would be used only when using_useAbsolute: true
.2. Absolute with local config
Here you set the
_basePath
when calling the function, I don't like it because I want to use always the same config, or at least most of the time without having to set it each time (see 1. Absolute with global config)But I believe it can be useful from time to time.
3. Use relative path (old way, still compatible)
Design
I decided to use the
_
before the keys I've created to obviously avoid issues. I believe the use of_
shows the key is somehow private to the function for its own use. I was afraid to mess up existing app by using a common/usual key.Test
As I said, I didn't write proper test, I made my tests directly in debug mode. But I have installed my
ejs-locals
on another app to test it and it worked fine there too.