<commit_before>/* jshint node:true */
'use strict';

var fs = require('fs');
var path = require('path');
var cheerio = require('cheerio');
var glob = require('glob');
var gutil = require('gulp-util');
var through = require('through2');
var extend = require('lodash.assign');
var PluginError = gutil.PluginError;

module.exports = function(options) {
  options = extend({trim: true}, options);

  function transform(file, encoding, next) {

    if(file.isNull()) {
      return next(null, file); // pass along
    }

    var $ = cheerio.load(file.contents.toString('utf8'));

    // This function receives an ng-include src and tries to read it from the filesystem
    function readSource(src) {
      var cwd = path.dirname(file.path);
      var match = glob.sync(src, {cwd: cwd});
      if(!match.length) return next(new PluginError('gulp-nginclude', 'File "' + src + '" not found'));
      return fs.readFileSync(path.join(cwd, match[0])).toString();
    }

    function processTag(i, ng) {
      var $ng = $(ng);
      var src = $ng.attr('src') || $ng.attr('ng-include');
      if(!src.match(/^'[^']+'$/g)) return false;

      // Remove old ng-include attributes so Angular doesn't read them
      $ng.removeAttr('src').removeAttr('ng-include');

      var before = "\n<!-- ngInclude: " + src + " -->\n";
      var after = "\n<!--/ngInclude: " + src + " -->\n";
      var include = readSource(src.substr(1, src.length - 2));
      if(options.trim) include = include.trim();
      $ng.html(before + include + after);
      return true;
    }<commit_msg>feat(main): add support for assetsDir<commit_after>/* jshint node:true */
'use strict';

var fs = require('fs');
var path = require('path');
var cheerio = require('cheerio');
var glob = require('glob');
var gutil = require('gulp-util');
var through = require('through2');
var extend = require('lodash.assign');
var PluginError = gutil.PluginError;

module.exports = function(options) {
  options = extend({trim: true}, options);

  function transform(file, encoding, next) {

    if(file.isNull()) {
      return next(null, file); // pass along
    }

    var $ = cheerio.load(file.contents.toString('utf8'));

    // This function receives an ng-include src and tries to read it from the filesystem
    function readSource(src) {
      var cwd = path.dirname(file.path);
      if(options.assetsDirs && options.assetsDirs.length) {
        var basename = path.basename(cwd);
        if(options.assetsDirs.indexOf(basename) === -1) {
          options.assetsDirs.unshift(path.basename(cwd));
        }
        src = path.join('{' + options.assetsDirs.join(',') + '}', src);
        cwd = path.dirname(cwd);
      }
      var match = glob.sync(src, {cwd: cwd});
      if(!match.length) return next(new PluginError('gulp-nginclude', 'File "' + src + '" not found'));
      return fs.readFileSync(path.join(cwd, match[0])).toString();
    }

    function processTag(i, ng) {
      var $ng = $(ng);
      var src = $ng.attr('src') || $ng.attr('ng-include');
      if(!src.match(/^'[^']+'$/g)) return false;

      // Remove old ng-include attributes so Angular doesn't read them
      $ng.removeAttr('src').removeAttr('ng-include');

      var before = "\n<!-- ngInclude: " + src + " -->\n";
      var after = "\n<!--/ngInclude: " + src + " -->\n";
      var include = readSource(src.substr(1, src.length - 2));
      if(options.trim) include = include.trim();
      $ng.html(before + include + after);
      return true;
    }
{'fraction_non_alphanumeric': 0.18085106382978725, 'fraction_numerical': 0.0031627372052903968, 'mean_word_length': 3.0977620730270905, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, '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': '1143316', 'n_tokens_mistral': 1126, 'n_tokens_neox': 1095, 'n_words': 276}