Skip to content

Commit

Permalink
add sd-pre
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Oct 13, 2013
1 parent c1206f8 commit b121a00
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/compiler.js
Expand Up @@ -11,7 +11,8 @@ var Emitter = require('./emitter'),
vmAttr,
repeatAttr,
partialAttr,
transitionAttr
transitionAttr,
preAttr

/*
* The DOM compiler
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'
}

/*
Expand Down
19 changes: 19 additions & 0 deletions test/unit/specs/directives.js
Expand Up @@ -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) {
Expand Down

0 comments on commit b121a00

Please sign in to comment.