-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Made it work without templating package.
We had weak dependency on the templating package but if templating package was not around things did not work. Also preliminary support for server side rendering. See #5903
- Loading branch information
Showing
11 changed files
with
262 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<!-- This file is needed to backport this pull request: https://github.com/meteor/meteor/pull/5903 | ||
It is a copy of dynamic.html with renamed template names. | ||
TODO: Remove this file eventually. | ||
--> | ||
|
||
<!-- Expects the data context to have a `template` property (the name of | ||
the template to render) and an optional `data` property. If the `data` | ||
property is not specified, then the parent data context will be used | ||
instead. Uses the __dynamicWithDataContext template below to actually | ||
render the template. --> | ||
<template name="__dynamicBackport"> | ||
{{checkContext}} | ||
{{#if dataContextPresent}} | ||
{{# __dynamicWithDataContext}}{{> Template.contentBlock}}{{/__dynamicWithDataContext}} | ||
{{else}} | ||
{{! if there was no explicit 'data' argument, use the parent context}} | ||
{{# __dynamicWithDataContext template=template data=..}}{{> Template.contentBlock}}{{/__dynamicWithDataContext}} | ||
{{/if}} | ||
</template> | ||
|
||
<!-- Expects the data context to have a `template` property (the name of | ||
the template to render) and a `data` property, which can be falsey. --> | ||
<template name="__dynamicWithDataContextBackport"> | ||
{{#with chooseTemplate template}} | ||
{{!-- The .. is evaluated inside {{#with ../data}} --}} | ||
{{# .. ../data}}{{> Template.contentBlock}}{{/ ..}} | ||
{{/with}} | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* This file is needed to backport this pull request: https://github.com/meteor/meteor/pull/5903 | ||
If it is a copy of dynamic.js file wrapped into a condition with renaming of backported templates. | ||
TODO: Remove this file eventually. | ||
*/ | ||
|
||
if (!Blaze.Template.__dynamicWithDataContext) { | ||
Blaze.Template.__dynamicWithDataContext = Blaze.Template.__dynamicWithDataContextBackport; | ||
Blaze.Template.__dynamic = Blaze.Template.__dynamicBackport; | ||
|
||
var Template = Blaze.Template; | ||
|
||
/** | ||
* @isTemplate true | ||
* @memberOf Template | ||
* @function dynamic | ||
* @summary Choose a template to include dynamically, by name. | ||
* @locus Templates | ||
* @param {String} template The name of the template to include. | ||
* @param {Object} [data] Optional. The data context in which to include the | ||
* template. | ||
*/ | ||
|
||
Template.__dynamicWithDataContext.helpers({ | ||
chooseTemplate: function (name) { | ||
return Blaze._getTemplate(name, function () { | ||
return Template.instance(); | ||
}); | ||
} | ||
}); | ||
|
||
Template.__dynamic.helpers({ | ||
dataContextPresent: function () { | ||
return _.has(this, "data"); | ||
}, | ||
checkContext: function () { | ||
if (!_.has(this, "template")) { | ||
throw new Error("Must specify name in the 'template' argument " + | ||
"to {{> Template.dynamic}}."); | ||
} | ||
|
||
_.each(this, function (v, k) { | ||
if (k !== "template" && k !== "data") { | ||
throw new Error("Invalid argument to {{> Template.dynamic}}: " + | ||
k); | ||
} | ||
}); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* This file is needed to backport this pull request: https://github.com/meteor/meteor/pull/5903 | ||
If it is a copy of templating.js file wrapped into a condition. | ||
TODO: Remove this file eventually. | ||
*/ | ||
|
||
if (!Blaze.Template.__checkName) { | ||
// Packages and apps add templates on to this object. | ||
|
||
/** | ||
* @summary The class for defining templates | ||
* @class | ||
* @instanceName Template.myTemplate | ||
*/ | ||
Template = Blaze.Template; | ||
|
||
var RESERVED_TEMPLATE_NAMES = "__proto__ name".split(" "); | ||
|
||
// Check for duplicate template names and illegal names that won't work. | ||
Template.__checkName = function (name) { | ||
// Some names can't be used for Templates. These include: | ||
// - Properties Blaze sets on the Template object. | ||
// - Properties that some browsers don't let the code to set. | ||
// These are specified in RESERVED_TEMPLATE_NAMES. | ||
if (name in Template || _.contains(RESERVED_TEMPLATE_NAMES, name)) { | ||
if ((Template[name] instanceof Template) && name !== "body") | ||
throw new Error("There are multiple templates named '" + name + "'. Each template needs a unique name."); | ||
throw new Error("This template name is reserved: " + name); | ||
} | ||
}; | ||
|
||
// XXX COMPAT WITH 0.8.3 | ||
Template.__define__ = function (name, renderFunc) { | ||
Template.__checkName(name); | ||
Template[name] = new Template("Template." + name, renderFunc); | ||
// Exempt packages built pre-0.9.0 from warnings about using old | ||
// helper syntax, because we can. It's not very useful to get a | ||
// warning about someone else's code (like a package on Atmosphere), | ||
// and this should at least put a bit of a dent in number of warnings | ||
// that come from packages that haven't been updated lately. | ||
Template[name]._NOWARN_OLDSTYLE_HELPERS = true; | ||
}; | ||
|
||
// Define a template `Template.body` that renders its | ||
// `contentRenderFuncs`. `<body>` tags (of which there may be | ||
// multiple) will have their contents added to it. | ||
|
||
/** | ||
* @summary The [template object](#templates_api) representing your `<body>` | ||
* tag. | ||
* @locus Client | ||
*/ | ||
Template.body = new Template('body', function () { | ||
var view = this; | ||
return _.map(Template.body.contentRenderFuncs, function (func) { | ||
return func.apply(view); | ||
}); | ||
}); | ||
Template.body.contentRenderFuncs = []; // array of Blaze.Views | ||
Template.body.view = null; | ||
|
||
Template.body.addContent = function (renderFunc) { | ||
Template.body.contentRenderFuncs.push(renderFunc); | ||
}; | ||
|
||
// This function does not use `this` and so it may be called | ||
// as `Meteor.startup(Template.body.renderIntoDocument)`. | ||
Template.body.renderToDocument = function () { | ||
// Only do it once. | ||
if (Template.body.view) | ||
return; | ||
|
||
var view = Blaze.render(Template.body, document.body); | ||
Template.body.view = view; | ||
}; | ||
|
||
// XXX COMPAT WITH 0.9.0 | ||
UI.body = Template.body; | ||
|
||
// XXX COMPAT WITH 0.9.0 | ||
// (<body> tags in packages built with 0.9.0) | ||
Template.__body__ = Template.body; | ||
Template.__body__.__contentParts = Template.body.contentViews; | ||
Template.__body__.__instantiate = Template.body.renderToDocument; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.