Create mode + Source view + UI enhancements

This commit is contained in:
NGPixel
2016-08-29 22:19:47 -04:00
parent 0f06ab6dc8
commit 16f300f0d5
27 changed files with 437 additions and 84 deletions

View File

@@ -33,6 +33,31 @@ module.exports = {
},
/**
* Check if a document already exists
*
* @param {String} entryPath The entry path
* @return {Promise<Boolean>} True if exists, false otherwise
*/
exists(entryPath) {
let self = this;
return self.fetchOriginal(entryPath, {
parseMarkdown: false,
parseMeta: false,
parseTree: false,
includeMarkdown: false,
includeParentInfo: false,
cache: false
}).then(() => {
return true;
}).catch((err) => {
return false;
});
},
/**
* Fetch a document from cache, otherwise the original
*
@@ -145,6 +170,8 @@ module.exports = {
} else {
return false;
}
}).catch((err) => {
return Promise.reject(new Error('Entry ' + entryPath + ' does not exist!'));
});
},
@@ -253,7 +280,33 @@ module.exports = {
return Promise.reject(new Error('Entry does not exist!'));
}
}).catch((err) => {
return new Error('Entry does not exist!');
return Promise.reject(new Error('Entry does not exist!'));
});
},
/**
* Create a new document
*
* @param {String} entryPath The entry path
* @param {String} contents The markdown-formatted contents
* @return {Promise<Boolean>} True on success, false on failure
*/
create(entryPath, contents) {
let self = this;
return self.exists(entryPath).then((docExists) => {
if(!docExists) {
return self.makePersistent(entryPath, contents).then(() => {
return self.fetchOriginal(entryPath, {});
});
} else {
return Promise.reject(new Error('Entry already exists!'));
}
}).catch((err) => {
winston.error(err);
return Promise.reject(new Error('Something went wrong.'));
});
},
@@ -274,6 +327,23 @@ module.exports = {
return git.commitDocument(entryPath);
});
},
/**
* Generate a starter page content based on the entry path
*
* @param {String} entryPath The entry path
* @return {Promise<String>} Starter content
*/
getStarter(entryPath) {
let self = this;
let formattedTitle = _.startCase(_.last(_.split(entryPath, '/')));
return fs.readFileAsync(path.join(ROOTPATH, 'client/content/create.md'), 'utf8').then((contents) => {
return _.replace(contents, new RegExp('{TITLE}', 'g'), formattedTitle);
});
}
};