Skip to content

Commit

Permalink
Support multiple font-{x} rules. (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
ReDrUm authored and bfred-it committed Dec 21, 2016
1 parent 56c3ee4 commit d54476a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -28,7 +28,7 @@ var declWalker = function (decl) {

var objFit = decl.value;

var existingFont = getLastPropertyDecl(parent, /font|font-family/);
var existingFont = getLastPropertyDecl(parent, /^font(-family)?$/);
var objPosition = getLastPropertyDecl(parent, 'object-position');

var value = [
Expand Down
26 changes: 16 additions & 10 deletions test.js
Expand Up @@ -15,19 +15,19 @@ function run(t, input, output, opts = {}) {
test('adds font-family declaration', (t) => {
return run(
t,
'a{object-fit:cover}',
'a{font-family:"object-fit:cover";object-fit:cover}',
'a{object-fit:cover;}',
'a{font-family:"object-fit:cover";object-fit:cover;}',
{ }
);
});

test('adds object-position declaration', (t) => {
return run(
t,
'a{object-fit: cover;object-position: top}',
'a{object-fit: cover;object-position: top;}',
'a{font-family: "object-fit:cover;object-position:top";' +
'object-fit: cover;' +
'object-position: top}',
'object-position: top;}',
{ }
);
});
Expand All @@ -38,14 +38,16 @@ test('keeps existing font-family declaration', (t) => {
'a{' +
'object-fit: cover;' +
'object-position: top;' +
'font-family: "Helvetica Neue", Helvetica, sans-serif' +
'font-family: "Helvetica Neue", Helvetica, sans-serif;' +
'font-weight: bold;' +
'}',
'a{' +
'object-fit: cover;' +
'object-position: top;' +
'font-family: ' +
'"object-fit:cover;object-position:top", ' +
'"Helvetica Neue", Helvetica, sans-serif' +
'"Helvetica Neue", Helvetica, sans-serif;' +
'font-weight: bold;' +
'}',
{ }
);
Expand All @@ -58,15 +60,17 @@ test('keeps the last existing font-family declaration', (t) => {
'font-family: overridden;' +
'object-fit: cover;' +
'object-position: top;' +
'font-family: "Helvetica Neue", Helvetica, sans-serif' +
'font-family: "Helvetica Neue", Helvetica, sans-serif;' +
'font-weight: bold;' +
'}',
'a{' +
'font-family: overridden;' +
'object-fit: cover;' +
'object-position: top;' +
'font-family: ' +
'"object-fit:cover;object-position:top", ' +
'"Helvetica Neue", Helvetica, sans-serif' +
'"Helvetica Neue", Helvetica, sans-serif;' +
'font-weight: bold;' +
'}',
{ }
);
Expand All @@ -79,7 +83,8 @@ test('keeps existing font declaration', (t) => {
'font-family: overridden;' +
'object-fit: cover;' +
'object-position: top;' +
'font: strong 1em/1 "Helvetica Neue", Helvetica, sans-serif' +
'font: strong 1em/1 "Helvetica Neue", Helvetica, sans-serif;' +
'font-weight: normal;' +
'}',
'a{' +
'font-family: overridden;' +
Expand All @@ -88,7 +93,8 @@ test('keeps existing font declaration', (t) => {
'font: strong 1em/1 "Helvetica Neue", Helvetica, sans-serif;' +
'font-family: ' +
'"object-fit:cover;object-position:top", ' +
'"Helvetica Neue", Helvetica, sans-serif' +
'"Helvetica Neue", Helvetica, sans-serif;' +
'font-weight: normal;' +
'}',
{ }
);
Expand Down

0 comments on commit d54476a

Please sign in to comment.