index.js
function updateReferences(images, options, sprites, css) {
	return new Promise(function (resolve) {
		css.walkComments(function (comment) {
			var rule, image, backgroundImage, backgroundPosition, backgroundSize;
			// Manipulate only token comments
			if (isToken(comment)) {
				// Match from the path with the tokens comments
				image = _.find(images, {path: comment.text});
				if (image) {
					// 2x check even dimensions.
					if (image.ratio === 2 && (image.coordinates.width % 2 !== 0 || image.coordinates.height % 2 !== 0)) {
						throw log(options.logLevel, 'lv1', ['Lazysprite:', colors.red(path.relative(process.cwd(), image.path)), '`2x` image should have' +
						' even dimensions.']);
					}

					// 3x check dimensions.
					if (image.ratio === 3 && (image.coordinates.width % 3 !== 0 || image.coordinates.height % 3 !== 0)) {
						throw log(options.logLevel, 'lv1', ['Lazysprite:', colors.red(path.relative(process.cwd(), image.path)), '`3x` image should have' +
						' correct dimensions.']);
					}

					// Generate correct ref to the sprite
					image.spriteRef = path.relative(image.stylesheetRelative, image.spritePath);
					image.spriteRef = image.spriteRef.split(path.sep).join('/');

					backgroundImage = postcss.decl({
						prop: 'background-image',
						value: getBackgroundImageUrl(image)
					});

					backgroundPosition = postcss.decl({
						prop: 'background-position',
						value: getBackgroundPosition(image)
					});

					// Replace the comment and append necessary properties.
					comment.replaceWith(backgroundImage);

					// Output the dimensions (only with 1x)
					if (options.outputDimensions && image.ratio === 1) {
						['height', 'width'].forEach(function (prop) {
							backgroundImage.after(
								postcss.decl({
									prop: prop,
									value: (image.ratio > 1 ? image.coordinates[prop] / image.ratio : image.coordinates[prop]) + 'px'
								})
							);
						});
					}

					backgroundImage.after(backgroundPosition);

					if (image.ratio > 1) {
						backgroundSize = postcss.decl({
							prop: 'background-size',
							value: getBackgroundSize(image)
						});

						backgroundPosition.after(backgroundSize);
					}
				}
			}
		});

		resolve([images, options, sprites, css]);
	});
}
function updateReferences(images, options, sprites, css) {
	return new Promise(function (resolve) {
		css.walkComments(function (comment) {
			var rule, image, backgroundImage, backgroundPosition, backgroundSize;
			// Manipulate only token comments
			if (isToken(comment)) {
				// Match from the path with the tokens comments
				image = _.find(images, {path: comment.text});
				if (image) {
					// 2x check even dimensions.
					if (image.ratio === 2 && (image.coordinates.width % 2 !== 0 || image.coordinates.height % 2 !== 0)) {
						throw log(options.logLevel, 'lv1', ['Lazysprite:', colors.red(path.relative(process.cwd(), image.path)), '`2x` image should have' +
						' even dimensions.']);
					}

					// 3x check dimensions.
					if (image.ratio === 3 && (image.coordinates.width % 3 !== 0 || image.coordinates.height % 3 !== 0)) {
						throw log(options.logLevel, 'lv1', ['Lazysprite:', colors.red(path.relative(process.cwd(), image.path)), '`3x` image should have' +
						' correct dimensions.']);
					}

					// Generate correct ref to the sprite
					image.spriteRef = path.relative(image.stylesheetRelative, image.spritePath);
					image.spriteRef = image.spriteRef.split(path.sep).join('/');

					backgroundImage = postcss.decl({
						prop: 'background-image',
						value: getBackgroundImageUrl(image)
					});

					backgroundPosition = postcss.decl({
						prop: 'background-position',
						value: getBackgroundPosition(image)
					});

					// Replace the comment and append necessary properties.
					comment.replaceWith(backgroundImage);

					// Output the dimensions (only with 1x)
					if (options.outputDimensions && image.ratio === 1) {
						['height', 'width'].forEach(function (prop) {
							backgroundImage.after(
								postcss.decl({
									prop: prop,
									value: (image.ratio > 1 ? image.coordinates[prop] / image.ratio : image.coordinates[prop]) + 'px'
								})
							);
						});
					}

					backgroundImage.after(backgroundPosition);

					if (image.ratio > 1) {
						backgroundSize = postcss.decl({
							prop: 'background-size',
							value: getBackgroundSize(image)
						});

						backgroundPosition.after(backgroundSize);
					}
				}
			}
		});

		resolve([images, options, sprites, css]);
	});
}
function updateReferences ( images , options , sprites , css ) { return new Promise ( function ( resolve ) { css . walkComments ( function ( comment ) { var rule , image , backgroundImage , backgroundPosition , backgroundSize ; // Manipulate only token comments if ( isToken ( comment ) ) { // Match from the path with the tokens comments image = _ . find ( images , { path : comment . text } ) ; if ( image ) { // 2x check even dimensions. if ( image . ratio === 2 && ( image . coordinates . width % 2 !== 0 || image . coordinates . height % 2 !== 0 ) ) { throw log ( options . logLevel , 'lv1' , [ 'Lazysprite:' , colors . red ( path . relative ( process . cwd ( ) , image . path ) ) , '`2x` image should have' + ' even dimensions.' ] ) ; } // 3x check dimensions. if ( image . ratio === 3 && ( image . coordinates . width % 3 !== 0 || image . coordinates . height % 3 !== 0 ) ) { throw log ( options . logLevel , 'lv1' , [ 'Lazysprite:' , colors . red ( path . relative ( process . cwd ( ) , image . path ) ) , '`3x` image should have' + ' correct dimensions.' ] ) ; } // Generate correct ref to the sprite image . spriteRef = path . relative ( image . stylesheetRelative , image . spritePath ) ; image . spriteRef = image . spriteRef . split ( path . sep ) . join ( '/' ) ; backgroundImage = postcss . decl ( { prop : 'background-image' , value : getBackgroundImageUrl ( image ) } ) ; backgroundPosition = postcss . decl ( { prop : 'background-position' , value : getBackgroundPosition ( image ) } ) ; // Replace the comment and append necessary properties. comment . replaceWith ( backgroundImage ) ; // Output the dimensions (only with 1x) if ( options . outputDimensions && image . ratio === 1 ) { [ 'height' , 'width' ] . forEach ( function ( prop ) { backgroundImage . after ( postcss . decl ( { prop : prop , value : ( image . ratio > 1 ? image . coordinates [ prop ] / image . ratio : image . coordinates [ prop ] ) + 'px' } ) ) ; } ) ; } backgroundImage . after ( backgroundPosition ) ; if ( image . ratio > 1 ) { backgroundSize = postcss . decl ( { prop : 'background-size' , value : getBackgroundSize ( image ) } ) ; backgroundPosition . after ( backgroundSize ) ; } } } } ) ; resolve ( [ images , options , sprites , css ] ) ; } ) ; }
Updates the CSS references from the token info.
@param  {Node}   css
@param  {Object} options
@param  {Array}  images
@param  {Array}  sprites
@return {Promise}
Updates the CSS references from the token info .