Skip to content

Commit

Permalink
Add verbatim tag (twigjs#574)
Browse files Browse the repository at this point in the history
Address issue twigjs#571
  • Loading branch information
toptalo authored and willrowe committed May 11, 2019
1 parent 8ffcd6c commit 5be59da
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 @@ -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
}

];
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 5be59da

Please sign in to comment.