<commit_before>/*
 * grunt-nginclude
 * https://github.com/mgcrea/grunt-nginclude
 *
 * Copyright (c) 2014 <NAME>
 * Licensed under the MIT license.
 */

'use strict';

module.exports = function(grunt) {

  // Please see the Grunt documentation for more information regarding task
  // creation: http://gruntjs.com/creating-tasks

  var chalk = require('chalk');
  var cheerio = require('cheerio');

  grunt.registerMultiTask('nginclude', 'Embed static ngIncludes.', function() {

    // Merge task-specific and/or target-specific options with these defaults.
    var options = this.options({
      assetsDirs: [this.target]
    });

    // Process some options to create others.
    options.baseSearchpath = options.assetsDirs.length > 1 ? '{' + options.assetsDirs.join(',') + '}' : options.assetsDirs[0];

    // This function receives an ng-include src and tries to read it from the filesystem.
    var readSource = function(src) {
      var searchpath = options.baseSearchpath + '/' + src.substr(1, src.length - 2);
      var foundfiles = grunt.file.expand(searchpath);
      if(!foundfiles.length) {
        grunt.log.warn('Included file "' + searchpath + '" not found.');
        return;
      }
      var include = grunt.file.read(foundfiles[0]).trim();
      return include;
    };

    // Heavy lifting is done here. Parses ng-include tags and includes the source contents inside them.
    var processHtml = function(html) {
      var $ = cheerio.load(html);

      // Use while to make the task recursive.
      while (true) {
        var tags = $('ng-include, [ng-include]');

        // If we don't find any more ng-include tags, we're done.
        if (tags.length === 0) {
          return $.html();
        }

        // For each tag, grab the associated source file and sub it in.
        tags.each(function(i, ng) {
          var $ng = $(ng);
          var src = $ng.attr('src') || $ng.attr('ng-include');

          if(!src.match(/^'.+'$/g)) {
            return;
          }

          // Remove old ng-include attributes so Angular doesn't read them.
          $ng.removeAttr('src').removeAttr('ng-include');
          
          var comment1 = "\n<!-- ngInclude: '" + src + "' -->\n";
          var comment2 = "\n<!--/ngInclude: '" + src + "' -->\n";
          var include = readSource(src);

          // As per Angular's behaviour, the included source is put inside the 
          $ng.html(comment1 + include + comment2);
        });
      }
    };

    // Iterate over all specified file groups.
    this.files.forEach(function(f) {
      // Concat specified files.
      var src = f.src.filter(function(filepath) {
        // Warn on and remove invalid source files (if nonull was set).
        if (!grunt.file.exists(filepath)) {
          grunt.log.warn('Source file "' + filepath + '" not found.');
          return false;
        } else {
          return true;
        }
      }).map(function(filepath) {
        // Read file source.
        return grunt.file.read(filepath);
      }).map(function(html) {
        // Process the file's HTML source. 
        return processHtml(html);<commit_msg>chore(jshint): make jshint happy<commit_after>/*
 * grunt-nginclude
 * https://github.com/mgcrea/grunt-nginclude
 *
 * Copyright (c) 2014 <NAME>
 * Licensed under the MIT license.
 */

'use strict';

module.exports = function(grunt) {

  // Please see the Grunt documentation for more information regarding task
  // creation: http://gruntjs.com/creating-tasks

  var chalk = require('chalk');
  var cheerio = require('cheerio');

  grunt.registerMultiTask('nginclude', 'Embed static ngIncludes.', function() {

    // Merge task-specific and/or target-specific options with these defaults.
    var options = this.options({
      assetsDirs: [this.target]
    });

    // Process some options to create others.
    options.baseSearchpath = options.assetsDirs.length > 1 ? '{' + options.assetsDirs.join(',') + '}' : options.assetsDirs[0];

    // This function receives an ng-include src and tries to read it from the filesystem.
    var readSource = function(src) {
      var searchpath = options.baseSearchpath + '/' + src.substr(1, src.length - 2);
      var foundfiles = grunt.file.expand(searchpath);
      if(!foundfiles.length) {
        grunt.log.warn('Included file "' + searchpath + '" not found.');
        return;
      }
      var include = grunt.file.read(foundfiles[0]).trim();
      return include;
    };

    // Heavy lifting is done here. Parses ng-include tags and includes the source contents inside them.
    var processHtml = function(html) {
      var $ = cheerio.load(html);

      function processTag(i, ng) {
        var $ng = $(ng);
        var src = $ng.attr('src') || $ng.attr('ng-include');

        if(!src.match(/^'.+'$/g)) {
          return;
        }

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

        var comment1 = "\n<!-- ngInclude: '" + src + "' -->\n";
        var comment2 = "\n<!--/ngInclude: '" + src + "' -->\n";
        var include = readSource(src);

        // As per Angular's behaviour, the included source is put inside the
        $ng.html(comment1 + include + comment2);
      }

      // Use while to make the task recursive.
      while (true) {
        var tags = $('ng-include, [ng-include]');

        // If we don't find any more ng-include tags, we're done.
        if (tags.length === 0) {
          return $.html();
        }

        // For each tag, grab the associated source file and sub it in.
        tags.each(processTag);
      }
    };

    // Iterate over all specified file groups.
    this.files.forEach(function(f) {
      // Concat specified files.
      var src = f.src.filter(function(filepath) {
        // Warn on and remove invalid source files (if nonull was set).
        if (!grunt.file.exists(filepath)) {
          grunt.log.warn('Source file "' + filepath + '" not found.');
          return false;
        } else {
          return true;
        }
      }).map(function(filepath) {
        // Read file source.
        return grunt.file.read(filepath);
      }).map(function(html) {
        // Process the file's HTML source.
        return processHtml(html);
{'fraction_non_alphanumeric': 0.14105431309904154, 'fraction_numerical': 0.0044728434504792336, 'mean_word_length': 2.245723172628305, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '5352009', 'n_tokens_mistral': 1873, 'n_tokens_neox': 1804, 'n_words': 524}