Skip to content
This repository has been archived by the owner on May 20, 2024. It is now read-only.

Commit

Permalink
[modules] add |forceescape Nunjucks filter
Browse files Browse the repository at this point in the history
Temporal solution of mozilla/nunjucks#782
  • Loading branch information
ArmorDarks committed Oct 27, 2016
1 parent 61f24b2 commit c1f0caf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
### Removed
- [sass] Removed all `$ekzo-enable-*` options in favor of modular imports. Now just comment out import of part, which you don't want to use.

### Added
- [modules] Added `|forceescape` filter for Nunjucks as temporal solution of https://github.com/mozilla/nunjucks/issues/782

### Changed
- [sass] Updated Ekzo to version 2.0.0.
- [misc] Renamed Ekzo submodule directory from `ekzo.sass` to `ekzo`.
Expand Down
13 changes: 12 additions & 1 deletion modules/nunjucks-extensions.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ numbro = require('numbro')
moment = require('moment')
smartPlurals = require('smart-plurals')
{ join } = require('path')
{ escape } = require('nunjucks/src/lib')

module.exports = (env, grunt, currentLocale, numberFormat, currencyFormat) ->

Expand Down Expand Up @@ -249,4 +250,14 @@ module.exports = (env, grunt, currentLocale, numberFormat, currencyFormat) ->
for property, value of input
spreaded += "#{property}='#{value}' "

return spreaded
return spreaded

###*
* Same as Nunjucks `|escape` filter, but enforces escaping in any case, even if input previously has been
* marked as `safe`. Can be applied on `caller()` of `macro` to enforce escaping of its content
* @todo Temporal solution for https://github.com/mozilla/nunjucks/issues/782
* @param {string|object} input Entity in to be escaped
* @return {string} Escaped entity
* @example {{ caller()|forceescape }} -> <p>Example text</p>
###
env.addFilter 'forceescape', (input) -> escape(input)

0 comments on commit c1f0caf

Please sign in to comment.