WIP partial improvements
This commit is contained in:
parent
4a38e896eb
commit
55e1ed3a2b
6 changed files with 64 additions and 25 deletions
|
@ -82,10 +82,26 @@ var deletePage = function() {
|
|||
bootbox.alert('Error deleting page!');
|
||||
});
|
||||
};
|
||||
|
||||
var partials = {};
|
||||
var aced = new Aced({
|
||||
editor: $('#entry-markdown-content').find('.editor').attr('id'),
|
||||
renderer: function(md) { return MDR.convert(md) },
|
||||
renderer: function(md) {
|
||||
var doc = metaMarked(md);
|
||||
if ('import' in doc.meta) {
|
||||
if (!doc.meta['import'].every(function(val) {return val in partials;})) {
|
||||
$.ajax({
|
||||
url: '/_partials',
|
||||
data: {'imports': doc.meta['import']},
|
||||
async: true,
|
||||
dataType: 'json',
|
||||
success: function (response) {
|
||||
$.extend(partials, response['partials']);
|
||||
//TODO: Force editor rerender
|
||||
}});
|
||||
}
|
||||
}
|
||||
return MDR.convert(md, partials)
|
||||
},
|
||||
info: Commit.info,
|
||||
submit: function(content) {
|
||||
var data = {
|
||||
|
|
|
@ -58,11 +58,12 @@ var MDR = {
|
|||
parse: function(md){
|
||||
return marked(md, { renderer: this.renderer });
|
||||
},
|
||||
convert: function(md, sanitize) {
|
||||
convert: function(md, partials, sanitize) {
|
||||
if (this.sanitize !== null) {
|
||||
sanitize = this.sanitize;
|
||||
}
|
||||
this.md = md;
|
||||
this.partials = partials;
|
||||
this.processMeta();
|
||||
try {
|
||||
var html = this.parse(this.md);
|
||||
|
@ -93,7 +94,15 @@ var MDR = {
|
|||
processMeta: function() {
|
||||
var doc = metaMarked(this.md);
|
||||
this.md = doc.md;
|
||||
this.meta = doc.meta;
|
||||
var meta = this.meta = {};
|
||||
if (this.partials) {
|
||||
$.each(this.partials, function(key, value) {
|
||||
var doc = metaMarked(value);
|
||||
Handlebars.registerPartial(key, doc.md);
|
||||
$.extend(meta, doc.meta);
|
||||
})
|
||||
}
|
||||
$.extend(this.meta, doc.meta);
|
||||
if (this.meta) {
|
||||
try {
|
||||
var template = Handlebars.compile(this.md);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue