From 5be59daad67c66c270b16056efbde36b86a3dbe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B8=D0=BA=D1=82=D0=BE=D1=80=20=D0=92=D0=B8=D0=BA?= =?UTF-8?q?=D1=82=D0=BE=D1=80?= Date: Tue, 3 Jul 2018 20:11:49 +0300 Subject: [PATCH] Add `verbatim` tag (#574) Address issue #571 --- src/twig.logic.js | 28 +++++++++++++++++++++++++++- test/test.verbatim.js | 10 ++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 test/test.verbatim.js diff --git a/src/twig.logic.js b/src/twig.logic.js index 18345bef..b9e64c12 100644 --- a/src/twig.logic.js +++ b/src/twig.logic.js @@ -39,7 +39,9 @@ module.exports = function (Twig) { embed: 'Twig.logic.type.embed', endembed: 'Twig.logic.type.endembed', 'with': 'Twig.logic.type.with', - endwith: 'Twig.logic.type.endwith' + endwith: 'Twig.logic.type.endwith', + verbatim: 'Twig.logic.type.verbatim', + endverbatim: 'Twig.logic.type.endverbatim' }; @@ -1196,6 +1198,30 @@ module.exports = function (Twig) { regex: /^endwith$/, next: [ ], open: false + }, + { + type: Twig.logic.type.verbatim, + regex: /^verbatim/, + next: [ + Twig.logic.type.endverbatim + ], + open: true, + + // Return the output without any parse + parse: function (token, context, chain) { + return { + chain: chain, + output: context + }; + } + }, + + // Add the {% endverbatim %} token + { + type: Twig.logic.type.endverbatim, + regex: /^endverbatim$/, + next: [ ], + open: false } ]; diff --git a/test/test.verbatim.js b/test/test.verbatim.js new file mode 100644 index 00000000..263f82c8 --- /dev/null +++ b/test/test.verbatim.js @@ -0,0 +1,10 @@ +var Twig = (Twig || require("../twig")).factory(), + twig = twig || Twig.twig; + +describe("Twig.js Verbatim ->", function () { + + it("should return raw content", function () { + twig({data: '{% verbatim %}{{ variable }}{% endverbatim %}'}).render({ 'variable': 42 }).should.equal('{{ variable }}'); + }); + +});