Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix for express and use sub directories in target

  • Loading branch information...
commit 0a126142ce9a0368036a0f9b3839d18ffd2255de 1 parent 6a505ce
@chrisdew authored
Showing with 17 additions and 5 deletions.
  1. +17 −5 duster.js
View
22 duster.js 100644 → 100755
@@ -1,9 +1,13 @@
+#!/usr/bin/env node
// duster.js
// Watch directory of dust.js templates and automatically compile them
// by Dan McGrady http://dmix.ca
+// Modified by Chris Dew http://www.barricane.com to work nicely with Express
+// and to deal with sub directories properly (i.e. create files in sub directories)
-var input_path = "./dusts"; // directory of dust templates are stored with .dust file extension
-var output_path = "./javascripts/dusts/"; // directory where the compiled .js files should be saved to
+var input_path = "./views/"; // directory of dust templates are stored with .dust file extension
+var input_parts = 1;
+var output_path = "./public/js/dust/"; // directory where the compiled .js files should be saved to
var fs = require('fs');
var dust = require('dustjs-linkedin');
@@ -13,10 +17,18 @@ function compile_dust(path, curr, prev) {
fs.readFile(path, function(err, data) {
if (err) throw err;
- var filename = path.split("/").reverse()[0].replace(".dust", "");
- var filepath = output_path + filename + ".js";
- var compiled = dust.compile(new String(data), filename);
+ var split_path = path.split("/");
+ var filename = split_path.reverse()[0].replace(".dust", "");
+ var destpath_parts = split_path.slice(input_parts, split_path.length - 1);
+ var destpath = destpath_parts.join("/");
+ if (destpath.length > 0) destpath = destpath + "/";
+
+ // Should this check that dest path exists and if not recursively mkdir
+ // until it does? At the moment, manual creation of directories is required.
+ var filepath = output_path + destpath + filename + ".js";
+ var compiled = dust.compile(new String(data), filename);
+
fs.writeFile(filepath, compiled, function(err) {
if (err) throw err;
console.log('Saved ' + filepath);
Please sign in to comment.
Something went wrong with that request. Please try again.