RandomEtc/ejs-locals — pull request #45 by Vadorequest (2014-10-10 20:17:54+00:00)
Title: Load files (partials, ...) using absolute path

# 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.

All examples are at the bottom of the `index.js`, I didn't understand how to create a proper test for this even if I added a file to test. (`box.ejs`). **Anyway I explain examples here too.**

## Examples

### 1. Absolute with global config
It is possible to set a `__config` global object that would look like this:
```
var __config = {
path: {
base: __dirname
}
};
```

where `__config.path.base` would contain the basepath of the application, or the basepath from where you want to load files, but only when using `_useAbsolute: true`.

### 2. Absolute with local config

```
// Use the absolute path provided by _basePath
partial('test/fixtures/partials/box.ejs', {_basePath: __dirname, box_title: 'test'})
```
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)*

```
// use the relative path from the current directory.
partial('test/fixtures/partials/box.ejs', {box_title: 'test'})
```

## 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.