<commit_before>'use strict';

const Promise    = require('bluebird');
const Path       = require('path');
const co         = require('co');
const _          = require('lodash');
const Variant    = require('./variant');
const console    = require('../console');
const Entities   = require('../entities');
const utils      = require('../utils');

module.exports = class VariantCollection extends Entities {

    constructor(opts, items) {
        super(opts, items);
    }

    default() {
        return this.find('name', this.parent.defaultName);
    }

    getCollatedContentSync() {
        return (this.toArray().map(variant => {
            const content = variant.getContentSync();
            const collator = this.parent.collator;
            return _.isFunction(collator) ? collator(content, variant) : content;
        })).join('\n');
    }

    getCollatedContext() {
        let collated = {};
        this.toArray().forEach(variant => {
            collated[`@${variant.handle}`] = variant.context;
        });
        return collated;
    }

    static *create(component, defaultView, configured, views, opts) {

        configured   = configured || [];
        views        = views || [];
        let variants = [];
        const source = component.source;
        const assets = component.assets();

        // first figure out if we need a 'default' variant.
        const hasDefaultConfigured = _.find(configured, ['name', component.defaultName]);

        function isRelated(variantHandle) {
            return function (file) {
                if (file.name.includes(source.setting('splitter'))) {
                    return file.name === variantHandle;
                }<commit_msg>feat(components): better collated content for variants that share a template<commit_after>'use strict';

const Promise    = require('bluebird');
const Path       = require('path');
const co         = require('co');
const _          = require('lodash');
const Variant    = require('./variant');
const console    = require('../console');
const Entities   = require('../entities');
const utils      = require('../utils');

module.exports = class VariantCollection extends Entities {

    constructor(opts, items) {
        super(opts, items);
    }

    default() {
        return this.find('name', this.parent.defaultName);
    }

    getCollatedContentSync() {
        let view = this.default().view;
        let sharedView = true;
        let variantsArray = this.toArray();
        variantsArray.map(variant => {
            if (view !== variant.view) {
                sharedView = false;
            }
        });
        if (sharedView) {
            return this.default().getContentSync();
        }
        return (variantsArray.map(variant => {
            const content = variant.getContentSync();
            const collator = this.parent.collator;
            return _.isFunction(collator) ? collator(content, variant) : content;
        })).join('\n');
    }

    getCollatedContext() {
        let collated = {};
        this.toArray().forEach(variant => {
            collated[`@${variant.handle}`] = variant.context;
        });
        return collated;
    }

    static *create(component, defaultView, configured, views, opts) {

        configured   = configured || [];
        views        = views || [];
        let variants = [];
        const source = component.source;
        const assets = component.assets();

        // first figure out if we need a 'default' variant.
        const hasDefaultConfigured = _.find(configured, ['name', component.defaultName]);

        function isRelated(variantHandle) {
            return function (file) {
                if (file.name.includes(source.setting('splitter'))) {
                    return file.name === variantHandle;
                }
{'fraction_non_alphanumeric': 0.1348727368144844, 'fraction_numerical': 0.0, 'mean_word_length': 2.174021648626145, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '894244', 'n_tokens_mistral': 991, 'n_tokens_neox': 968, 'n_words': 234}