How to use the setFilter function from swig

Find comprehensive JavaScript swig.setFilter code examples handpicked from public code repositorys.

62
63
64
65
66
67
68
69
70
71
swig.setExtension('i18n', function(ctx, tag, default_translation) {
  var language = ctx.i18n ? ctx.i18n.language : 'unknown';
  return translate(tag, language, default_translation);
});

swig.setFilter('i18n', function(tag, language, defaultTranslation, replacementPairs) {
  var translation = translate(tag, language, defaultTranslation);
  _.each(replacementPairs, function(val, key) {
    translation = translation.replace(new RegExp(key, "g"),val);
  });
fork icon4
star icon4
watch icon0

2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
*
* @example
* // This filter will disable auto-escaping on its output:
* function bazbop (input) { return input; }
* bazbop.safe = true;
* swig.setFilter('bazbop', bazbop);
* // => {{ "<p>"|bazbop }}
* // => <p>
*
* @param {*} input Input argument, automatically sent from Swig's built-in parser.
fork icon0
star icon1
watch icon0

+ 5 other calls in file

41
42
43
44
45
46
47
48
49
50
});
swig.setFilter('typeof', function (input, type) {
    if (typeof type == 'undefined') return typeof input;
    return typeof input == type;
});
swig.setFilter('inArray', function (array, obj) {
    if (typeof array !== 'object') return false;
    return array.inArray(obj);
});
swig.setFilter('array_key_exists', function (array, key) {
fork icon0
star icon0
watch icon0

+ 3 other calls in file