forked from Asimov4/makehub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
project-parser.js
55 lines (54 loc) · 2.3 KB
/
project-parser.js
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
47
48
49
50
51
52
53
54
55
var pagedown = require("pagedown");
var converter = pagedown.getSanitizingConverter();
var _ = require('underscore');
module.exports = {
parse: function(gist, callback) {
//return projectContent.split('\n');
var project = {
'id': gist.id,
'user': gist.user.login,
'description': gist.description,
'urls': [],
'raw': gist.files['makehub'].content
};
if (gist.files['makehub'].content) {
var projectGist = gist.files['makehub'].content;
var matches = projectGist.match(/media: (.*)/g);
if (matches) {
var urls = matches.map(function (match, index) {
projectGist = projectGist.replace(match, "{{" + index + "}}");
return match.replace("media: ", "");
});
project['urls'] = urls;
}
project = _.extend(project,JSON.parse(gist.files['makehub.json'].content));
project['content'] = converter.makeHtml(projectGist);
}
return project;
},
encode: function(project) {
var gistContent = "";
gistContent += "# Title \n" + project.title + "\n";
gistContent += "# Picture \nmedia: " + project.picture + "\n";
gistContent += "# Test \n" + project.objective + "\n";
gistContent += "# Duration\n" + project.duration + "\n";
gistContent += "# Age Group\n" + project.ageGroup + "\n";
gistContent += "# Materials\n";
_.each(project.materials, function(material) {
gistContent += "## " + material.item + "\n";
gistContent += "* description:" + material.description + "\n";
gistContent += "* quantity:" + material.quantity + "\n";
gistContent += "* price:" + material.price + "\n";
gistContent += "* link:" + material.link + "\n\n";
});
gistContent += "# Steps\n";
_.each(project.steps, function(step) {
gistContent += "## " + step.description + "\n";
gistContent += "media: " + step.media + "\n\n";
gistContent += "notes: " + step.notes + "\n\n";
})
gistContent += "# Notes\n" + project.notes + "\n";
console.log(gistContent);
return gistContent;
}
};