<commit_before>'use strict';

var util = require('util');
var path = require('path');
var slash = require('slash');

var Block = function (config, file, match) {
    this.replacement = match[0];
    this.linefeed = match[1];
    this.indent = match[2];
    this.beginTag = match[3];
    this.taskName = match[4];
    this.originalContent = match[5];
    this.endTag = match[6];

    this.replacements = [];
    this.config = config;
    this.template = null;
    this.file = file;
};

Block.prototype.build = function () {
    if (!this.replacements.length) {
        return this.config.keepUnassigned ? [this.originalContent] : [];
    }

    // get the replacement strings and do replacements for extensions
    if (this.uniqueExts) {
        var basename = path.basename(this.file.path);
        var extname = path.extname(basename);
        basename = basename.slice(0, basename.lastIndexOf(extname));
        if (this.uniqueExts['%f']) {
            this.uniqueExts['%f'].value = basename;
        }
        if (this.uniqueExts['%e']) {
            this.uniqueExts['%e'].value = extname;
        }

        Object.keys(this.uniqueExts).forEach(function (key) {
            var unique = this.uniqueExts[key];
            this.template = this.template.replace(unique.regex, unique.value);
        }.bind(this));
    }

    if (this.srcIsNull) {
        return [this.indent + this.template];
    }

    return this.replacements.map(function (replacement) {
        if (this.template) {
            if (Array.isArray(replacement)) {
                replacement.unshift(this.template);
                return this.indent + util.format.apply(util, replacement);
            } else {
                return this.indent + util.format(this.template, replacement);
            }
        }

        if (this.config.resolvePaths) {
            var replacementPath = path.resolve(this.file.cwd, replacement);
            replacement = path.relative(this.file.dirname, replacementPath);
            replacement = slash(replacement);
        }

        var ext = replacement.split('.').pop().toLowerCase();

        //add build version or timestamp support
        //some file like main.js?ts=123124
        //some file like main.js?sha1=0a9d
        ext = ext.split('?')[0].toLowerCase();

        if (ext === 'js') {
            return util.format('%s<script src="%s"></script>', this.indent, replacement);
        } else if (ext === 'css') {
            return util.format('%s<link rel="stylesheet" href="%s">', this.indent, replacement);
        }
        return this.indent + replacement;
    }.bind(this));
};

Block.prototype.compile = function (tasks) {
    var task = tasks[this.taskName];
    
    if (task) {
        this.replacements = task.src;
        this.template = task.tpl;<commit_msg>file.dirname is only available in vinyl@0.5.0 and newer, using path.dirname to support the older versions.<commit_after>'use strict';

var util = require('util');
var path = require('path');
var slash = require('slash');

var Block = function (config, file, match) {
    this.replacement = match[0];
    this.linefeed = match[1];
    this.indent = match[2];
    this.beginTag = match[3];
    this.taskName = match[4];
    this.originalContent = match[5];
    this.endTag = match[6];

    this.replacements = [];
    this.config = config;
    this.template = null;
    this.file = file;
};

Block.prototype.build = function () {
    if (!this.replacements.length) {
        return this.config.keepUnassigned ? [this.originalContent] : [];
    }

    // get the replacement strings and do replacements for extensions
    if (this.uniqueExts) {
        var basename = path.basename(this.file.path);
        var extname = path.extname(basename);
        basename = basename.slice(0, basename.lastIndexOf(extname));
        if (this.uniqueExts['%f']) {
            this.uniqueExts['%f'].value = basename;
        }
        if (this.uniqueExts['%e']) {
            this.uniqueExts['%e'].value = extname;
        }

        Object.keys(this.uniqueExts).forEach(function (key) {
            var unique = this.uniqueExts[key];
            this.template = this.template.replace(unique.regex, unique.value);
        }.bind(this));
    }

    if (this.srcIsNull) {
        return [this.indent + this.template];
    }

    return this.replacements.map(function (replacement) {
        if (this.template) {
            if (Array.isArray(replacement)) {
                replacement.unshift(this.template);
                return this.indent + util.format.apply(util, replacement);
            } else {
                return this.indent + util.format(this.template, replacement);
            }
        }

        if (this.config.resolvePaths) {
            var replacementPath = path.resolve(this.file.cwd, replacement);
            replacement = path.relative(path.dirname(this.file.path), replacementPath);
            replacement = slash(replacement);
        }

        var ext = replacement.split('.').pop().toLowerCase();

        //add build version or timestamp support
        //some file like main.js?ts=123124
        //some file like main.js?sha1=0a9d
        ext = ext.split('?')[0].toLowerCase();

        if (ext === 'js') {
            return util.format('%s<script src="%s"></script>', this.indent, replacement);
        } else if (ext === 'css') {
            return util.format('%s<link rel="stylesheet" href="%s">', this.indent, replacement);
        }
        return this.indent + replacement;
    }.bind(this));
};

Block.prototype.compile = function (tasks) {
    var task = tasks[this.taskName];
    
    if (task) {
        this.replacements = task.src;
        this.template = task.tpl;
{'fraction_non_alphanumeric': 0.1444639718804921, 'fraction_numerical': 0.006854130052724078, 'mean_word_length': 2.341749853200235, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '6832958', 'n_tokens_mistral': 1697, 'n_tokens_neox': 1672, 'n_words': 349}