Fix live preview of imports in editor

This commit is contained in:
Chase Sterling 2016-08-09 20:14:29 -04:00
parent 55e1ed3a2b
commit 55e2ceccaa
2 changed files with 8 additions and 10 deletions

View file

@ -189,7 +189,7 @@ class WikiPage(HookMixin):
@property @property
def imports(self): def imports(self):
"""Names""" """Names"""
meta = self._get_meta(self.data) meta = self._get_meta(self.data) or {}
return meta.get('import', []) return meta.get('import', [])
@staticmethod @staticmethod

View file

@ -87,17 +87,15 @@ var aced = new Aced({
editor: $('#entry-markdown-content').find('.editor').attr('id'), editor: $('#entry-markdown-content').find('.editor').attr('id'),
renderer: function(md) { renderer: function(md) {
var doc = metaMarked(md); var doc = metaMarked(md);
if ('import' in doc.meta) { 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;})) { if (!doc.meta['import'].every(function(val) {return val in partials;})) {
$.ajax({ $.getJSON('/partials', {'imports': doc.meta['import']}, function (response) {
url: '/_partials',
data: {'imports': doc.meta['import']},
async: true,
dataType: 'json',
success: function (response) {
$.extend(partials, response['partials']); $.extend(partials, response['partials']);
//TODO: Force editor rerender // 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}});
});
} }
} }
return MDR.convert(md, partials) return MDR.convert(md, partials)