-
Notifications
You must be signed in to change notification settings - Fork 6
/
plan2html.js
76 lines (67 loc) · 2.53 KB
/
plan2html.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
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env node
// Converts a markdown formatted Lean Canvas to HTML
// http://github.com/shermanhuman/planvas
// This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/.
var marked = require('marked');
var fs = require('fs');
var Handlebars = require('handlebars');
marked.setOptions({
gfm: true
});
var leantemplate = fs.readFileSync('presentation.html', 'utf8');
if (process.argv.length <= 2) {
console.log(` No arguments supplied. Give me some MD files to munch.
Maybe try using the filenames of what you want converted as arguments.
As many as you want, seperated by spaces.`)
} else {
for (i = 2; i < process.argv.length; i++) {
val = process.argv[i];
console.log('Converting ' + val + ' to HTML.');
var htmlfilename = val + '.html';
var infile = fs.readFile(val, 'utf8', function (err, data) {
if (err) throw err;
var parsed = parse(data);
var planvas = htmlify(parsed);
//console.log('leantemplate = ' + leantemplate);
var template = Handlebars.compile(leantemplate);
//console.log('planvas = ' + planvas);
var converted = template(planvas);
//console.log('converted = ' + converted);
fs.writeFile(htmlfilename, converted, function (err) {
if (err) {
throw err;
}
else {
console.log('Saved as ' + htmlfilename);
}
})
})
}
};
var parse = function (data) {
textarray = data.split('##');
var planvas = {
problem: '##' + textarray[1],
existingalternatives: '##' + textarray[2],
solution: '##' + textarray[3],
keymetrics: '##' + textarray[4],
uniquevalueproposition: '##' + textarray[5],
highlevelconcept: '##' + textarray[6],
unfairadvantage: '##' + textarray[7],
channels: '##' + textarray[8],
customersegments: '##' + textarray[9],
earlyadopters: '##' + textarray[10],
coststructure: '##' + textarray[11],
revenuestreams: '##' + textarray[12]
};
//console.log(planvas);
return planvas;
}
var htmlify = function (object) {
for (var prop in object) {
object[prop] = marked(object[prop]);
}
//console.log(object);
return object;
}