Ejemplo n.º 1
0
function dataTransform( key, value, imagePath, imageResultPath ) {
	var obj, ori, latest, fail, img;
	if ( key === 'screenshot' ) {

		img = changeSlashes( value );
		ori = path.join( imageResultPath, img );

		if ( isFile( ori ) ) {

			latest = getImageResultDiffFromSrc( ori );
			fail = getImageResultFailureFromSrc( ori );

			obj = {
				original: datauri( ori ),
				src: img
			};

			if ( isFile( fail ) ) {
				obj.failure = datauri( fail );
				if ( isFile( latest ) ) {
					obj.latest = datauri( latest );
				}
			}

			return obj;
		} else {
			if ( optionDebug > 0 ) {
				log( ( "Expected file does not exist! " + value ).grey );
			}
			return null;
		}
	}

	return value;
}
function dataTransform(key, value, imagePath, imageResultPath){
	var obj, ori, latest, fail;
	if(key === 'screenshot'){

		ori = path.join(imageResultPath, changeSlashes(value));

		if(isFile(ori)){

			latest = ori.replace(/.png$/, '.diff.png');
			fail = ori.replace(/.png$/, '.fail.png');

			obj = {
				original: datauri(ori)
			};

			if(isFile(fail)){
				obj.failure = datauri(fail);
				if(isFile(latest)){
					obj.latest = datauri(latest);
				}
			}

			return obj;
		} else {
			if(optionDebug > 0){
				console.log(("Expected file does not exist! "+ value).grey);
			}
			return null;
		}
	}

	return value;
}
Ejemplo n.º 3
0
		fileContent = fileContent.replace(/url\(["']*([^)'"]+)["']*\)/g, function(matchedWord, imgUrl){
			var newUrl = imgUrl;
			var flag = imgUrl.indexOf(options.tag)!=-1;	// urls like "img/bg.png?__inline" will be transformed to base64
			//var flag = !!imgUrl.match(/\?__inline/);	// urls like "img/bg.png?__inline" will be transformed to base64
			grunt.log.debug('cssInlineToHtml(): flag:'+flag +'\n');
			if(isBase64Path(imgUrl) || isRemotePath(imgUrl)){
				return matchedWord;
			}
			grunt.log.debug( 'cssInlineToHtml(): imgUrl: '+imgUrl +'\n');
			grunt.log.debug( 'cssInlineToHtml(): filepath: '+filepath +'\n');
			var absoluteImgurl = path.resolve( path.dirname(filepath),imgUrl );	// img url relative to project root
			grunt.log.debug( 'cssInlineToHtml(): absoluteImgurl: '+absoluteImgurl +'\n');
			newUrl = path.relative( path.dirname(htmlFilepath), absoluteImgurl );	// img url relative to the html file
			grunt.log.debug([htmlFilepath, filepath, absoluteImgurl, imgUrl]);
			grunt.log.debug( 'cssInlineToHtml(): newUrl: '+newUrl +'\n');

			absoluteImgurl = absoluteImgurl.replace(/\?.*$/, '');
			if(flag && grunt.file.exists(absoluteImgurl)){
				grunt.log.debug( 'cssInlineToHtml(): flag&&grunt.file.exists(absoluteImgurl) newUrl: '+newUrl + '\n');
				newUrl = datauri(absoluteImgurl);
			}else{
				grunt.log.debug( 'cssInlineToHtml(): ! flag&&grunt.file.exists(absoluteImgurl) newUrl: '+newUrl + '\n');
				newUrl = newUrl.replace(/\\/g, '/');
			}

			return matchedWord.replace(imgUrl, newUrl);
		});
Ejemplo n.º 4
0
		fileContent = fileContent.replace(/url\(["']*([^)'"]+)["']*\)/g, function(matchedWord, imgUrl){
			var newUrl = imgUrl;
			var flag = imgUrl.indexOf(options.tag)!=-1;	// urls like "img/bg.png?__inline" will be transformed to base64
			if(isBase64Path(imgUrl)) {
				grunt.log.debug('css(): not escaping: isBase64Path:' + imgUrl + '\n');
				return matchedWord;
			}
			if (isRemotePath(imgUrl)){
				grunt.log.debug('css(): not escaping: isRemotePath:' + imgUrl + '\n');
				return matchedWord;
			}
			grunt.log.debug( 'css(): imgUrl: '+imgUrl +'\n');
			grunt.log.debug( 'css(): filepath: '+filepath +'\n');
			var absoluteImgurl = path.resolve( path.dirname(filepath),imgUrl );
			grunt.log.debug( 'css(): absoluteImgurl: '+absoluteImgurl +'\n');
			newUrl = path.relative( path.dirname(filepath), absoluteImgurl );
			grunt.log.debug( 'css(): newUrl: '+newUrl +'\n');

			absoluteImgurl = absoluteImgurl.replace(/\?.*$/, '');
			if(flag && grunt.file.exists(absoluteImgurl)){
				newUrl = datauri(absoluteImgurl);
				grunt.log.debug( 'css(): flag&&grunt.file.exists(absoluteImgurl) newUrl: '+newUrl + '\n');
			}else{
				newUrl = newUrl.replace(/\\/g, '/');
				grunt.log.debug( 'css(): ! flag&&grunt.file.exists(absoluteImgurl) newUrl: '+newUrl + '\n');
			}

			grunt.log.debug( 'css(): newUrl: '+newUrl + '\n');
			return matchedWord.replace(imgUrl, newUrl);
		});
      uris.forEach(function(uri) {
        var src, replacement, needle, fixedUri;
         // fixed current dir when specified uri is like root
        fixedUri = uri.indexOf('/') === 0 ? '.' + uri : uri;

        // Resolve image realpath
        needle = path.resolve(fixedUri);
         // Assume file existing cause found from haystack
		 if (haystack.indexOf(needle) !== -1) {

          // check if file exceeds the max bytes
          var fileSize = getFileSize(needle);
          if (options.maxBytes && fileSize > options.maxBytes) {
            // file is over the max size
            grunt.log.ok('Skipping (size ' + fileSize + ' > ' + options.maxBytes +'): ' + uri);
            return;
          } else {
            // Encoding to Data uri
            replacement = datauri(needle);

            grunt.log.ok('Encode: '+needle);
          }
        } else {
          if (options.fixDirLevel) {
            // Diff of directory level
            replacement = adjustDirectoryLevel(fixedUri, destDir, baseDir);
            grunt.log.ok('Adjust: '+ uri + ' -> ' + replacement);
          } else {
            replacement = uri;
            grunt.log.ok('Ignore: '+ uri);
          }
        }

        content = content.replace(new RegExp(uri, 'g'), replacement);
      });
