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