Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove styleModifiers #1452

Merged
merged 10 commits into from
Dec 28, 2022
Merged
14 changes: 0 additions & 14 deletions packages/core/src/lib/expandPartials.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

const logger = require('./log');
const ph = require('./parameter_hunter');
const smh = require('./style_modifier_hunter');
const jsonCopy = require('./json_copy');
const getPartial = require('./get');

const parameter_hunter = new ph();
const style_modifier_hunter = new smh();

module.exports = function (currentPattern, patternlab) {
const processRecursive = require('./processRecursive');
Expand Down Expand Up @@ -47,18 +45,6 @@ module.exports = function (currentPattern, patternlab) {
`partial pattern ${partial}`
);

//if partial has style modifier data, replace the styleModifier value
if (
currentPattern.stylePartials &&
currentPattern.stylePartials.length > 0
) {
style_modifier_hunter.consume_style_modifier(
cleanPartialPattern,
foundPartial,
patternlab
);
}

//this is what we came here for
logger.debug(
`within ${currentPattern.patternPartial}, replacing extendedTemplate partial ${foundPartial} with ${cleanPartialPattern.patternPartial}'s extendedTemplate`
Expand Down
4 changes: 0 additions & 4 deletions packages/core/src/lib/loadPattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,6 @@ module.exports = function (relPath, patternlab) {

currentPattern.template = fs.readFileSync(templatePath, 'utf8');

//find any stylemodifiers that may be in the current pattern
currentPattern.stylePartials =
currentPattern.findPartialsWithStyleModifiers();

//find any pattern parameters that may be in the current pattern
currentPattern.parameteredPartials =
currentPattern.findPartialsWithPatternParameters();
Expand Down
4 changes: 0 additions & 4 deletions packages/core/src/lib/object_factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,6 @@ Pattern.prototype = {
return this.engine.findPartials(this);
},

findPartialsWithStyleModifiers: function () {
return this.engine.findPartialsWithStyleModifiers(this);
},

findPartialsWithPatternParameters: function () {
return this.engine.findPartialsWithPatternParameters(this);
},
Expand Down
12 changes: 0 additions & 12 deletions packages/core/src/lib/parameter_hunter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
'use strict';

const smh = require('./style_modifier_hunter');
const style_modifier_hunter = new smh();

const getPartial = require('./get');
const logger = require('./log');
const parseLink = require('./parseLink');
Expand Down Expand Up @@ -313,15 +310,6 @@ const parameter_hunter = function () {
}
}

//if partial has style modifier data, replace the styleModifier value
if (pattern.stylePartials && pattern.stylePartials.length > 0) {
style_modifier_hunter.consume_style_modifier(
partialPattern,
pMatch,
patternlab
);
}

// set pattern.extendedTemplate pMatch with replacedPartial
pattern.extendedTemplate = pattern.extendedTemplate.replace(
pMatch,
Expand Down
3 changes: 0 additions & 3 deletions packages/core/src/lib/processIterative.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ module.exports = function (pattern, patternlab) {
return pph
.find_pseudopatterns(pattern, patternlab)
.then(() => {
//find any stylemodifiers that may be in the current pattern
pattern.stylePartials = pattern.findPartialsWithStyleModifiers();

//find any pattern parameters that may be in the current pattern
pattern.parameteredPartials = pattern.findPartialsWithPatternParameters();
return Promise.resolve(pattern);
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/lib/pseudopattern_hunter.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ pseudopattern_hunter.prototype.find_pseudopatterns = function (
extendedTemplate: currentPattern.extendedTemplate,
isPseudoPattern: true,
basePattern: currentPattern,
stylePartials: currentPattern.stylePartials,
parameteredPartials: currentPattern.parameteredPartials,

// Only regular patterns are discovered during iterative walks
Expand Down
45 changes: 0 additions & 45 deletions packages/core/src/lib/style_modifier_hunter.js

This file was deleted.

7 changes: 0 additions & 7 deletions packages/core/test/engine_handlebars_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,6 @@ tap.test(
}
);

tap.test(
'find_pattern_partials finds simple partials with style modifiers',
function (test) {
testFindPartials(test, ['{{> molecules-single-comment:foo }}']);
}
);

tap.test(
'find_pattern_partials finds partials with handlebars parameters',
function (test) {
Expand Down
87 changes: 0 additions & 87 deletions packages/core/test/engine_mustache_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,32 +71,6 @@ function testFindPartials(test, partialTests) {
test.end();
}

function testFindPartialsWithStyleModifiers(test, partialTests) {
test.plan(partialTests.length + 1);

// setup current pattern from what we would have during execution
// docs on partial syntax are here:
// https://patternlab.io/docs/including-patterns/
var currentPattern = Pattern.create(
'molecules/testing/test-mol.mustache', // relative path now
null, // data
{
template: partialTests.join(eol),
}
);

// act
var results = currentPattern.findPartialsWithStyleModifiers();

// assert
test.equal(results.length, partialTests.length);
partialTests.forEach(function (testString, index) {
test.equal(results[index], testString);
});

test.end();
}

function testFindPartialsWithPatternParameters(test, partialTests) {
test.plan(partialTests.length + 1);

Expand Down Expand Up @@ -160,63 +134,13 @@ tap.test(
}
);

tap.test(
'find_pattern_partials finds simple partials with style modifiers',
function (test) {
testFindPartials(test, [
'{{> molecules-single-comment:foo }}',
'{{> molecules-single-comment:foo|bar }}',
]);
}
);

tap.test('find_pattern_partials finds mixed partials', function (test) {
testFindPartials(test, [
'{{> molecules-single-comment:foo(description: "test", anotherThing: true) }}',
'{{> molecules-single-comment:foo|bar(description: true) }}',
]);
});

tap.test(
'find_pattern_partials finds one simple partial with styleModifier',
function (test) {
testFindPartialsWithStyleModifiers(test, [
'{{> molecules-comment-header:test}}',
]);
}
);

tap.test(
'find_pattern_partials finds partial with many styleModifiers',
function (test) {
testFindPartialsWithStyleModifiers(test, [
'{{> molecules-comment-header:test|test2|test3}}',
]);
}
);

tap.test(
'find_pattern_partials finds partials with differing styleModifiers',
function (test) {
testFindPartialsWithStyleModifiers(test, [
'{{> molecules-comment-header:test|test2|test3}}',
'{{> molecules-comment-header:foo-1}}',
'{{> molecules-comment-header:bar_1}}',
]);
}
);

tap.test(
'find_pattern_partials finds partials with styleModifiers when parameters present',
function (test) {
testFindPartialsWithStyleModifiers(test, [
'{{> molecules-comment-header:test|test2|test3(description: true)}}',
"{{> molecules-comment-header:foo-1(description: 'foo')}}",
"{{> molecules-comment-header:bar_1(descrition: 'bar', anotherThing: 10102010) }}",
]);
}
);

tap.test(
'find_pattern_partials_with_parameters finds one simple partial with parameters',
function (test) {
Expand All @@ -240,14 +164,3 @@ tap.test(
]);
}
);

tap.test(
'find_pattern_partials finds partials with parameters when styleModifiers present',
function (test) {
testFindPartialsWithPatternParameters(test, [
'{{> molecules-comment-header:test|test2|test3(description: true)}}',
"{{> molecules-comment-header:foo-1(description: 'foo')}}",
"{{> molecules-comment-header:bar_1(descrition: 'bar', anotherThing: 10102010) }}",
]);
}
);
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div class="{{styleModifier}}">
<div class="{{ additionalClasses }}">
{{> test-link }}
</div>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{> test-paramMiddle(styleModifier: "foo") }}
{{> test-paramMiddle(additionalClasses: "foo") }}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<span class="test_base {{styleModifier}}">
<span class="test_base {{ additionalClasses }}">
{{message}}
</span>
28 changes: 0 additions & 28 deletions packages/core/test/index_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,34 +253,6 @@ tap.test('buildPatterns suite', (test) => {
}
);

tap.test(
'correctly ignores bookended partials without a style modifier when the same partial has a style modifier between',
(test) => {
var pattern = get('test-bookend-listitem', patternlab);
test.equal(
util.sanitized(pattern.extendedTemplate),
util.sanitized(`<div class="test_group">
{{#listItems-two}}
<span class="test_base {{styleModifier}}">
{{message}}
</span>

<span class="test_base test_1">
{{message}}
</span>

<span class="test_base {{styleModifier}}">
{{message}}
</span>

{{/listItems-two}}
</div>
`)
);
test.end();
}
);

tap.test(
'listItems keys (`one` through `twelve`) can be used more than once per pattern',
(test) => {
Expand Down
Loading