Skip to content

Commit

Permalink
Merge pull request #675 from leviy/master_implement-deprecated-tag
Browse files Browse the repository at this point in the history
Add support for 'deprecated' tag
  • Loading branch information
RobLoach authored Nov 1, 2019
2 parents 74073f5 + a3f0fc0 commit 8270a18
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/twig.logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ 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',
deprecated: 'Twig.logic.type.deprecated'
};

// Regular expressions for handling logic tokens.
Expand Down Expand Up @@ -1272,6 +1273,25 @@ module.exports = function (Twig) {
regex: /^endwith$/,
next: [],
open: false
},
{
/**
* Deprecated type logic tokens.
*
* Format: {% deprecated 'Description' %}
*/
type: Twig.logic.type.deprecated,
regex: /^deprecated\s+(.+)$/,
next: [],
open: true,
compile(token) {
console.warn('Deprecation notice: ' + token.match[1]);

return token;
},
parse() {
return {};
}
}

];
Expand Down
11 changes: 11 additions & 0 deletions test/test.tags.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const Twig = require('../twig').factory();
const sinon = require('sinon');

const {twig} = Twig;

Expand Down Expand Up @@ -53,4 +54,14 @@ describe('Twig.js Tags ->', function () {
'<strong>twig.js</strong>'
);
});

it('should support deprecated tag and show a console warn message', function () {
let consoleSpy = sinon.spy(console, 'warn');

twig({
data: '{% deprecated \'`foo` is deprecated use `bar`\' %}'
}).render();

consoleSpy.should.be.calledWith('Deprecation notice: \'`foo` is deprecated use `bar`\'');
});
});

0 comments on commit 8270a18

Please sign in to comment.