Skip to content

Commit

Permalink
Allow template engines to select formatter.
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbert committed Feb 15, 2012
1 parent dcffd22 commit c4dfcc5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
11 changes: 7 additions & 4 deletions lib/client_asset_manager/template_engine.js
Expand Up @@ -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) {
Expand Down
12 changes: 9 additions & 3 deletions src/client_asset_manager/template_engine.coffee
Expand Up @@ -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

Expand Down

0 comments on commit c4dfcc5

Please sign in to comment.