Fix scope order when importing partials with metadata.

Render error when importing wiki pages that do not exist.
This commit is contained in:
Chase Sterling 2016-08-09 21:45:07 -04:00
parent 55e2ceccaa
commit 9a730a947e
4 changed files with 18 additions and 34 deletions

View file

@ -82,19 +82,20 @@ var deletePage = function() {
bootbox.alert('Error deleting page!');
});
};
var partials = {};
var partials = [];
var aced = new Aced({
editor: $('#entry-markdown-content').find('.editor').attr('id'),
renderer: function(md) {
var doc = metaMarked(md);
if (doc.meta && 'import' in doc.meta) {
// If we don't have all the imports loaded as partials, get them from server
if (!doc.meta['import'].every(function(val) {return val in partials;})) {
$.getJSON('/partials', {'imports': doc.meta['import']}, function (response) {
$.extend(partials, response['partials']);
// If the imports have changed, refresh them from the server
if (partials.length < doc.meta['import'].length ||
!doc.meta['import'].every(function(impname, index) {return partials[partials.length-index-1][0] == impname})) {
$.getJSON('/_partials', {'imports': doc.meta['import']}, function (response) {
partials = response['partials'];
// TODO: Better way to force update of the preview here than this fake signal?
aced.editor.session.doc._signal('change',
{'action': 'insert', 'lines': [''], 'start': {'row': 0}, 'end': {'row': 0}});
{'action': 'insert', 'lines': [], 'start': {'row': 0}, 'end': {'row': 0}});
});
}
}

View file

@ -96,9 +96,9 @@ var MDR = {
this.md = doc.md;
var meta = this.meta = {};
if (this.partials) {
$.each(this.partials, function(key, value) {
var doc = metaMarked(value);
Handlebars.registerPartial(key, doc.md);
$.each(this.partials, function(index, item) {
var doc = metaMarked(item[1]);
Handlebars.registerPartial(item[0], doc.md);
$.extend(meta, doc.meta);
})
}