Skip to content

Commit

Permalink
Added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
frankmarineau committed Aug 11, 2014
1 parent 51af63d commit 01e99ad
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@ module.exports = function(cssString) {
var cssObject = css.parse(cssString);
var longPropertiesPositions = [];

// Loop through every rule of the stylesheet
cssObject.stylesheet.rules.forEach(function(rule) {
if (rule.type === "rule") {
if (rule.type === "rule") { // Exclude comments and other things that aren't rules
var declarations = [];

// Create an array of the rule's declarations indexed by their property name
rule.declarations.forEach(function(declaration) {
declarations[declaration.property] = declaration;
});

// Loop through all of the shorthandable properties to find if the current one can be shortened
shorthands.forEach(function(shorthand) {
var shorthandValue = shorthand.getShorthandValue(shorthand, declarations);
var shorthandValue = shorthand.getShorthandValue(shorthand, declarations); // Defined in properties.js

if (shorthandValue !== "") {
if (shorthandValue !== "") { // If there are no the specific properties of the shorthand, "getShorthandValue" returns an empty string
var newDeclarations = [];

// Add the new shorthand property
// Add the new shorthanded property
newDeclarations.push({
type: 'declaration',
property: shorthand.shorthandProperty,
Expand All @@ -36,6 +39,7 @@ module.exports = function(cssString) {
}
});

// Replace the rule's old declarations with the new shorthanded ones
rule.declarations = newDeclarations;
}
});
Expand Down

0 comments on commit 01e99ad

Please sign in to comment.