mirror of
https://github.com/CryptKeeperZK/ejs.git
synced 2026-01-09 07:27:56 -05:00
Merge branch 'master' of github.com:mde/ejs
This commit is contained in:
34
.github/workflows/create-release.yml
vendored
Normal file
34
.github/workflows/create-release.yml
vendored
Normal file
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -64,7 +64,8 @@ publishTask('ejs', ['build'], function () {
|
||||
'ejs.js',
|
||||
'ejs.min.js',
|
||||
'lib/**',
|
||||
'bin/**'
|
||||
'bin/**',
|
||||
'usage.txt'
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
14
lib/ejs.js
14
lib/ejs.js
@@ -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) + '"');
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ejs",
|
||||
"version": "3.1.0",
|
||||
"version": "3.1.2",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
||||
@@ -6,13 +6,15 @@
|
||||
"engine",
|
||||
"ejs"
|
||||
],
|
||||
"version": "3.1.2",
|
||||
"version": "3.1.3",
|
||||
"author": "Matthew Eernisse <mde@fleegix.org> (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"
|
||||
|
||||
30
test/ejs.js
30
test/ejs.js
@@ -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}),
|
||||
|
||||
1
test/fixtures/hello-template.html
vendored
Normal file
1
test/fixtures/hello-template.html
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<p>Hello template!</p>
|
||||
Reference in New Issue
Block a user