<commit_before>/*!
 * assemble-render-file <https://github.com/jonschlinkert/assemble-render-file>
 *
 * Copyright (c) 2015, <NAME>.
 * Licensed under the MIT License.
 */

'use strict';

var utils = require('./utils');
var debug = utils.debug;

/**
 * Render a vinyl file.
 *
 * ```js
 * app.src('*.hbs')
 *   .pipe(app.renderFile());
 * ```
 *
 * @name .renderFile
 * @param  {Object} `locals` Optionally locals to pass to the template engine for rendering.
 * @return {Object}
 * @api public
 */

module.exports = function(config) {
  return function(app) {
    config = utils.merge({}, app.options, config);

    app.define('renderFile', function(engine, locals) {
      if (typeof engine !== 'string') {
        locals = engine;
        engine = null;
      }

      debug('renderFile: engine "%s"', engine);
      var opts = {};

      if (locals && !locals.isCollection) {
        opts = utils.merge({}, config, locals);
      }

      var View = opts.View || opts.File || app.View;

      return utils.through.obj(function(file, enc, next) {
        if (file.isNull()) {
          return next(null, file);
        }

        if (!file.isView) file = new View(file);

        // run `onLoad` middleware
        app.handle('onLoad', file, function(err, view) {
          if (err) return next(err);

          debug('renderFile, preRender: %s', view.relative);

          // create the context to pass to templates
          var ctx = utils.merge({}, app.cache.data, locals, view.data);
          ctx.engine = resolveEngine(app, ctx, engine);

          if (!ctx.engine && app.option('engineStrict') === false) {
            next(null, view);
            return;<commit_msg>use handleView to ensure onLoad is only called once for each file<commit_after>/*!
 * assemble-render-file <https://github.com/jonschlinkert/assemble-render-file>
 *
 * Copyright (c) 2015, <NAME>.
 * Licensed under the MIT License.
 */

'use strict';

var utils = require('./utils');
var debug = utils.debug;

/**
 * Render a vinyl file.
 *
 * ```js
 * app.src('*.hbs')
 *   .pipe(app.renderFile());
 * ```
 *
 * @name .renderFile
 * @param  {Object} `locals` Optionally locals to pass to the template engine for rendering.
 * @return {Object}
 * @api public
 */

module.exports = function(config) {
  return function(app) {
    config = utils.merge({}, app.options, config);

    app.define('renderFile', function(engine, locals) {
      if (typeof engine !== 'string') {
        locals = engine;
        engine = null;
      }

      debug('renderFile: engine "%s"', engine);
      var opts = {};

      if (locals && !locals.isCollection) {
        opts = utils.merge({}, config, locals);
      }

      var View = opts.View || opts.File || app.View;

      return utils.through.obj(function(file, enc, next) {
        if (file.isNull()) {
          return next(null, file);
        }

        if (!file.isView) file = new View(file);

        // run `onLoad` middleware
        app.handleView('onLoad', file, function(err, view) {
          if (err) return next(err);

          debug('renderFile, preRender: %s', view.relative);

          // create the context to pass to templates
          var ctx = utils.merge({}, app.cache.data, locals, view.data);
          ctx.engine = resolveEngine(app, ctx, engine);

          if (!ctx.engine && app.option('engineStrict') === false) {
            next(null, view);
            return;
{'fraction_non_alphanumeric': 0.15934387814879905, 'fraction_numerical': 0.0023432923257176333, 'mean_word_length': 2.4564777327935223, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1473458', 'n_tokens_mistral': 1055, 'n_tokens_neox': 1041, 'n_words': 282}