Skip to content

Commit

Permalink
Merge pull request #17 from TrySound/fix-space
Browse files Browse the repository at this point in the history
Fix space
  • Loading branch information
Sean King committed Feb 22, 2016
2 parents 7279230 + f0b9c33 commit 56751f4
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 74 deletions.
144 changes: 72 additions & 72 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,91 +3,91 @@
var postcss = require('postcss'),
displays = ['block', 'table'];

module.exports = postcss.plugin('postcss-clearfix', function (opts) {
opts = opts || {};

if (displays.indexOf(opts.display) === -1) {
opts.display = displays[0];
/**
* Clear: fix; rule handler
* @param {string} decl current decleration
*/
function clearFix(decl, opts) {

var origRule = decl.parent,
ruleSelectors = origRule.selectors,
newRule;

ruleSelectors = ruleSelectors.map(function(ruleSelector){
return ruleSelector + ':after';
}).join(',\n');

// Insert the :after rule before the original rule
newRule = origRule.cloneBefore({
selector: ruleSelectors
}).removeAll();

newRule.append('content: \'\'; display: ' + opts.display + '; clear: both;');

// If the original rule only had clear:fix in it, remove the whole rule
if (decl.prev() === undefined && decl.next() === undefined) {
origRule.remove();
} else {
// Otherwise just remove the delcl
decl.remove();
}

return function (css) {
}

/**
* Clear: fix; rule handler
* @param {string} decl current decleration
*/
function clearFix(decl){
/**
* Clear: fix-legacy; rule handler
* @param {string} decl current decleration
*/
function clearFixLegacy(decl) {

var origRule = decl.parent,
ruleSelectors = origRule.selectors,
newRule;
var origRule = decl.parent,
ruleSelectors = origRule.selectors,
bothRuleSelectors,
afterRuleSelectors,
bothRule,
afterRule;

ruleSelectors = ruleSelectors.map(function(ruleSelector){
return ruleSelector + ':after';
}).join(',\n');

// Insert the :after rule before the original rule
newRule = origRule.cloneBefore({
selector: ruleSelectors
}).removeAll();
bothRuleSelectors = ruleSelectors.map(function(ruleSelector){
return ruleSelector + ':before,\n' + ruleSelector + ':after';
}).join(',\n');

newRule.append('content: \'\'; display: ' + opts.display + '; clear: both;');

// If the original rule only had clear:fix in it, remove the whole rule
if (decl.prev() === undefined && decl.next() === undefined) {
origRule.remove();
} else {
// Otherwise just remove the delcl
decl.remove();
}

};

/**
* Clear: fix-legacy; rule handler
* @param {string} decl current decleration
*/
function clearFixLegacy(decl) {
afterRuleSelectors = ruleSelectors.map(function(ruleSelector){
return ruleSelector + ':after';
}).join(',\n');

var origRule = decl.parent,
ruleSelectors = origRule.selectors,
bothRuleSelectors,
afterRuleSelectors,
bothRule,
afterRule;
// Insert new rules before the original rule
bothRule = origRule.cloneBefore({
selector: bothRuleSelectors
}).removeAll();

bothRuleSelectors = ruleSelectors.map(function(ruleSelector){
return ruleSelector + ':before,\n' + ruleSelector + ':after';
}).join(',\n');
afterRule = origRule.cloneBefore({
selector: afterRuleSelectors
}).removeAll();

afterRuleSelectors = ruleSelectors.map(function(ruleSelector){
return ruleSelector + ':after';
}).join(',\n');
bothRule.append('content: \' \'; display: table;');

// Insert new rules before the original rule
bothRule = origRule.cloneBefore({
selector: bothRuleSelectors
}).removeAll();
// Longhand syntax operates a little quicker, only single decls here so use it.
afterRule.append({
prop: 'clear',
value: 'both'
});

afterRule = origRule.cloneBefore({
selector: afterRuleSelectors
}).removeAll();
origRule.append({
prop: 'zoom',
value: '1'
});

bothRule.append('content: \'\'; display: table;');
decl.remove();
}

// Longhand syntax operates a little quicker, only single decls here so use it.
afterRule.append({
prop: 'clear',
value: 'both'
});
module.exports = postcss.plugin('postcss-clearfix', function(opts) {
opts = opts || {};

origRule.append({
prop: 'zoom',
value: '1'
});
if (displays.indexOf(opts.display) === -1) {
opts.display = displays[0];
}

decl.remove();
};
return function(css) {

// Run handlers through all relevant CSS decls
css.walkDecls('clear', function(decl) {
Expand All @@ -96,12 +96,12 @@ module.exports = postcss.plugin('postcss-clearfix', function (opts) {

// Pass all clear: fix; properties to clearFix()
case 'fix':
clearFix(decl);
clearFix(decl, opts);
break;

// Pass all clear: fix-legacy properties to clearFixLegacy()
case 'fix-legacy':
clearFixLegacy(decl);
clearFixLegacy(decl, opts);
break;

}
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/fix-legacy.expected.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.foo:before,
.foo:after {
content: '';
content: ' ';
display: table;
}
.foo:after {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/multiple.expected.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
.baz:after,
.fab:before,
.fab:after {
content: '';
content: ' ';
display: table;
}

Expand Down

0 comments on commit 56751f4

Please sign in to comment.