<commit_before>// Settings parser
// This gulp task pulls the variables out of each component's Sass file, and collects them in one settings file.
// Use it like this:
// gulp.task('settings', function() {
//   return require('settings-parser')('scss/**/*.scss');
// });

var concat     = require('gulp-concat')  
var extend     = require('util')._extend;
var format     = require('util').format;
var fs         = require('fs');
var gulp       = require('gulp');
var gutil      = require('gulp-util');
var ignore     = require('gulp-ignore');
var inject     = require('gulp-inject-string');
var repeatChar = require('./lib/repeatChar');
var rename     = require('gulp-rename');
var multiline  = require('multiline');
var path       = require('path');
var order      = require('gulp-order');
var sassdoc    = require('sassdoc');
var through    = require('through2');

var noop = function() {};

var titleText = multiline(function() {/*
//  %s
//  %s
//
//  Table of Contents:
//
*/});

module.exports = function(paths, options) {
  // The plugin must be called with a string or array of globs
  if (typeof paths === 'undefined') {
    var err = new gutil.PluginError('foundation-settings-parser', {
      message: 'you need to specify paths for the plugin to parse.'
    });
  }

  options = extend({
    title:        "SETTINGS",
    output:       '_settings.scss'
  }, options);

  sassdoc.parse(paths, { verbose: true }).then(parse);

  function parse(data) {
    var outputPath = path.join(process.cwd(), options.settingsPath);
    data = processSassDoc(data);

    // Erase the existing files
    if (fs.existsSync(outputPath)) {
      fs.unlinkSync(outputPath);
    }

    var outputStream = fs.createWriteStream(outputPath, {flags: 'w'});

    // Format title text with custom title
    titleText = format(titleText, options.title, repeatChar('-', options.title.length));

    var n = 1;
    for (var i in data) {
      var c = n < 10 ? ' '+n : n;
      titleText += format('\n//  %s. %s', c, i);
      n++;
    }

    outputStream.write(titleText);
    outputStream.write('\n\n');

    // Iterate through each component
    for (var i in data) {
      var group = data[i];

      outputStream.write(format('// %s\n// %s\n\n', i, repeatChar('-', i.length)));

      // Iterate through each variable within the component
      for (var j in group) {
        var variable = data[i][j];
        var value = variable.context.value.split('\n');

        if (value.length === 1) {
          outputStream.write(format('// $%s: %s;\n', variable.context.name, variable.context.value));
        }
      }

      outputStream.write('\n');
    }
  }

  function processSassDoc(tree) {
    var sass = {};

    for (var i in tree) {
      var obj = tree[i];
      var group = obj.group[0];

      if (!sass[group]) sass[group] = [];
      if (obj.context.type === 'variable') sass[group].push(obj);<commit_msg>Properly print out multiline Sass variables with comment markets<commit_after>// Settings parser
// This gulp task pulls the variables out of each component's Sass file, and collects them in one settings file.
// Use it like this:
// gulp.task('settings', function() {
//   return require('settings-parser')('scss/**/*.scss');
// });

var concat     = require('gulp-concat')  
var extend     = require('util')._extend;
var format     = require('util').format;
var fs         = require('fs');
var gulp       = require('gulp');
var gutil      = require('gulp-util');
var ignore     = require('gulp-ignore');
var inject     = require('gulp-inject-string');
var repeatChar = require('./lib/repeatChar');
var rename     = require('gulp-rename');
var multiline  = require('multiline');
var path       = require('path');
var order      = require('gulp-order');
var sassdoc    = require('sassdoc');
var through    = require('through2');

var noop = function() {};

var titleText = multiline(function() {/*
//  %s
//  %s
//
//  Table of Contents:
//
*/});

module.exports = function(paths, options) {
  // The plugin must be called with a string or array of globs
  if (typeof paths === 'undefined') {
    var err = new gutil.PluginError('foundation-settings-parser', {
      message: 'you need to specify paths for the plugin to parse.'
    });
  }

  options = extend({
    title:        "SETTINGS",
    output:       '_settings.scss'
  }, options);

  sassdoc.parse(paths, { verbose: true }).then(parse);

  function parse(data) {
    var outputPath = path.join(process.cwd(), options.settingsPath);
    data = processSassDoc(data);

    // Erase the existing files
    if (fs.existsSync(outputPath)) {
      fs.unlinkSync(outputPath);
    }

    var outputStream = fs.createWriteStream(outputPath, {flags: 'w'});

    // Format title text with custom title
    titleText = format(titleText, options.title, repeatChar('-', options.title.length));

    // Generate the table of contents
    var n = 1;
    for (var i in data) {
      var c = n < 10 ? ' '+n : n;
      titleText += format('\n//  %s. %s', c, i);
      n++;
    }

    outputStream.write(titleText);
    outputStream.write('\n\n');

    // Iterate through each component
    for (var i in data) {
      var group = data[i];
      outputStream.write(format('// %s\n// %s\n\n', i, repeatChar('-', i.length)));

      // Iterate through each variable within the component
      for (var j in group) {
        var variable = data[i][j];
        var value = variable.context.value.split('\n');

        if (value.length === 1) {
          outputStream.write(format('// $%s: %s;\n', variable.context.name, variable.context.value));
        }
        else {
          value = value.map(function(v, i) {
            if (i === 0) return v;
            return '// ' + v;
          });
          outputStream.write(format('// $%s: %s;\n', variable.context.name, value.join('\n')));
        }
      }

      outputStream.write('\n');
    }
  }

  function processSassDoc(tree) {
    var sass = {};

    for (var i in tree) {
      var obj = tree[i];
      var group = obj.group[0];

      if (!sass[group]) sass[group] = [];
      if (obj.context.type === 'variable') sass[group].push(obj);
{'fraction_non_alphanumeric': 0.1649014176307642, 'fraction_numerical': 0.0021182988430829396, 'mean_word_length': 2.6319526627218934, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '269426', 'n_tokens_mistral': 1953, 'n_tokens_neox': 1903, 'n_words': 532}