Ejemplo n.º 6
0
 Util.qrDecode = function(pathToImage, cb) {
     qrcode.decode(Datauri(path.resolve(pathToImage)), function(err, result) {
         if(err)
             console.error(err);
         cb(err, result);
     });
 };
Ejemplo n.º 7
0
 function () {
     var stream = this;
     DataURI(fileName, function (err, content) {
         if (err) {
             throw err;
         }
         stream.queue('module.exports = \n"' + content + '";\n');
         stream.queue(null);
     });
 }
Ejemplo n.º 8
0
 items = items.concat(media.map(function (media) {
     return {
       id: media.id,
       views: media.views,
       downloads: media.downloads,
       type: 'media',
       subtype: typeToExtension[media.type],
       title: media.name,
       preview: datauri('public/preview/' + media.id + '.png')
     };
   })
Ejemplo n.º 9
0
            urlResults.forEach(function(url){
                console.info('url', url);

                var p = path.join(path.dirname(filePath), url);

                if (!fs.existsSync(p) || !fs.statSync(p).isFile()) {
                    console.warn('! Файл не найден:', p);
                    return;
                }

                if (options.urlToBase64) {
                    // Заменить url(path/to/resource) на url(data:base64)
                    var dataUri = DataUri(p);
                    str = str.replace(urlRegexp, util.format(CSS_URL_DATA_BASE_64_FORMAT, dataUri));
                } else {
                    // Заменить url(path/to/resource) на url("path/to/resource?hashResource")
                    var hash = helper.getFileHash(p);
                    str = str.replace(urlRegexp, util.format(CSS_URL_HASH_FORMAT, url, hash));
                }
            });
Ejemplo n.º 10
0
		fileContent = fileContent.replace(/url\(["']*([^)'"]+)["']*\)/g, function(matchedWord, imgUrl){
			var newUrl = imgUrl;
			var flag = !!imgUrl.match(/\?__inline/);	// urls like "img/bg.png?__inline" will be transformed to base64
			if(isBase64Path(imgUrl) || isRemotePath(imgUrl)){
				return matchedWord;
			}
			grunt.log.debug( 'imgUrl: '+imgUrl);
			grunt.log.debug( 'filepath: '+filepath);
			var absoluteImgurl = path.resolve( path.dirname(filepath),imgUrl );
			grunt.log.debug( 'absoluteImgurl: '+absoluteImgurl);
			newUrl = path.relative( path.dirname(filepath), absoluteImgurl );
			grunt.log.debug( 'newUrl: '+newUrl);

			absoluteImgurl = absoluteImgurl.replace(/\?.*$/, '');
			if(flag && grunt.file.exists(absoluteImgurl)){
				newUrl = datauri(absoluteImgurl);
			}else{
				newUrl = newUrl.replace(/\\/g, '/');
			}

			return matchedWord.replace(imgUrl, newUrl);
		});
Ejemplo n.º 11
0
      uris.forEach(function(u) {
        var src, replacement,
            needle = path.resolve(u).slice((baseGrunt+'/').length);

        // Assume file existing cause found from haystack
        if (haystack.indexOf(needle) !== -1) {
          // Encoding to Data uri
          replacement = datauri(u);

          grunt.log.ok('Encode: '+u);
        } else {
          if (options.fixDirLevel) {
            // Diff of directory level
            replacement =  adjustDirectoryLevel(u, destDir, baseSrc);
            grunt.log.ok('Adjust: '+ u + ' -> ' + replacement);
          } else {
            replacement = u;
            grunt.log.ok('Ignore: '+ u);
          }
        }

        content = content.replace(new RegExp(u, 'g'), replacement);
      });