From 3b96bd43deae5c060d9db164fe7a0deb06ec66fa Mon Sep 17 00:00:00 2001 From: Leonardo Matos Date: Wed, 6 May 2020 14:31:16 -0300 Subject: [PATCH 01/12] fix(pkg): fix entry file for browser (compiled) Fix to handle `import ejs from 'ejs'` within bundlers such as Webpack --- package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/package.json b/package.json index 1f7fc996..5c4753e6 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,9 @@ "ejs": "./bin/cli.js" }, "main": "./lib/ejs.js", + "browser": "ejs.min.js", + "jsdelivr": "ejs.min.js", + "unpkg": "ejs.min.js", "repository": { "type": "git", "url": "git://github.com/mde/ejs.git" From f27623116d113d2cd6af2f6298b010f72e62ebcf Mon Sep 17 00:00:00 2001 From: Leonardo Matos Date: Thu, 14 May 2020 01:56:46 -0300 Subject: [PATCH 02/12] feat(includer): implementing 'includer' function to options https://github.com/mde/ejs/issues/500 --- lib/ejs.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/ejs.js b/lib/ejs.js index bb4e1bfb..f6addc39 100755 --- a/lib/ejs.js +++ b/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,15 @@ 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; + } + return handleCache(opts, includerResult.template); + } + } return handleCache(opts); } From b525a777f690c9c9882071c7f2bd45e8014269a3 Mon Sep 17 00:00:00 2001 From: Leonardo Matos Date: Thu, 14 May 2020 02:17:55 -0300 Subject: [PATCH 03/12] test(includer): unit tests for includer function option --- test/ejs.js | 30 ++++++++++++++++++++++++++++++ test/fixtures/hello-template.html | 1 + 2 files changed, 31 insertions(+) create mode 100644 test/fixtures/hello-template.html diff --git a/test/ejs.js b/test/ejs.js index 5a7e7d4e..aee31350 100755 --- a/test/ejs.js +++ b/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 (url, prev) { + if (url.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 (url, prev) { + if (prev === '/include.ejs') { + return { + template: '

Hello template!

\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}), diff --git a/test/fixtures/hello-template.html b/test/fixtures/hello-template.html new file mode 100644 index 00000000..c0de8a52 --- /dev/null +++ b/test/fixtures/hello-template.html @@ -0,0 +1 @@ +

Hello template!

