<commit_before>var fu = require('../fileUtil');

function isInline(context) {
  return (context.config.attributes.styles || {}).inline;
}

module.exports = {
  isInline: isInline,

  generatedFiles: function(context, next) {
    if (isInline(context) && context.mode === 'styles') {
      // Prevent stylesheet output if in inline mode
      return [];
    } else {
      return next();
    }
  },

  resource: function(context, next) {
    var resource = next();

    if (isInline(context) && (resource.style || /\.css$/.test(resource.src))) {
      var generator = function(callback) {
        function loaded(err, data) {
          if (err) {
            return callback(err);
          }

          var config = context.config,
              loaderName = config.attributes.styles.inlineLoader || (config.scopedAppModuleName(context.module) + '.loader.loadInlineCSS');
          callback(err, {
            data: loaderName + '("'
                + (data.data != null ? data.data : data)
                    .replace(/\\/g, '\\')
                    .replace(/\n/g, '\\n')
                    .replace(/"/g, '\\"')
                + '");\n',
            inputs: data.inputs,
            noSeparator: true
          });
        }
        if (typeof resource === 'function') {
          resource(loaded);
        } else if (resource.src) {
          fu.readFile(resource.src, loaded);
        }
      };
      generator.style = true;
      generator.sourceFile = resource.sourceFile || resource.src;
      return generator;
    }

    return resource;
  }
};<commit_msg>Move inline-styles plugin processing to module API<commit_after>var fu = require('../fileUtil');

function isInline(context) {
  return (context.config.attributes.styles || {}).inline;
}

module.exports = {
  isInline: isInline,

  generatedFiles: function(context, next) {
    if (isInline(context) && context.mode === 'styles') {
      // Prevent stylesheet output if in inline mode
      return [];
    } else {
      return next();
    }
  },

  module: function(context, next) {
    next();

    if (isInline(context)) {
      context.moduleResources = context.moduleResources.map(function(resource) {
         if (resource.style || /\.css$/.test(resource.src)) {
            var generator = function(callback) {
              fu.loadResource(resource, function(err, data) {
                if (err) {
                  return callback(err);
                }

                var config = context.config,
                    loaderName = config.attributes.styles.inlineLoader || (config.scopedAppModuleName(context.module) + '.loader.loadInlineCSS');
                callback(err, {
                  data: loaderName + '("'
                      + data.content
                          .replace(/\\/g, '\\')
                          .replace(/\n/g, '\\n')
                          .replace(/"/g, '\\"')
                      + '");\n',
                  inputs: data.inputs,
                  noSeparator: true
                });
              });
            };
            generator.style = true;
            generator.sourceFile = resource.sourceFile || resource.src;
            return generator;
          } else {
            return resource;
          }
        });
    }
  }
};
{'fraction_non_alphanumeric': 0.1426385062748699, 'fraction_numerical': 0.0, 'mean_word_length': 1.6185897435897436, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3839066', 'n_tokens_mistral': 894, 'n_tokens_neox': 877, 'n_words': 177}