diff --git a/packages/spacebars/spacebars.js b/packages/spacebars/spacebars.js index 43cac2707c..ae126b0753 100644 --- a/packages/spacebars/spacebars.js +++ b/packages/spacebars/spacebars.js @@ -3,7 +3,7 @@ Spacebars = {}; var makeStacheTagStartRegex = function (r) { - return new RegExp(r.source + /(?![{>!#/@])/.source, + return new RegExp(r.source + /(?![{>!#/])/.source, r.ignoreCase ? 'i' : ''); }; @@ -22,8 +22,7 @@ var starts = { COMMENT: makeStacheTagStartRegex(/^\{\{\s*!/), INCLUSION: makeStacheTagStartRegex(/^\{\{\s*>\s*(?!\s)/), BLOCKOPEN: makeStacheTagStartRegex(/^\{\{\s*#\s*(?!\s)/), - BLOCKCLOSE: makeStacheTagStartRegex(/^\{\{\s*\/\s*(?!\s)/), - ANNOTATION: makeStacheTagStartRegex(/^\{\{\s*@\s*(?!\s)/) + BLOCKCLOSE: makeStacheTagStartRegex(/^\{\{\s*\/\s*(?!\s)/) }; var ends = { @@ -197,7 +196,6 @@ Spacebars.parseStacheTag = function (inputString, pos, options) { else if (run(starts.INCLUSION)) type = 'INCLUSION'; else if (run(starts.BLOCKOPEN)) type = 'BLOCKOPEN'; else if (run(starts.BLOCKCLOSE)) type = 'BLOCKCLOSE'; - else if (run(starts.ANNOTATION)) type = 'ANNOTATION'; else error('Unknown stache tag starting with "' + str.slice(0,5) + '"'); @@ -731,8 +729,6 @@ Spacebars.compile = function (inputString, options) { parts.push(codeGenBasicStache(tag, funcInfo)); break; - case 'ANNOTATION': - error("Can't use an annotation stache tag in an attribute name or value"); default: error("Unknown stache tag type: " + tag.type); } @@ -811,8 +807,6 @@ Spacebars.compile = function (inputString, options) { break; case 'COMMENT': break; - case 'ANNOTATION': - error("Annotation stache tag must occur inside an HTML start tag"); default: error("Unexpected tag type: " + tag.type); } @@ -824,48 +818,15 @@ Spacebars.compile = function (inputString, options) { case 'StartTag': var attrs = null; var dynamicAttrs = null; - var annotations = null; _.each(t.data, function (kv) { var name = kv.nodeName; var value = kv.nodeValue; if ((typeof name) !== 'string') { - if (name.length === 1 && - name[0].type === 'ANNOTATION' && - value === '') { - var tag = name[0]; - // XXX support arbitrary, user-defined - // annotations in the future - var annotationName = tag.path.join(''); - if (annotationName !== 'emit') - error("Unknown annotation: " + annotationName); - - // for now, we only allow strings and keyword - // arguments whose values are strings, - // as in `{{@emit "keydown" click="myclick"}}` - var emitData = null; - _.each(tag.args, function (arg) { - if (arg[0] !== 'STRING') - error("Argument values to @emit must be STRING"); - var highEvent = arg[1]; - var lowEvent = arg[2] || highEvent; - emitData = (emitData || {}); - emitData[toJSLiteral(lowEvent)] = - toJSLiteral(highEvent); - }); - if (emitData) { - annotations = (annotations || []); - annotations.push(makeObjectLiteral({ - type: toJSLiteral('emit'), - data: makeObjectLiteral(emitData) - })); - } - } else { - dynamicAttrs = (dynamicAttrs || []); - dynamicAttrs.push([interpolate(name, funcInfo, - INTERPOLATE_DYNAMIC_ATTR), - interpolate(value, funcInfo, - INTERPOLATE_DYNAMIC_ATTR)]); - } + dynamicAttrs = (dynamicAttrs || []); + dynamicAttrs.push([interpolate(name, funcInfo, + INTERPOLATE_DYNAMIC_ATTR), + interpolate(value, funcInfo, + INTERPOLATE_DYNAMIC_ATTR)]); } else { attrs = (attrs || {}); attrs[toJSLiteral(name)] = @@ -880,11 +841,6 @@ Spacebars.compile = function (inputString, options) { return '[' + pair[0] + ', ' + pair[1] + ']'; }).join(', ') + ']'; } - if (annotations) { - options = (options || {}); - options['annotations'] = '[' + - annotations.join(', ') + ']'; - } if (t.self_closing) { options = (options || {}); options['selfClose'] = 'true'; diff --git a/packages/ui/attrs.js b/packages/ui/attrs.js index 5a54e435eb..9b1df25584 100644 --- a/packages/ui/attrs.js +++ b/packages/ui/attrs.js @@ -1,4 +1,3 @@ -var Component = UIComponent; var ATTRIBUTE_NAME_REGEX = /^[^\s"'>/=/]+$/; @@ -128,7 +127,7 @@ _extend(AttributeHandler.prototype, { return ''; return this.name + '="' + - _UI.encodeSpecialEntities(this.stringifyValue(value), true) + '"'; + UI.encodeSpecialEntities(this.stringifyValue(value), true) + '"'; }, stringifyValue: function (value) { return String(value); diff --git a/packages/ui/base.js b/packages/ui/base.js index 18bc53f81b..2792cad54c 100644 --- a/packages/ui/base.js +++ b/packages/ui/base.js @@ -1,5 +1,5 @@ -// @export _UI -_UI = { +// @export UI +UI = { nextGuid: 1 }; @@ -54,7 +54,7 @@ var constrImpl = function (ths, args, type) { ths.data = dataFunc; } - ths.guid = _UI.nextGuid++; + ths.guid = UI.nextGuid++; ths.constructed(); return ths; @@ -241,5 +241,4 @@ Component.include({ } }); -// @export UIComponent -UIComponent = Component; \ No newline at end of file +UI.Component = Component; \ No newline at end of file diff --git a/packages/ui/components.js b/packages/ui/components.js index c31474f1a5..96ae5ac862 100644 --- a/packages/ui/components.js +++ b/packages/ui/components.js @@ -1,8 +1,7 @@ -var Component = UIComponent; -_UI.Text = Component.extend({ +UI.Text = Component.extend({ typeName: 'Text', - _encodeEntities: _UI.encodeSpecialEntities, + _encodeEntities: UI.encodeSpecialEntities, _stringify: function (x) { return String(x == null ? '' : x); }, @@ -12,7 +11,7 @@ _UI.Text = Component.extend({ } }); -_UI.HTML = Component.extend({ +UI.HTML = Component.extend({ typeName: 'HTML', _stringify: function (x) { return String(x == null ? '' : x); @@ -23,7 +22,7 @@ _UI.HTML = Component.extend({ } }); -_UI.If = Component.extend({ +UI.If = Component.extend({ typeName: 'If', render: function (buf) { var self = this; @@ -34,7 +33,18 @@ _UI.If = Component.extend({ } }); -_UI.Counter = Component.extend({ +UI.Unless = Component.extend({ + typeName: 'Unless', + render: function (buf) { + var self = this; + var condition = Deps.isolate(function () { + return ! self.data(); + }); + buf(condition ? self.content() : self.elseContent()); + } +}); + +UI.Counter = Component.extend({ typeName: "Counter", fields: { count: 0 @@ -46,7 +56,7 @@ _UI.Counter = Component.extend({ var self = this; buf("