Пример #1
0
function wrapInPage(bemjson, meta) {
    var basename = path.basename(meta.filename, '.bemjson.js'),
        shortBemjsonFilename = meta.filename.replace('.bemjson.js', '.short.bemjson.js');

    mkdirp.sync(path.dirname(shortBemjsonFilename));
    fs.writeFileSync(shortBemjsonFilename, "(" + JSON.stringify(bemjson) + ")");

    if (libConf.coreLib === 'bem-bl') {
        return {
            block: 'b-page',
            title: naming.stringify(meta.notation),
            head: [{ elem: 'css', url: basename + '.css' }],
            content: [
                bemjson,
                { elem: 'js', url: 'https://yastatic.net/jquery/1.8.3/jquery.min.js' },
                { elem: 'js', url: basename + '.js' }
            ]
        };
    }

    return {
        block: 'page',
        title: naming.stringify(meta.notation),
        head: [{ elem: 'css', url: basename + '.css' }],
        scripts: [{ elem: 'js', url: basename + '.js' }],
        mods: { theme: getThemeFromBemjson(bemjson) },
        content: bemjson
    };
}
Пример #2
0
    typify(entity) {
        var id = stringifyEntity(entity),
            type = entityType(entity);

        this._entityMap.set(id, entity);
        this._typedIds[type].add(id);
    }
Пример #3
0
    dependenciesOf(entity) {
        var id = stringifyEntity(entity);

        var entityMap = this._entityMap,
            orderedSet = this._orderedDependencyMap.get(id),
            unorderedSet = this._unorderedDependencyMap.get(id);

        if (!orderedSet && !unorderedSet) return new Set().values();

        var orderedIterator = orderedSet && orderedSet.values(),
            unorderedIterator = unorderedSet && unorderedSet.values();

        return {
            [Symbol.iterator]: function () {
                return this;
            },
            next: function () {
                var item = this._iterator.next(),
                    isDone = item.done;

                if (isDone && this._iterator === orderedIterator) {
                    this._iterator = unorderedIterator;
                }

                return {
                    value: entityMap.get(item.value),
                    done: item.done
                };
            },
            _iterator: orderedIterator || unorderedIterator
        };
    }
Пример #4
0
	return loop.map(function (item) {
		var key = stringifyEntity(item.entity),
			tech = item.tech;

		if (tech) {
			return key + '.' + tech;
		}

		return key;
	}).join(' <- ');
Пример #5
0
    addDependency(fromEntity, toEntity, params) {
        params || (params = {});

        var fromId = stringifyEntity(fromEntity),
            toId = stringifyEntity(toEntity);

        this._entityMap.set(fromId, fromEntity);
        fromEntity.id = fromId; // TODO: fixme
        this._entityMap.set(toId, toEntity);
        toEntity.id = toId;

        var map = params.order ? this._orderedDependencyMap : this._unorderedDependencyMap;

        if (!map.has(fromId)) {
            map.set(fromId, new Set());
        }

        map.get(fromId).add(toId);
    }
Пример #6
0
function wrapInPage(bemjson, meta) {
    var basename = '_' + path.basename(meta.filename, '.bemjson.js');
    return {
        block : 'page',
        title : naming.stringify(meta.notation),
        head : [{ elem : 'css', url : basename + '.css' }],
        scripts : [{ elem : 'js', url : basename + '.js' }],
        mods : { theme : getThemeFromBemjson(bemjson) },
        content : bemjson
    };
}
Пример #7
0
            [Symbol.iterator]: function * () {
                function* step(track) {
                    var previousId = track[track.length - 1];

                    if (visitedIds.has(previousId)) return;

                    visitedIds.add(previousId);

                    var orderedDependencies = graph._orderedDependencyMap.get(previousId) || new Set().values(),
                        unorderedDependencies = graph._unorderedDependencyMap.get(previousId) || new Set().values();

                    for (let id of orderedDependencies) {
                        // игнорируем зависимость самого на себя
                        if (previousId === id) continue;

                        // проверяем нет ли циклической ordered-зависимости
                        var loopFirstIndex = track.indexOf(id);
                        if (loopFirstIndex !== -1) {
                            // добавляем в цепь замыкающую сущность
                            track.push(id);
                            // формируем цепь для ошибки
                            var errorInfo = track.slice(loopFirstIndex).map(errorObject);

                            throw new DependencyError(errorInfo);
                        }

                        yield [entityMap.get(id), true, previousId];

                        yield* step(track.concat(id));
                    }

                    function errorObject(key) {
                        return {
                            entity: parseId(key)
                        };
                    }

                    for (let id of unorderedDependencies) {
                        // игнорируем зависимость самого на себя
                        if (previousId === id) continue;

                        yield [entityMap.get(id), undefined, previousId];

                        yield* step([id]);
                    }
                }

                var startId = stringifyEntity(startEntity);

                yield* step([startId]);
            }
Пример #8
0
                    .on('data', function (file) {
                        const id = stringifyEntity(file.entity);

                        promises.push(new Promise((resolve, reject) => {
                            fs.stat(file.path, (err, stats) => {
                                if (err) {
                                    return reject(err);
                                }

                                file.isDirectory = stats.isDirectory();
                                file.mtime = stats.mtime;

                                (data[id] || (data[id] = [])).push(file);

                                resolve();
                            });
                        }));
                    })
Пример #9
0
function generateBemPath(dep, tech) {
    var path = `${dep.block}/`;
    var filename = `${bemNaming.stringify(dep)}.${tech}`;

    if (bemNaming.isBlock(dep)) {
        path = `${path}${filename}`;
    }

    if (bemNaming.isElem(dep)) {
        path = `${path}__${dep.elem}/${filename}`;
    }

    if (bemNaming.isBlockMod(dep)) {
        path = `${path}_${dep.modName}/${filename}`;
    }

    if (bemNaming.isElemMod(dep)) {
        path = `${path}__${dep.elem}/_${dep.modName}/${filename}`;
    }

    return path;
}
Пример #10
0
    _dependenciesOfFromMap(entity, map) {
        var id = stringifyEntity(entity);

        var entityMap = this._entityMap,
            dependenceEntities = map.get(id);

        if (!dependenceEntities) return new Set().values();

        var iterator = dependenceEntities.values();

        return {
            [Symbol.iterator]: function () {
                return this;
            },
            next: function () {
                var item = iterator.next();

                return {
                    value: entityMap.get(item.value),
                    done: item.done
                };
            }
        };
    }