Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updates to cjsTemplate to expose a few different methods to consume i…
…t. Use fs spec for reading files.
- Loading branch information
Dustin Machi
committed
Jun 10, 2010
1 parent
d44135b
commit 284f168
Showing
3 changed files
with
67 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
var fs = require("file"); | ||
var templateDir = (require("commonjs-utils/settings").templateFolder || "templates/"); | ||
var templateExtension = (require("commonjs-utils/settings").templateExtension || ".html"); | ||
|
||
exports.get = function(name){ | ||
var nameParts = name.split("/"); | ||
var templateName = templateDir + name; | ||
|
||
|
||
if (fs.isDirectory(templateName) && !fs.isFile(templateName+templateExtension)){ | ||
templateName = templateName + "/" + nameParts[nameParts.length-1] + templateExtension; | ||
}else{ | ||
templateName = templateName + templateExtension; | ||
} | ||
|
||
if (fs.isFile(templateName)){ | ||
return fs.read(templateName); | ||
}else{ | ||
var ending = nameParts.pop(); | ||
templateName = templateDir + nameParts.join("/"); | ||
if (fs.isDirectory(templateName)) { | ||
templateName = templateName +"/"+ nameParts[nameParts.length-1] + templateExtension; | ||
if (fs.isFile(templateName)){ | ||
return readFile(templateName); | ||
} | ||
}else{ | ||
//twice we popped one off above | ||
nameParts.push(ending); | ||
nameParts.push(ending); | ||
} | ||
} | ||
|
||
var found=false; | ||
while(nameParts.length>0){ | ||
var templateName = templateDir + nameParts.join("/") + templateExtension; | ||
if (fs.isFile(templateName)){ | ||
return fs.read(templateName); | ||
} | ||
nameParts.pop(); | ||
} | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters