Evan You 12 лет назад
Родитель
Сommit
b121a00a95
2 измененных файлов с 25 добавлено и 3 удалено
  1. 6 3
      src/compiler.js
  2. 19 0
      test/unit/specs/directives.js

+ 6 - 3
src/compiler.js

@@ -11,7 +11,8 @@ var Emitter     = require('./emitter'),
     vmAttr,
     repeatAttr,
     partialAttr,
-    transitionAttr
+    transitionAttr,
+    preAttr
 
 /*
  *  The DOM compiler
@@ -182,7 +183,8 @@ CompilerProto.compile = function (node, root) {
     var compiler = this
     if (node.nodeType === 1) {
         // a normal node
-        var repeatExp    = node.getAttribute(repeatAttr),
+        if (node.hasAttribute(preAttr)) return
+        var repeatExp  = node.getAttribute(repeatAttr),
             vmId       = node.getAttribute(vmAttr),
             partialId  = node.getAttribute(partialAttr)
         // we need to check for any possbile special directives
@@ -589,10 +591,11 @@ CompilerProto.destroy = function () {
  */
 function refreshPrefix () {
     var prefix     = config.prefix
-    repeatAttr       = prefix + '-repeat'
+    repeatAttr     = prefix + '-repeat'
     vmAttr         = prefix + '-viewmodel'
     partialAttr    = prefix + '-partial'
     transitionAttr = prefix + '-transition'
+    preAttr        = prefix + '-pre'
 }
 
 /*

+ 19 - 0
test/unit/specs/directives.js

@@ -537,6 +537,25 @@ describe('UNIT: Directives', function () {
 
     })
 
+    describe('pre', function () {
+        
+        it('should skip compilation', function () {
+            var testId = 'pre-test'
+            mock(testId, '<span sd-pre><strong>{{lol}}</strong><a sd-text="hi"></a></span>')
+            var t = new Seed({
+                el: '#' + testId,
+                scope: {
+                    lol: 'heyhey',
+                    hi: 'hohoho'
+                }
+            })
+            assert.strictEqual(t.$el.querySelector('strong').textContent, '{{lol}}')
+            assert.strictEqual(t.$el.querySelector('a').textContent, '')
+            assert.ok(t.$el.querySelector('a').hasAttribute('sd-text'))
+        })
+
+    })
+
 })
 
 function mockDirective (dirName, tag, type) {