Skip to content

Commit

Permalink
Add verbatim tag (#574)
Browse files Browse the repository at this point in the history
Address issue #571
  • Loading branch information
toptalo authored and dave-irvine committed Jul 3, 2018
1 parent 6a4ed35 commit 662d520
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/twig.logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
};


Expand Down Expand Up @@ -1247,6 +1249,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
}

];
Expand Down
10 changes: 10 additions & 0 deletions test/test.verbatim.js
Original file line number Diff line number Diff line change
@@ -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 }}');
});

});

0 comments on commit 662d520

Please sign in to comment.