From 633b5fbfb9e3aaeb31040fa0d5ee4cb9eb44f9d8 Mon Sep 17 00:00:00 2001 From: Leonardo Matos Date: Thu, 14 May 2020 02:18:30 -0300 Subject: [PATCH 04/12] fix(includer): fix handling includer option --- lib/ejs.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/ejs.js b/lib/ejs.js index f6addc39..104aadad 100755 --- a/lib/ejs.js +++ b/lib/ejs.js @@ -313,7 +313,9 @@ function includeFile(path, options) { if (includerResult.filename) { opts.filename = includerResult.filename; } - return handleCache(opts, includerResult.template); + if (includerResult.template) { + return handleCache(opts, includerResult.template); + } } } return handleCache(opts); @@ -524,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; From 1fb829a935541bf37a6af6fda0a4a76e0c954207 Mon Sep 17 00:00:00 2001 From: Leonardo Matos Date: Thu, 14 May 2020 02:25:19 -0300 Subject: [PATCH 05/12] docs(includer): simple includer function reference on options --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 74524ac3..23b291d7 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,10 @@ 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 `(url, prev)` parameters, + where `url` is the path in include as-is and `prev` 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 From 8da7213eb488c4467ce20fc2a0e4b95e4ae84424 Mon Sep 17 00:00:00 2001 From: Leonardo Matos Date: Sat, 16 May 2020 18:02:37 -0300 Subject: [PATCH 06/12] test(includer): rename first param (url -> original) --- test/ejs.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/ejs.js b/test/ejs.js index aee31350..1052e3b5 100755 --- a/test/ejs.js +++ b/test/ejs.js @@ -1001,8 +1001,8 @@ suite('include()', function () { test('include ejs with custom includer function', function () { var file = 'test/fixtures/include-root.ejs'; - var inc = function (url, prev) { - if (url.charAt(0) === '/') { + var inc = function (original, prev) { + if (original.charAt(0) === '/') { return { filename: path.join(__dirname, 'fixtures', prev) }; @@ -1016,8 +1016,8 @@ suite('include()', function () { test('include ejs with includer returning template', function () { var file = 'test/fixtures/include-root.ejs'; - var inc = function (url, prev) { - if (prev === '/include.ejs') { + var inc = function (original, prev) { + if (original === '/include.ejs') { return { template: '

Hello template!

\n' }; From 247c0e2b41a4efcb342260a1ed3d39803e3e63d9 Mon Sep 17 00:00:00 2001 From: Leonardo Matos Date: Sat, 16 May 2020 18:03:12 -0300 Subject: [PATCH 07/12] docs(includer): edit function parameters names (originalPath, parsedPath) to be more descriptive --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 23b291d7..df083546 100644 --- a/README.md +++ b/README.md @@ -90,10 +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 `(url, prev)` parameters, - where `url` is the path in include as-is and `prev` 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. + - `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 From 6e2196824dbb50025e2ac822f6adbebb9d48b8dc Mon Sep 17 00:00:00 2001 From: Leonardo Matos Date: Sat, 16 May 2020 18:04:17 -0300 Subject: [PATCH 08/12] test(includer): rename first param (url -> original) --- test/ejs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/ejs.js b/test/ejs.js index 1052e3b5..5360499d 100755 --- a/test/ejs.js +++ b/test/ejs.js @@ -1017,7 +1017,7 @@ suite('include()', function () { test('include ejs with includer returning template', function () { var file = 'test/fixtures/include-root.ejs'; var inc = function (original, prev) { - if (original === '/include.ejs') { + if (prev === '/include.ejs') { return { template: '

Hello template!

\n' }; From d434f459872eaf97143a7e1cdb853a80f06b13c3 Mon Sep 17 00:00:00 2001 From: mde Date: Sat, 16 May 2020 23:47:08 -0700 Subject: [PATCH 09/12] Added usage.txt to release package --- jakefile.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/jakefile.js b/jakefile.js index 9b7c70ee..0eebf2e0 100644 --- a/jakefile.js +++ b/jakefile.js @@ -64,7 +64,8 @@ publishTask('ejs', ['build'], function () { 'ejs.js', 'ejs.min.js', 'lib/**', - 'bin/**' + 'bin/**', + 'usage.txt' ]); }); From 8b774bb97fe0715b42526e021f0b67854001eb01 Mon Sep 17 00:00:00 2001 From: mde Date: Sat, 16 May 2020 23:56:14 -0700 Subject: [PATCH 10/12] Fix broken browserification --- package-lock.json | 2 +- package.json | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 94e7cc2f..af51801f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "ejs", - "version": "3.1.0", + "version": "3.1.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 5c4753e6..6253d691 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,6 @@ "ejs": "./bin/cli.js" }, "main": "./lib/ejs.js", - "browser": "ejs.min.js", "jsdelivr": "ejs.min.js", "unpkg": "ejs.min.js", "repository": { From 661d848eadcd85117f655b5f8327f13ae2cc85da Mon Sep 17 00:00:00 2001 From: mde Date: Sat, 16 May 2020 23:58:57 -0700 Subject: [PATCH 11/12] Version 3.1.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6253d691..5d140238 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "engine", "ejs" ], - "version": "3.1.2", + "version": "3.1.3", "author": "Matthew Eernisse (http://fleegix.org)", "license": "Apache-2.0", "bin": { From 9875f815877ce7a3be6939fa0c3d57e3d1d833de Mon Sep 17 00:00:00 2001 From: Leonardo Matos Date: Sun, 17 May 2020 16:54:52 -0300 Subject: [PATCH 12/12] ci(create-release): auto setup github release after version tag --- .github/workflows/create-release.yml | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/create-release.yml diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml new file mode 100644 index 00000000..f46281ca --- /dev/null +++ b/.github/workflows/create-release.yml @@ -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