diff --git a/History.md b/History.md index 6284863..0f8a0bc 100644 --- a/History.md +++ b/History.md @@ -1,3 +1,8 @@ +unreleased +========== + + * switch to {{ }} for templates. This is more versatile. + 1.1.1 / 2014-05-13 ========== diff --git a/lib/utils.js b/lib/utils.js index 6a9a858..732e693 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -37,7 +37,7 @@ var props = function(str) { exports.interpolationProps = function(str) { var m; var arr = []; - var re = /\{([^}]+)\}/g; + var re = /\{\{([^}]+)\}\}/g; while (m = re.exec(str)) { var expr = m[1]; @@ -57,7 +57,7 @@ exports.interpolationProps = function(str) { */ exports.interpolate = function(str, fn){ - return str.replace(/\{([^}]+)\}/g, function(_, expr){ + return str.replace(/\{\{([^}]+)\}\}/g, function(_, expr){ var cb = cache[expr]; if (!cb) cb = cache[expr] = compile(expr); var val = fn(expr.trim(), cb); @@ -74,7 +74,7 @@ exports.interpolate = function(str, fn){ */ exports.hasInterpolation = function(str) { - return ~str.indexOf('{'); + return ~str.indexOf('{{'); }; /** diff --git a/package.json b/package.json index 9207f94..fc9712c 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "clone": "clone-component" }, "devDependencies": { - "zuul": "~1.5.4", + "zuul": "~1.6.4", "clone-component": "component/clone#acfb79aa", "better-assert": "~1.0.0", "mocha": "~1.17.0" diff --git a/test/attr-interpolation.js b/test/attr-interpolation.js index 43f3d5b..a2ee11c 100644 --- a/test/attr-interpolation.js +++ b/test/attr-interpolation.js @@ -5,21 +5,21 @@ var reactive = require('../'); describe('attr interpolation', function(){ it('should support initialization', function(){ - var el = domify(''); + var el = domify(''); var user = { id: '1234' }; var view = reactive(el, user); assert('/download/1234' == el.getAttribute('href')); }) it('should ignore whitespace', function(){ - var el = domify(''); + var el = domify(''); var user = { id: '1234' }; var view = reactive(el, user); assert('/download/1234' == el.getAttribute('href')); }) it('should react to changes', function(){ - var el = domify(''); + var el = domify(''); var user = { id: '1234' }; var view = reactive(el, user); @@ -30,7 +30,7 @@ describe('attr interpolation', function(){ }) it('should support multiple attributes', function(){ - var el = domify('Download {file}'); + var el = domify('Download {{file}}'); var user = { id: '1234' }; var view = reactive(el, user); @@ -43,7 +43,7 @@ describe('attr interpolation', function(){ }) it('should support multiple properties', function(){ - var el = domify(''); + var el = domify(''); var user = { id: '1234', file: 'something' }; var view = reactive(el, user); diff --git a/test/each.js b/test/each.js index 1731121..443adee 100644 --- a/test/each.js +++ b/test/each.js @@ -5,13 +5,13 @@ var reactive = require('../'); describe('each', function(){ it('empty should not fail', function(){ - var el = domify(''); + var el = domify(''); var view = reactive(el); assert.equal(el.children.length, 0); }) it('predefined array should work', function(){ - var el = domify(''); + var el = domify(''); var model = { todos: ['milk', 'cereal', 'apples'] @@ -26,7 +26,7 @@ describe('each', function(){ }) it('setting property should work', function(){ - var el = domify(''); + var el = domify(''); var model = { todos: ['candy'] @@ -46,7 +46,7 @@ describe('each', function(){ }) it('should not set after destroy', function(){ - var el = domify(''); + var el = domify(''); var model = { todos: ['candy'] }; var view = reactive(el, model); @@ -63,7 +63,7 @@ describe('each', function(){ }) it('should not react to changes of an old array any more', function () { - var el = domify(''); + var el = domify(''); var array = ['candy']; var model = { todos: array }; @@ -81,7 +81,7 @@ describe('each', function(){ }) it('accessing properties', function(){ - var el = domify(''); + var el = domify(''); var model = { todos: [ @@ -100,7 +100,7 @@ describe('each', function(){ }) it('calls event handlers in the context of child reactive', function (done) { - var el = domify(''); + var el = domify(''); var model = { todos: [ @@ -126,7 +126,7 @@ describe('each', function(){ }); it('Array#push', function(){ - var el = domify(''); + var el = domify(''); var model = { todos: [] @@ -144,7 +144,7 @@ describe('each', function(){ }) it('Array#unshift', function(){ - var el = domify(''); + var el = domify(''); var model = { todos: [] @@ -165,7 +165,7 @@ describe('each', function(){ }) it('Array#splice', function(){ - var el = domify(''); + var el = domify(''); var model = { todos: [] @@ -200,7 +200,7 @@ describe('each', function(){ // test that items are put into the proper place in the dom it('multiple arrays', function(){ - var el = domify(''); + var el = domify(''); var model = { todos: [], @@ -226,7 +226,7 @@ describe('each', function(){ // nothing on the each binding line should be evaluated before the each has // taken over the line it('other bindings', function(){ - var el = domify('
{name}
'); + var el = domify('
{{name}}
'); var model = { todos: [{ @@ -243,7 +243,7 @@ describe('each', function(){ }) it('other bindings - flipped', function(){ - var el = domify('
{name}
'); + var el = domify('
{{name}}
'); var model = { todos: [{ diff --git a/test/reactive.js b/test/reactive.js index ac40810..1ea2e06 100644 --- a/test/reactive.js +++ b/test/reactive.js @@ -64,7 +64,7 @@ describe('reactive(el, obj)', function(){ }) it('should support nested properties', function(){ - var el = domify('
{name.first} {name.last}
'); + var el = domify('
{{name.first}} {{name.last}}
'); var user = { name: { @@ -79,15 +79,15 @@ describe('reactive(el, obj)', function(){ it('should support deeply nested properties', function(){ var model = { foo: { bar: { baz: { rofl: 'ok' } } } }; - var view = reactive(domify('
{ foo.bar.baz.rofl }
'), model); + var view = reactive(domify('
{{ foo.bar.baz.rofl }}
'), model); assert('ok' == view.el.textContent); }) it('should not fail for undefined properties', function(){ - var view = reactive(domify('
{ foo }
'), {}); + var view = reactive(domify('
{{ foo }}
'), {}); assert.equal('', view.el.textContent); - var view = reactive(domify('
{ foo.bar }
'), {}); + var view = reactive(domify('
{{ foo.bar }}
'), {}); assert.equal('', view.el.textContent); }); @@ -126,7 +126,7 @@ describe('.set(prop, value)', function(){ }); it('should update bindings from an object', function(){ - var el = domify('

{name}

{age}

'); + var el = domify('

{{name}}

{{age}}

'); function User(name, age) { this.name = name; @@ -216,7 +216,7 @@ describe('data-visible', function(){ }) it('should update on array changes', function() { - var tmpl = ''; + var tmpl = ''; var model = { items: [] }; var view = reactive(tmpl, model); assert('hidden' == view.el.className); diff --git a/test/text-interpolation.js b/test/text-interpolation.js index a80f993..9b7dba7 100644 --- a/test/text-interpolation.js +++ b/test/text-interpolation.js @@ -5,28 +5,28 @@ var reactive = require('../'); describe('text interpolation', function(){ it('should support initialization', function(){ - var el = domify('
Download {file}
'); + var el = domify('
Download {{file}}
'); var user = { id: '1234', file: 'tobi.png' }; var view = reactive(el, user); assert('Download tobi.png' == el.children[0].textContent); }) it('should ignore whitespace', function(){ - var el = domify('
Download { file }
'); + var el = domify('
Download {{ file }}
'); var user = { id: '1234', file: 'tobi.png' }; var view = reactive(el, user); assert('Download tobi.png' == el.children[0].textContent); }) it('should ignore null values', function(){ - var el = domify('
{ id }
'); + var el = domify('
{{ id }}
'); var user = { id: null }; var view = reactive(el, user); assert('' === el.textContent); }) it('should react to changes', function(){ - var el = domify('
Download {file}
'); + var el = domify('
Download {{file}}
'); var user = { id: '1234', file: 'tobi.png' }; var view = reactive(el, user); @@ -37,14 +37,14 @@ describe('text interpolation', function(){ }) it('should support multiple properties', function(){ - var el = domify('

{first} {last} is a {species}

'); + var el = domify('

{{first}} {{last}} is a {{species}}

'); var pet = { first: 'tobi', last: 'holowaychuk', species: 'ferret' }; var view = reactive(el, pet); assert('tobi holowaychuk is a ferret' == el.children[0].textContent); }) it('should support multiple properties in a single expression', function(){ - var el = domify('

{first + " " + last}

'); + var el = domify('

{{first + " " + last}}

'); var pet = { first: 'tobi', last: 'holowaychuk' }; var view = reactive(el, pet); @@ -55,7 +55,7 @@ describe('text interpolation', function(){ }) it('should support model method calls as properties', function(){ - var el = domify('

first: {first}

'); + var el = domify('

first: {{first}}

'); var pet = { first: function(){ @@ -68,7 +68,7 @@ describe('text interpolation', function(){ }) it('should support complex expressions', function(){ - var el = domify('

first: {siblings[0]}, last: {siblings[siblings.length - 1]}

'); + var el = domify('

first: {{siblings[0]}}, last: {{siblings[siblings.length - 1]}}

'); var pet = { siblings: [ @@ -86,7 +86,7 @@ describe('text interpolation', function(){ }) it('should support complex model method calls as properties', function(){ - var el = domify('

name: {casual ? first : first + " " + last}

'); + var el = domify('

name: {{casual ? first : first + " " + last}}

'); var pet = { casual: function(){ return false }, @@ -99,7 +99,7 @@ describe('text interpolation', function(){ }) it('should support method calls as properties on the view', function(){ - var el = domify('

name: {casual}

'); + var el = domify('

name: {{casual}}

'); var pet = { casual: function(){ return false }, @@ -119,7 +119,7 @@ describe('text interpolation', function(){ }) it('should support the root element', function(){ - var el = domify('

Hello {name}'); + var el = domify('

Hello {{name}}'); var user = { name: 'Tobi' }; reactive(el, user); assert('Hello Tobi' == el.textContent); @@ -127,17 +127,17 @@ describe('text interpolation', function(){ it('should support calling a property as a function', function(){ var model = { name: { first: 'Some Really Long Name' } }; - var view = reactive('

Hello {name.first.slice(0,6)}

', model); + var view = reactive('

Hello {{name.first.slice(0,6)}}

', model); assert('Hello Some R' == view.el.textContent); var model = { name: 'Some Really Long Name' }; - var view = reactive('

Hello {name.slice(0,4)}

', model); + var view = reactive('

Hello {{name.slice(0,4)}}

', model); assert('Hello Some' == view.el.textContent); }) it('should support setting base property', function(){ var model = { name: { first: 'foobar' } }; - var view = reactive('

{name.first}

', model); + var view = reactive('

{{name.first}}

', model); assert('foobar' == view.el.textContent); view.set('name', { first: 'baz' });