From a123e94331bca0314288f2b74ebd89d7b153b362 Mon Sep 17 00:00:00 2001 From: kookookchoozeus Date: Thu, 14 Apr 2016 11:37:45 +0100 Subject: [PATCH 1/3] Adds CLI support for partials with relative paths --- bin/mustache | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/bin/mustache b/bin/mustache index 430e8b937..8d1136adb 100755 --- a/bin/mustache +++ b/bin/mustache @@ -78,7 +78,13 @@ function readPartials (cb) { var partialPath = partialsPaths.pop(); var partial = fs.createReadStream(partialPath); streamToStr(partial, function onDone (str) { - partials[getPartialName(partialPath)] = str; + + var keysArray = getPartialNames(partialPath); + + keysArray.forEach(function addPartialNames (key) { + partials[key] = str; + }); + readPartials(cb); }); } @@ -131,6 +137,27 @@ function hasVersionArg () { }); } -function getPartialName (filename) { - return path.basename(filename, '.mustache'); +function getPartialNames (filename) { + + // get path relative to the template file + // in order to use e.g. {{> ../common/footer }} + + // before, {{> footer }} used the first -p file with the filename 'footer' + + // the second replace is for a consistent form between platforms + // without it, you would have to use {{> ..\\common\\footer }} for windows + // and {{> ../common/footer }} for *nix + + // this can be extended to the mustache API by using the relative path as + // the key in the partials object + // e.g. mustache.render(template, view, { '../../common/footer': '...' }) + var relativePath = path. + relative(templateArg, filename). + replace('.mustache', ''). + replace(/\\{1,2}/g, '/'); + + return [ + path.basename(filename, '.mustache'), + relativePath + ]; } From 42fbdc3850df02f554ac4d068502028f443f841b Mon Sep 17 00:00:00 2001 From: kookookchoozeus Date: Sat, 16 Apr 2016 17:07:42 +0100 Subject: [PATCH 2/3] Revert cli back to what it was while I fix the tests for windows --- bin/mustache | 33 +++------------------------------ 1 file changed, 3 insertions(+), 30 deletions(-) diff --git a/bin/mustache b/bin/mustache index 8d1136adb..430e8b937 100755 --- a/bin/mustache +++ b/bin/mustache @@ -78,13 +78,7 @@ function readPartials (cb) { var partialPath = partialsPaths.pop(); var partial = fs.createReadStream(partialPath); streamToStr(partial, function onDone (str) { - - var keysArray = getPartialNames(partialPath); - - keysArray.forEach(function addPartialNames (key) { - partials[key] = str; - }); - + partials[getPartialName(partialPath)] = str; readPartials(cb); }); } @@ -137,27 +131,6 @@ function hasVersionArg () { }); } -function getPartialNames (filename) { - - // get path relative to the template file - // in order to use e.g. {{> ../common/footer }} - - // before, {{> footer }} used the first -p file with the filename 'footer' - - // the second replace is for a consistent form between platforms - // without it, you would have to use {{> ..\\common\\footer }} for windows - // and {{> ../common/footer }} for *nix - - // this can be extended to the mustache API by using the relative path as - // the key in the partials object - // e.g. mustache.render(template, view, { '../../common/footer': '...' }) - var relativePath = path. - relative(templateArg, filename). - replace('.mustache', ''). - replace(/\\{1,2}/g, '/'); - - return [ - path.basename(filename, '.mustache'), - relativePath - ]; +function getPartialName (filename) { + return path.basename(filename, '.mustache'); } From 52a44f54d25d83841d3eb6df05b84b5408c852f4 Mon Sep 17 00:00:00 2001 From: kookookchoozeus Date: Sat, 16 Apr 2016 17:07:47 +0100 Subject: [PATCH 3/3] Revert "Revert cli back to what it was while I fix the tests for windows" This reverts commit 42fbdc3850df02f554ac4d068502028f443f841b. --- bin/mustache | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/bin/mustache b/bin/mustache index 430e8b937..8d1136adb 100755 --- a/bin/mustache +++ b/bin/mustache @@ -78,7 +78,13 @@ function readPartials (cb) { var partialPath = partialsPaths.pop(); var partial = fs.createReadStream(partialPath); streamToStr(partial, function onDone (str) { - partials[getPartialName(partialPath)] = str; + + var keysArray = getPartialNames(partialPath); + + keysArray.forEach(function addPartialNames (key) { + partials[key] = str; + }); + readPartials(cb); }); } @@ -131,6 +137,27 @@ function hasVersionArg () { }); } -function getPartialName (filename) { - return path.basename(filename, '.mustache'); +function getPartialNames (filename) { + + // get path relative to the template file + // in order to use e.g. {{> ../common/footer }} + + // before, {{> footer }} used the first -p file with the filename 'footer' + + // the second replace is for a consistent form between platforms + // without it, you would have to use {{> ..\\common\\footer }} for windows + // and {{> ../common/footer }} for *nix + + // this can be extended to the mustache API by using the relative path as + // the key in the partials object + // e.g. mustache.render(template, view, { '../../common/footer': '...' }) + var relativePath = path. + relative(templateArg, filename). + replace('.mustache', ''). + replace(/\\{1,2}/g, '/'); + + return [ + path.basename(filename, '.mustache'), + relativePath + ]; }