mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Start to make custom block helpers work
UI.contentBlock
This commit is contained in:
@@ -23,8 +23,8 @@ var builtInUIPaths = {
|
||||
// function for the template in which `UI.contentBlock` (or
|
||||
// `UI.elseBlock`) is invoked. `template` is a reference to the
|
||||
// template itself.
|
||||
'contentBlock': 'template.__content',
|
||||
'elseBlock': 'template.__elseContent',
|
||||
'contentBlock': 'self.__contentBlock',
|
||||
'elseBlock': 'self.__elseBlock',
|
||||
|
||||
// `Template` is the global template namespace. If you define a
|
||||
// template named `foo` in Spacebars, it gets defined as
|
||||
|
||||
@@ -49,16 +49,7 @@ SpacebarsCompiler.codeGen = function (parseTree, options) {
|
||||
{codegen: codegen})).visit(tree);
|
||||
|
||||
var code = '(function () { ';
|
||||
if (isTemplate) {
|
||||
// support `{{> UI.contentBlock}}` and `{{> UI.elseBlock}}` with
|
||||
// lexical scope by creating a local variable in the
|
||||
// template's render function.
|
||||
code += 'var template = this; ';
|
||||
}
|
||||
if (isTemplate || isBody) {
|
||||
// XXX This should replace `var template` and `var self` and become
|
||||
// `var self`. When we're compiling a render method for a component,
|
||||
// there is a "this," but otherwise, there isn't.
|
||||
code += 'var self = this; ';
|
||||
}
|
||||
code += 'return ';
|
||||
|
||||
@@ -31,7 +31,7 @@ Tinytest.add("templating - html scanner", function (test) {
|
||||
|
||||
// arguments are quoted strings like '"hello"'
|
||||
var simpleTemplate = function (templateName, content) {
|
||||
return '\nTemplate.__define__(' + templateName + ', (function() {\n var template = this;\n var self = this;\n return ' + content + ';\n}));\n';
|
||||
return '\nTemplate.__define__(' + templateName + ', (function() {\n var self = this;\n return ' + content + ';\n}));\n';
|
||||
};
|
||||
|
||||
var checkResults = function(results, expectJs, expectHead) {
|
||||
|
||||
@@ -37,17 +37,24 @@ UI.TemplateComponent = Blaze.Component.extend({
|
||||
constructor: function (dataFunc, contentFunc, elseFunc) {
|
||||
UI.TemplateComponent.__super__.constructor.call(this);
|
||||
|
||||
if (dataFunc)
|
||||
this.dataFunc = dataFunc;
|
||||
if (contentFunc)
|
||||
this.contentFunc = contentFunc;
|
||||
if (elseFunc)
|
||||
this.elseFunc = elseFunc;
|
||||
if (dataFunc) {
|
||||
this.__dataFunc = dataFunc;
|
||||
}
|
||||
if (contentFunc) {
|
||||
this.__contentBlock = Blaze.Component.extend({
|
||||
render: function () { return contentFunc(); }
|
||||
}).prototype;
|
||||
}
|
||||
if (elseFunc) {
|
||||
this.__elseBlock = Blaze.Component.extend({
|
||||
render: function () { return elseFunc(); }
|
||||
}).prototype;
|
||||
}
|
||||
},
|
||||
render: function () {
|
||||
var self = this;
|
||||
if (self.dataFunc) {
|
||||
return Blaze.With(self.dataFunc, function () {
|
||||
if (self.__dataFunc) {
|
||||
return Blaze.With(self.__dataFunc, function () {
|
||||
return self.renderTemplate();
|
||||
});
|
||||
} else {
|
||||
@@ -105,5 +112,7 @@ UI.TemplateComponent = Blaze.Component.extend({
|
||||
extend: function () {
|
||||
throw new Error(
|
||||
"Component#extend was part of a private API that has been removed");
|
||||
}
|
||||
},
|
||||
__contentBlock: null,
|
||||
__elseBlock: null
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user