Skip to content

Commit

Permalink
Merge branch 'master' of github.com:mde/ejs
Browse files Browse the repository at this point in the history
  • Loading branch information
mde committed May 25, 2020
2 parents 3bb3024 + 6f12023 commit fac1227
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 4 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Create release

on:
push:
tags:
- 'v*'

jobs:
create-release:
name: Create GitHub Release
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Get semver number
id: get_semver
env:
TAG_NAME: ${{ github.ref }}
run: echo "::set-output name=num::${TAG_NAME:11}"

- name: Create release on GitHub API
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: "v${{ steps.get_semver.outputs.num }}"
body: |
Version ${{ steps.get_semver.outputs.num }}
draft: false
prerelease: false
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ Therefore, we do not recommend using this shortcut.
output inside scriptlet tags.
- `async` When `true`, EJS will use an async function for rendering. (Depends
on async/await support in the JS runtime.
- `includer` Custom function to handle EJS includes, receives `(originalPath, parsedPath)`
parameters, where `originalPath` is the path in include as-is and `parsedPath` is the
previously resolved path. Should return an object `{ filename, template }`,
you may return only one of the properties, where `filename` is the final parsed path and `template`
is the included content.

This project uses [JSDoc](http://usejsdoc.org/). For the full public API
documentation, clone the repository and run `npm run doc`. This will run JSDoc
Expand Down
3 changes: 2 additions & 1 deletion jakefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ publishTask('ejs', ['build'], function () {
'ejs.js',
'ejs.min.js',
'lib/**',
'bin/**'
'bin/**',
'usage.txt'
]);
});

Expand Down
14 changes: 13 additions & 1 deletion lib/ejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ function getIncludePath(path, options) {
if (!includePath && Array.isArray(views)) {
includePath = resolvePaths(path, views);
}
if (!includePath) {
if (!includePath && typeof options.includer !== 'function') {
throw new Error('Could not find the include file "' +
options.escapeFunction(path) + '"');
}
Expand Down Expand Up @@ -307,6 +307,17 @@ function fileLoader(filePath){
function includeFile(path, options) {
var opts = utils.shallowCopy({}, options);
opts.filename = getIncludePath(path, opts);
if (typeof options.includer === 'function') {
var includerResult = options.includer(path, opts.filename);
if (includerResult) {
if (includerResult.filename) {
opts.filename = includerResult.filename;
}
if (includerResult.template) {
return handleCache(opts, includerResult.template);
}
}
}
return handleCache(opts);
}

Expand Down Expand Up @@ -515,6 +526,7 @@ function Template(text, opts) {
options.cache = opts.cache || false;
options.rmWhitespace = opts.rmWhitespace;
options.root = opts.root;
options.includer = opts.includer;
options.outputFunctionName = opts.outputFunctionName;
options.localsName = opts.localsName || exports.localsName || _DEFAULT_LOCALS_NAME;
options.views = opts.views;
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
"engine",
"ejs"
],
"version": "3.1.2",
"version": "3.1.3",
"author": "Matthew Eernisse <[email protected]> (http://fleegix.org)",
"license": "Apache-2.0",
"bin": {
"ejs": "./bin/cli.js"
},
"main": "./lib/ejs.js",
"jsdelivr": "ejs.min.js",
"unpkg": "ejs.min.js",
"repository": {
"type": "git",
"url": "git://github.com/mde/ejs.git"
Expand Down
30 changes: 30 additions & 0 deletions test/ejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,36 @@ suite('include()', function () {
fixture('include.html'));
});

test('include ejs with custom includer function', function () {
var file = 'test/fixtures/include-root.ejs';
var inc = function (original, prev) {
if (original.charAt(0) === '/') {
return {
filename: path.join(__dirname, 'fixtures', prev)
};
} else {
return prev;
}
};
assert.equal(ejs.render(fixture('include-root.ejs'), {pets: users}, {filename: file, delimiter: '@', includer: inc}),
fixture('include.html'));
});

test('include ejs with includer returning template', function () {
var file = 'test/fixtures/include-root.ejs';
var inc = function (original, prev) {
if (prev === '/include.ejs') {
return {
template: '<p>Hello template!</p>\n'
};
} else {
return prev;
}
};
assert.equal(ejs.render(fixture('include-root.ejs'), {pets: users}, {filename: file, delimiter: '@', includer: inc}),
fixture('hello-template.html'));
});

test('work when nested', function () {
var file = 'test/fixtures/menu.ejs';
assert.equal(ejs.render(fixture('menu.ejs'), {pets: users}, {filename: file}),
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/hello-template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>Hello template!</p>

0 comments on commit fac1227

Please sign in to comment.