Permalink
Browse files

Allow template engines to select formatter.

  • Loading branch information...
1 parent dcffd22 commit c4dfcc52f07853cb13a434a17caf1c0e9a332a91 @gilbert committed Feb 15, 2012
Showing with 16 additions and 7 deletions.
  1. +7 −4 lib/client_asset_manager/template_engine.js
  2. +9 −3 src/client_asset_manager/template_engine.coffee
@@ -42,14 +42,17 @@ exports.init = function(root) {
prevEngine = null;
templates = [];
return files.forEach(function(path) {
- var extension, f, formatter, fullPath;
+ var engine, extension, f, formatter, fullPath;
fullPath = pathlib.join(root, templateDir, path);
+ engine = tlib.selectEngine(templateEngines, path) || defaultEngine;
extension = pathlib.extname(path);
if (extension) extension = extension.substring(1);
- formatter = (f = formatters[extension]) && f.assetType === 'html' && f || formatters['html'];
+ formatter = (f = formatters[extension]) && f.assetType === 'html' && f;
+ if (engine.selectFormatter) {
+ formatter = engine.selectFormatter(path, formatters, formatter);
+ }
+ formatter || (formatter = formatters['html']);
return formatter.compile(fullPath, {}, function(output) {
- var engine;
- engine = tlib.selectEngine(templateEngines, path) || defaultEngine;
templates.push(tlib.wrapTemplate(output, path, engine, prevEngine));
prevEngine = engine;
if (templates.length === files.length) {
@@ -45,14 +45,20 @@ exports.init = (root) ->
files.forEach (path) ->
fullPath = pathlib.join(root, templateDir, path)
+ engine = tlib.selectEngine(templateEngines, path) || defaultEngine
+
+ # default method to select an HTML formatter
extension = pathlib.extname(path)
extension = extension.substring(1) if extension
+ formatter = (f = formatters[extension]) && f.assetType == 'html' && f
+
+ # Allow engine to select formatter
+ formatter = engine.selectFormatter(path, formatters, formatter) if engine.selectFormatter
- # Select the approriate HTML formatter, or default to 'HTML' (echo/bypass)
- formatter = (f = formatters[extension]) && f.assetType == 'html' && f || formatters['html']
+ # default to 'HTML' (echo/bypass)
+ formatter ||= formatters['html']
formatter.compile fullPath, {}, (output) ->
- engine = tlib.selectEngine(templateEngines, path) || defaultEngine
templates.push tlib.wrapTemplate(output, path, engine, prevEngine)
prevEngine = engine

0 comments on commit c4dfcc5

Please sign in to comment.