forked from colmena/colmena
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage.js
More file actions
46 lines (39 loc) · 869 Bytes
/
page.js
File metadata and controls
46 lines (39 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'use strict';
var Showdown = require('showdown');
module.exports = function(Page) {
Page.createFakeData = function (faker) {
var name = faker.company.catchPhrase();
var slug = faker.helpers.slugify(name);
return Page.create({
id: slug,
name: name,
slug: slug,
content: ' > ' + faker.lorem.paragraph()
});
};
var converter = new Showdown.converter();
Page.html = function(id, cb) {
Page.findById(id, function(err, page) {
if (err) {
return cb(err);
}
var result = page;
result.html = converter.makeHtml(page.content);
cb(err, result);
});
};
Page.remoteMethod('html', {
accepts: {
arg: 'id',
type: 'string'
},
returns: {
arg: 'content',
type: 'string'
},
http: {
path: '/:id/html',
verb: 'get'
}
});
};