Browse Source

support filters in partials (close #735)

Evan You 11 years ago
parent
commit
5288d7f1bb
2 changed files with 24 additions and 0 deletions
  1. 4 0
      src/directives/partial.js
  2. 20 0
      test/unit/specs/directives/partial_spec.js

+ 4 - 0
src/directives/partial.js

@@ -39,6 +39,10 @@ module.exports = {
     var partial = this.vm.$options.partials[id]
     var partial = this.vm.$options.partials[id]
     _.assertAsset(partial, 'partial', id)
     _.assertAsset(partial, 'partial', id)
     if (partial) {
     if (partial) {
+      var filters = this.filters && this.filters.read
+      if (filters) {
+        partial = _.applyFilters(partial, filters, this.vm)
+      }
       this.compile(templateParser.parse(partial, true))
       this.compile(templateParser.parse(partial, true))
     }
     }
   }
   }

+ 20 - 0
test/unit/specs/directives/partial_spec.js

@@ -111,5 +111,25 @@ if (_.inBrowser) {
       })
       })
     })
     })
 
 
+    it('partial with filters', function () {
+      var vm = new Vue({
+        el: el,
+        template: '<div>{{>test | replace}}</div>',
+        partials: {
+          test: '{{a}}'
+        },
+        data: {
+          a: 'A',
+          b: 'B'
+        },
+        filters: {
+          replace: function () {
+            return '{{b}}'
+          }
+        }
+      })
+      expect(el.innerHTML).toBe('<div>' + wrap('B') + '</div>')
+    })
+
   })
   })
 }
 }