Make {{#markdown}} work.

This commit is contained in:
Avital Oliver
2014-06-06 14:50:25 -07:00
parent ec64edcd1f
commit 49fcddb76f
3 changed files with 18 additions and 14 deletions

View File

@@ -126,6 +126,8 @@ Blaze.lookup = function (name, component, options) {
//return Blaze._bindIfIsFunction(component[name], component);
} else if (isTemplate && _.has(Template, name)) {
return Template[name];
} else if (UI._globalHelpers[name]) {
return UI._globalHelpers[name];
} else {
var dataVar = Blaze.getCurrentDataVar();
if (dataVar) {

View File

@@ -1,12 +1,18 @@
if (Package.ui) {
var UI = Package.ui.UI;
if (Package.blaze) {
var Blaze = Package.blaze.Blaze;
var HTML = Package.htmljs.HTML; // implied by `ui`
Package.ui.UI.registerHelper('markdown', UI.block(function () {
var self = this;
return function () {
var text = UI.toRawText(self.__content, self /*parentComponent*/);
Blaze.MarkdownComponent = Blaze.Component.extend({
constructor: function (dataFunc, contentFunc) {
Blaze.MarkdownComponent.__super__.constructor.call(this);
this.contentFunc = contentFunc;
},
render: function () {
var text = Blaze.toText(this.contentFunc(), HTML.TEXTMODE.STRING);
var converter = new Showdown.converter();
return HTML.Raw(converter.makeHtml(text));
};
}));
}
});
UI.registerHelper("markdown", Blaze.MarkdownComponent.prototype);
}

View File

@@ -1,13 +1,9 @@
// XXX this file no longer makes sense in isolation. take it apart as
// part file reorg on the 'ui' package
var globalHelpers = {};
UI._globalHelpers = {};
UI.registerHelper = function (name, func) {
globalHelpers[name] = func;
};
UI._globalHelper = function (name) {
return globalHelpers[name];
UI._globalHelpers[name] = func;
};
Handlebars = {};