'use strict';

var jstransformer = require('jstransformer');
var uglify = require('uglify-js');
var CleanCSS = require('clean-css');
var resolve = require('resolve');

module.exports = filter;
function filter(name, str, options, currentDirectory) {
  if (typeof filter[name] === 'function') {
    return filter[name](str, options);
  } else {
    var tr;
    try {
      try {
        tr = require(resolve.sync('jstransformer-' + name, {basedir: currentDirectory || process.cwd()}));
      } catch (ex) {
        tr = require('jstransformer-' + name);
      }
      tr = jstransformer(tr);
    } catch (ex) {}
    if (tr) {
      // TODO: we may want to add a way for people to separately specify "locals"
      var result = tr.render(str, options, options).body;
      if (options && options.minify) {
        try {
          switch (tr.outputFormat) {
            case 'js':
              result = uglify.minify(result, {fromString: true}).code;
              break;
            case 'css':
              result = new CleanCSS().minify(result).styles;
              break;
          }
        } catch (ex) {
          // better to fail to minify than output nothing
        }
      }
      return result;
    } else {
      var err = new Error('unknown filter ":' + name + '"');
      err.code = 'UNKNOWN_FILTER';
      throw err;
    }
  }
}

@@ -246,104 +246,8 @@
 ) %7B%0A
-  if (typeof filter%5Bname%5D === 'function') %7B%0A    return filter%5Bname%5D(str, options);%0A  %7D else %7B%0A  
   va
@@ -254,26 +254,22 @@
 r tr;%0A  
- 
- 
 try %7B%0A
-  
     try 
@@ -266,26 +266,24 @@
 %7B%0A    try %7B%0A
-  
       tr = r
@@ -375,26 +375,24 @@
 d()%7D));%0A    
-  
 %7D catch (ex)
@@ -390,26 +390,24 @@
 atch (ex) %7B%0A
-  
       tr = r
@@ -439,30 +439,26 @@
  name);%0A    
- 
- 
 %7D%0A
-  
     tr = jst
@@ -473,18 +473,16 @@
 er(tr);%0A
-  
   %7D catc
@@ -491,18 +491,16 @@
 (ex) %7B%7D%0A
-  
   if (tr
@@ -499,26 +499,24 @@
   if (tr) %7B%0A
-  
     // TODO:
@@ -583,26 +583,24 @@
 locals%22%0A    
- 
- 
 var result =
@@ -643,18 +643,16 @@
 dy;%0A    
-  
 if (opti
@@ -672,26 +672,24 @@
 s.minify) %7B%0A
-  
       try %7B%0A
@@ -696,18 +696,16 @@
         
-  
 switch (
@@ -729,26 +729,24 @@
 %7B%0A          
-  
 case 'js':%0A 
@@ -740,26 +740,24 @@
  case 'js':%0A
-  
             
@@ -821,35 +821,31 @@
             
-  
 break;%0A
-  
           ca
@@ -858,34 +858,32 @@
 s':%0A            
-  
 result = new Cle
@@ -921,35 +921,31 @@
             
-  
 break;%0A
-  
         %7D%0A  
@@ -948,18 +948,16 @@
 %7D%0A      
-  
 %7D catch 
@@ -959,26 +959,24 @@
 atch (ex) %7B%0A
-  
         // b
@@ -1029,26 +1029,20 @@
     
-  
 %7D%0A    
- 
- 
 %7D%0A    
- 
- 
 retu
@@ -1052,18 +1052,16 @@
 result;%0A
-  
   %7D else
@@ -1063,18 +1063,16 @@
  else %7B%0A
-  
     var 
@@ -1126,18 +1126,16 @@
 ');%0A    
-  
 err.code
@@ -1159,18 +1159,16 @@
 R';%0A    
-  
 throw er
@@ -1170,20 +1170,14 @@
 ow err;%0A
-    %7D%0A
   %7D%0A%7D%0A

Remove odd conditional in run-filter