-
Notifications
You must be signed in to change notification settings - Fork 8
/
project-parser.js
63 lines (62 loc) · 2.69 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
56
57
58
59
60
61
62
63
var pagedown = require("pagedown");
var converter = pagedown.getSanitizingConverter();
var _ = require('underscore');
module.exports = {
parse: function(gist, callback) {
var project = {
'id': gist.id,
'user': gist.owner.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));
var steps = project.steps.map(function(step) {
step['picture'] = step['media'];
return step;
})
project.steps = steps;
project['content'] = converter.makeHtml(projectGist);
// We need to reset the following values as they may have been overriden by the makehub.json file
project['id'] = gist.id;
project['user'] = gist.owner.login;
project['description'] = gist.description;
}
return project;
},
encode: function(project) {
var gistContent = "";
gistContent += "# Title \n" + project.title + "\n";
gistContent += "# Picture \nmedia: " + project.picture + "\n";
gistContent += "# Objective\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;
}
};