/*
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

/**
 *  Express 3.x support.
 */
var fs = require('fs');

module.exports = function (Hogan) {
  if (typeof Hogan === 'undefined'
    || typeof Hogan.scan === 'undefined'
    || typeof Hogan.parse === 'undefined'
    || typeof Hogan.generate === 'undefined') {
      throw new Error('please, require Hogan!');
  }

  Hogan.fcache = {};

  Hogan.fcompile = function (path, options) {
    options = options || {};
    options.filename = path;

    var key = path + ':string';

    if (options.cache && Hogan.fcache[key]) {
      return Hogan.fcache[key];
    }
   
      var text = fs.readFileSync(path, 'utf8');

    try { 
      var rt = Hogan.generate(Hogan.parse(Hogan.scan(text, options.delimiters), text, options), text, options);
    } catch (error) {
      throw new Error('missing read template file : '+path);
    }

    return options.cache ? Hogan.fcache[key] = rt : rt;
  };

  Hogan.renderFile = function (path, options, fn) {
    try {
      fn(null, Hogan.fcompile(path,options).render(options));
    } catch (error) {
      fn(error);
    }
  };

  Hogan.__express = Hogan.renderFile;

  return Hogan;
}

@@ -618,16 +618,60 @@
 ('fs');%0A
+var _path = require('path');%0Avar ctx = %7B%7D;%0A%0A
 %0Amodule.
@@ -1163,19 +1163,16 @@
 ;%0A    %7D%0A
-   
 %0A      v
@@ -1212,16 +1212,20 @@
 utf8');%0A
+    
 %0A    try
@@ -1498,67 +1498,565 @@
 %0A%0A  
-Hogan.renderFile = function (path, options, fn) %7B%0A    try %7B
+renderPartials = function(partials, opt) %7B%0A    var count, name, path, result;%0A    count = 1;%0A    result = %7B%7D;%0A    for (name in partials) %7B%0A      path = partials%5Bname%5D;%0A      if (typeof path !== 'string') %7B%0A        continue;%0A      %7D%0A      if (!_path.extname(path)) %7B%0A         path += ctx.ext;%0A      %7D%0A      path = ctx.lookup(path);%0A      count++;%0A      result%5Bname%5D = Hogan.fcompile(path,opt);%0A    %7D%0A    return result;%0A  %7D;%0A%0A%0A  Hogan.renderFile = function (path, options, fn) %7B%0A    ctx = this;%0A    try %7B%0A      var partials = renderPartials(options.partials);
 %0A   
@@ -2110,16 +2110,25 @@
 (options
+,partials
 ));%0A    

Add support for rendering partials