2020-10-16 18:02:58 +01:00
|
|
|
const ghostBookshelf = require('./base');
|
2021-03-05 13:54:01 +00:00
|
|
|
const urlUtils = require('../../shared/url-utils');
|
2020-10-16 18:02:58 +01:00
|
|
|
|
|
|
|
const Snippet = ghostBookshelf.Model.extend({
|
2021-03-05 13:54:01 +00:00
|
|
|
tableName: 'snippets',
|
|
|
|
|
2021-03-18 17:16:37 +00:00
|
|
|
format() {
|
|
|
|
const attrs = ghostBookshelf.Model.prototype.format.apply(this, arguments);
|
|
|
|
|
|
|
|
if (attrs.mobiledoc) {
|
|
|
|
attrs.mobiledoc = urlUtils.mobiledocToTransformReady(attrs.mobiledoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
return attrs;
|
|
|
|
},
|
|
|
|
|
|
|
|
parse() {
|
|
|
|
const attrs = ghostBookshelf.Model.prototype.parse.apply(this, arguments);
|
|
|
|
|
|
|
|
if (attrs.mobiledoc) {
|
|
|
|
attrs.mobiledoc = urlUtils.transformReadyToAbsolute(attrs.mobiledoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
return attrs;
|
2021-03-05 13:54:01 +00:00
|
|
|
}
|
2020-10-16 18:02:58 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
const Snippets = ghostBookshelf.Collection.extend({
|
|
|
|
model: Snippet
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
Snippet: ghostBookshelf.model('Snippet', Snippet),
|
|
|
|
Snippets: ghostBookshelf.collection('Snippets', Snippets)
|
|
|
|
};
|