xonecas.io
818
Du

dustymarkdown / files

dustymarkdown / node_modules / dust / docs / build.js

1.9 KB
1var path   = require('path'),
2    fs     = require('fs'),
3    Script = process.binding('evals').Script,
4    dust   = require('../lib/dust'),
5    root   = path.join(path.dirname(__filename), "..");
6
7var src = fs.readFileSync(path.join(root, 'docs/index.dust.html'), 'utf8');
8dust.loadSource(dust.compile(src, "index"));
9
10var sd = process.compile(fs.readFileSync(path.join(root, 'vendor/showdown.js'), 'utf8'), 'showdown.js');
11
12var inliners = {
13  css: function(names) {
14    var out = "<style type=\"text/css\">";
15    names.forEach(function(name) {
16      out += fs.readFileSync(path.join(root, 'docs', name + '.css'), 'utf8');
17    });
18    out += "</style>";
19    return out;
20  },
21
22  js: function(names) {
23    var out = "<script type=\"text/javascript\">";
24    names.forEach(function(name) {
25      out += fs.readFileSync(path.join(root, 'docs', name + '.js'), 'utf8');
26    });
27    out += "</script>";
28    return out;
29  }
30}
31
32var context = {
33  inline: function(chk, ctx, bod, prm) {
34    var names = prm.names.split(' ');
35    return chk.write(inliners[prm.ext](names));
36  },
37
38  tmpl: function(chk, ctx, bod, prm) {
39    var names = prm.names.split(' ');
40    var out = "<script type=\"text/javascript\">";
41    names.forEach(function(name) {
42      out += dust.compile(fs.readFileSync(path.join(root, 'docs', name + '.dust.html'), 'utf8'), "select");
43    });
44    out += "</script>";
45    return chk.write(out);
46  },
47
48  md: function(chk, ctx, bod, prm) {
49    var converter = new sd();
50    return chk.tap(function(data) {
51      return converter.makeHtml(data);
52    }).render(bod.block, ctx).untap();
53  },
54
55  file: function(chk, ctx, bod, prm) {
56    var name = prm.name;
57    return chk.write(fs.readFileSync(path.join(root, 'docs', name), 'utf8'));
58  }
59}
60
61function render() {
62  dust.render("index", context, function(err, output) {
63    if (err) throw err;
64    fs.writeFileSync(path.join(root, 'index.html'), output);
65  });
66}
67
68render();