Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions packages/core/src/lib/object_factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,18 @@ const Pattern = function(relPath, data, patternlab) {
info.dir = info.hasDir ? pathObj.dir.split(path.sep).pop() : '';
info.dirLevel = pathObj.dir.split(path.sep).length;

this.maxNestingLevel = this.getMaxNestingLevel(patternlab);
this.relPath = path.normalize(relPath); // '00-atoms/00-global/00-colors.mustache'
this.fileName = pathObj.name; // '00-colors'
this.subdir = pathObj.dir; // '00-atoms/00-global'
if ((this.subdir.match(/\w(?=\\)|\w(?=\/)/g) || []).length > 1) {
this.subdir = this.subdir.split(/\/|\\/, 2).join(path.sep); // '00-atoms/03-controls/00-button' -> '00-atoms/03-controls'
if ((this.subdir.match(/\w(?=\\)|\w(?=\/)/g) || []).length > (this.maxNestingLevel - 1)) {
this.subdir = this.subdir.split(/\/|\\/, this.maxNestingLevel).join(path.sep); // '00-atoms/03-controls/00-button' -> '00-atoms/03-controls'
}
this.fileExtension = pathObj.ext; // '.mustache'

// this is the unique name, subDir + fileName (sans extension)
this.name = '';
if (info.hasDir && info.dirLevel > 2) {
if (info.hasDir && info.dirLevel > this.maxNestingLevel) {
let variant = '';

if (this.fileName.indexOf('~') !== -1) {
Expand Down Expand Up @@ -92,7 +93,7 @@ const Pattern = function(relPath, data, patternlab) {

// the joined pattern group and subgroup directory
this.flatPatternPath =
info.hasDir && info.dirLevel > 2
info.hasDir && info.dirLevel > this.maxNestingLevel
? this.subdir
.replace(/[/\\]/g, '-')
.replace(new RegExp('-' + info.dir + '$'), '')
Expand Down Expand Up @@ -229,6 +230,15 @@ Pattern.prototype = {
return '';
}
},

getMaxNestingLevel: function(patternlab) {
let maxNestingLevel = 2;
// if (typeof patternlab?.config?.maxNestingLevel !== "undefined") {
if (typeof ((patternlab || {}).config || {}).maxNestingLevel !== "undefined") {
maxNestingLevel = patternlab.config.maxNestingLevel;
}
return maxNestingLevel;
},
};

// Pattern static methods
Expand Down