2020-10-16 12:02:58 -05:00
|
|
|
const ghostBookshelf = require('./base');
|
2021-03-05 08:54:01 -05:00
|
|
|
const urlUtils = require('../../shared/url-utils');
|
2021-05-25 15:13:50 -05:00
|
|
|
const mobiledocLib = require('../lib/mobiledoc');
|
2020-10-16 12:02:58 -05:00
|
|
|
|
|
|
|
const Snippet = ghostBookshelf.Model.extend({
|
2021-03-05 08:54:01 -05:00
|
|
|
tableName: 'snippets',
|
|
|
|
|
2021-03-23 04:11:24 -05:00
|
|
|
formatOnWrite(attrs) {
|
2021-03-18 12:16:37 -05:00
|
|
|
if (attrs.mobiledoc) {
|
2021-05-25 15:13:50 -05:00
|
|
|
attrs.mobiledoc = urlUtils.mobiledocToTransformReady(attrs.mobiledoc, {cardTransformers: mobiledocLib.cards});
|
2021-03-18 12:16:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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 08:54:01 -05:00
|
|
|
}
|
2020-10-16 12:02:58 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
const Snippets = ghostBookshelf.Collection.extend({
|
|
|
|
model: Snippet
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
Snippet: ghostBookshelf.model('Snippet', Snippet),
|
|
|
|
Snippets: ghostBookshelf.collection('Snippets', Snippets)
|
|
|
|
};
|