From aeade95694bc2cbddc5e4d64190cca92a91f55d6 Mon Sep 17 00:00:00 2001 From: DveMac Date: Tue, 11 Nov 2014 10:52:17 +0000 Subject: [PATCH 01/13] Added support for script data attrs --- tasks/inline.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/tasks/inline.js b/tasks/inline.js index 5e08f6d..d4ad49d 100644 --- a/tasks/inline.js +++ b/tasks/inline.js @@ -55,6 +55,20 @@ module.exports = function(grunt) { return url.match(/^'?data.*base64/); } + function getDataAttribs(attrs) { + var matches, + reg = /(data-[\a-z-]+="[\w-]+")/gm, + dataAttribs = []; + + matches = attrs.match(reg); + + if (matches && matches.length) { + dataAttribs.push.apply(dataAttribs, matches); + } + + return matches; + } + // from grunt-text-replace.js in grunt-text-replace function getPathToDestination(pathToSource, pathToDestinationFile) { var isDestinationDirectory = (/\/$/).test(pathToDestinationFile); @@ -101,15 +115,15 @@ module.exports = function(grunt) { } return ret; - }).replace(/\s*<\/script>/g, function(matchedWord, src){ - var ret = matchedWord; + }).replace(/\s*<\/script>/g, function(matchedWord, src, attrs){ + var ret = matchedWord, dataAttribs = getDataAttribs(attrs); if(!isRemotePath(src) && src.indexOf(options.tag)!=-1){ var inlineFilePath = path.resolve( path.dirname(filepath), src ).replace(/\?.*$/, ''); // 将参数去掉 var c = options.uglify ? UglifyJS.minify(inlineFilePath).code : grunt.file.read( inlineFilePath ); if( grunt.file.exists(inlineFilePath) ){ var inlineTagAttributes = options.inlineTagAttributes.js; - ret = ''; + ret = ''; }else{ grunt.log.error("Couldn't find " + inlineFilePath + '!'); } From d843213bb9ce6279b0c3bd8a1142284b2e5d0350 Mon Sep 17 00:00:00 2001 From: DveMac Date: Tue, 11 Nov 2014 10:52:50 +0000 Subject: [PATCH 02/13] Bumped --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 633240a..3ca866b 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ }, "name": "grunt-inline", "description": "Inlines img, script and link tags into the same file.", - "version": "0.3.2", + "version": "0.3.3", "keywords": [ "gruntplugin", "inline", From 08688ae3ea56fbb564833c8dff54323bc9f63bbc Mon Sep 17 00:00:00 2001 From: DveMac Date: Tue, 11 Nov 2014 10:55:30 +0000 Subject: [PATCH 03/13] Refactored data attr method --- tasks/inline.js | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/tasks/inline.js b/tasks/inline.js index d4ad49d..7bb61b4 100644 --- a/tasks/inline.js +++ b/tasks/inline.js @@ -56,17 +56,8 @@ module.exports = function(grunt) { } function getDataAttribs(attrs) { - var matches, - reg = /(data-[\a-z-]+="[\w-]+")/gm, - dataAttribs = []; - - matches = attrs.match(reg); - - if (matches && matches.length) { - dataAttribs.push.apply(dataAttribs, matches); - } - - return matches; + var reg = /(data-[\a-z-]+="[\w-]+")/gm; + return attrs.match(reg) || []; } // from grunt-text-replace.js in grunt-text-replace From e64711545b5a62edb103a8547fb5c20a0b025679 Mon Sep 17 00:00:00 2001 From: DveMac Date: Tue, 18 Nov 2014 11:15:32 +0000 Subject: [PATCH 04/13] Added support for domain relative paths --- package.json | 80 +++++++++++++++++------------------ tasks/inline.js | 6 +-- test/dist/css.html | 1 + test/dist/script.html | 1 + test/expected/css.min.html | 5 +++ test/expected/script.min.html | 2 +- 6 files changed, 51 insertions(+), 44 deletions(-) diff --git a/package.json b/package.json index 3ca866b..b74a83a 100644 --- a/package.json +++ b/package.json @@ -1,40 +1,40 @@ -{ - "author": { - "name": "程序猿小卡", - "email": "chyingp@gmail.com", - "url": "https://github.com/chyingp" - }, - "name": "grunt-inline", - "description": "Inlines img, script and link tags into the same file.", - "version": "0.3.3", - "keywords": [ - "gruntplugin", - "inline", - "js", - "css" - ], - "main": "inline", - "repository": { - "type": "git", - "url": "https://github.com/chyingp/grunt-inline.git" - }, - "engines": { - "node": ">=0.8.0" - }, - "devDependencies": { - "grunt-contrib-nodeunit": "~0.1.2", - "grunt-contrib-clean": "~0.4.0", - "grunt-contrib-htmlmin": "~0.1.3", - "grunt": "~0.4.0" - }, - "dependencies": { - "uglify-js": "2.4.1", - "datauri": "~0.2.0", - "clean-css": "1.1.7" - }, - "scripts": { - "test": "grunt test" - }, - "_id": "grunt-inline@0.1.0", - "_from": "grunt-inline@~0.1.0" -} +{ + "author": { + "name": "程序猿小卡", + "email": "chyingp@gmail.com", + "url": "https://github.com/chyingp" + }, + "name": "grunt-inline", + "description": "Inlines img, script and link tags into the same file.", + "version": "0.3.3", + "keywords": [ + "gruntplugin", + "inline", + "js", + "css" + ], + "main": "inline", + "repository": { + "type": "git", + "url": "https://github.com/chyingp/grunt-inline.git" + }, + "engines": { + "node": ">=0.8.0" + }, + "devDependencies": { + "grunt": "~0.4.0", + "grunt-contrib-clean": "~0.4.0", + "grunt-contrib-htmlmin": "~0.1.3", + "grunt-contrib-nodeunit": "~0.1.2" + }, + "dependencies": { + "uglify-js": "2.4.1", + "datauri": "~0.2.0", + "clean-css": "1.1.7" + }, + "scripts": { + "test": "grunt test" + }, + "_id": "grunt-inline@0.1.0", + "_from": "grunt-inline@~0.1.0" +} diff --git a/tasks/inline.js b/tasks/inline.js index 7bb61b4..bb6cabc 100644 --- a/tasks/inline.js +++ b/tasks/inline.js @@ -106,7 +106,7 @@ module.exports = function(grunt) { } return ret; - }).replace(/\s*<\/script>/g, function(matchedWord, src, attrs){ + }).replace(/\s*<\/script>/g, function(matchedWord, src, attrs){ var ret = matchedWord, dataAttribs = getDataAttribs(attrs); if(!isRemotePath(src) && src.indexOf(options.tag)!=-1){ @@ -123,7 +123,7 @@ module.exports = function(grunt) { return ret; - }).replace(//g, function(matchedWord, src){ + }).replace(//g, function(matchedWord, src){ var ret = matchedWord; if(!isRemotePath(src) && src.indexOf(options.tag)!=-1){ @@ -141,7 +141,7 @@ module.exports = function(grunt) { grunt.log.debug('ret = : ' + ret +'\n'); return ret; - }).replace(//g, function(matchedWord, src){ + }).replace(//g, function(matchedWord, src){ var ret = matchedWord; if(!grunt.file.isPathAbsolute(src) && src.indexOf(options.tag)!=-1){ diff --git a/test/dist/css.html b/test/dist/css.html index 6a100a3..ffede39 100644 --- a/test/dist/css.html +++ b/test/dist/css.html @@ -7,6 +7,7 @@ + diff --git a/test/dist/script.html b/test/dist/script.html index 6f58362..1b52658 100644 --- a/test/dist/script.html +++ b/test/dist/script.html @@ -3,6 +3,7 @@ test + diff --git a/test/expected/css.min.html b/test/expected/css.min.html index 8d3b73c..9f6d27b 100644 --- a/test/expected/css.min.html +++ b/test/expected/css.min.html @@ -8,4 +8,9 @@ body{background: url('http://www.example.com/img/bg.png');} body{background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABsAAAAwCAYAAADgvwGgAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAABUlJREFUeNq8WFtsVEUY/ufsWbbtsl1aWtqCBKlJtVakTSEGa4IvJqiJPmg0PmjwRZONBGJDAzHYmD54i40PatCoMeEBL28N6oORROSlloqWW420hRbtZVvYXpa17Z4zfjNndnt2zzl7iJad5Ns5Z87MfPNf5p9/ljHGAkRkkFthjIhz1NkGq5Jt6putmKZJhYpOnmScVrtomDRoTWwDX30iSzIOFKlAMgoUk0wrJhmXTsbYbSeDvVgKNKVwiRq8rwfKlGpTwDgwumps2Gc9TGNDqJOouQTL1nNAL573ARGmaSQBLWRrGzi8uBCYmFiqsZC3Wxo+D7yCl1MYuREja+QMRBNKA76bmihvk2Ulc4eQvh91Qklvor4hpWdsn69k2++u56HQGhqfmqGxiXhGtXSL0lp9rOdB0zAbCzpI37Fu0vUAJZI36WTfAHV+eIwuDI1iPMudmOeROCPbSV/XDzCTzPQyVZSV0FOPPUynvniX9rS1KnN4hEnuIiWjHl9n5MO9wk3IXEiQmZwjPVxG8ekb1PrcAanWrEodJDl6HgB2YIHLBSWbnFyiifFFStdtJ72+hdKpRareuIGeeaTNW4VSEm7nfdtGtBZ4Hngf+BjYD2yVNjvTdUT2Dt+xmX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tvlyzw95XseSnPsyG/adeuz2njQzPL9O7U8l6vFjjHSKR2Ul7cdps51sYoQEBQCCVkgQEBAQd2FyUuJyEduIbwHZezX32nmPt9Fz6nBXPjmk/2WzFknHfihrGMyNXJ1W2Kkgew8x1ae4joV5bLhvitw3hdUyVvG9XDtDs7VzbA5xMVho0ZM0eRHULfpdZfTzy5x6NebT1yxz6qJf2SzFNx3a3tEf8AnCdfLmrvF4jp7xznafirr6XLXtu8x2NvtOjqVkHuMLv4XTGfFPS0fq0+zv6OirgctacBDQn49Xt3B9Std9Xgp1tDKuDJbpC4bP7LQ4c/1DKzRumiGreOjIvHU8yqjVa+2f7rFHKf1l34dNXH57vG2u2nGT1pUXEUwe2/l60jl8l2aDQzi+8ye9+zRqdT7Ty16fuqytHGhAQFAICCVkgQEBQCAg6KV2zQmE1Od8Mg6tPPwI6rXkxUyRw3jdnS9qTvWdloo7e3ImhtypHPpzex24T8uIVbk8Jxzzpbb6uumutHK0bvTj2/x7m/3Kdpp8N0/uuafCcva0fX+G77dT0lL9v8e0dipbcfENH7qI8Iy/7R9f4Pt1PSXnWtv7DmkVKLI+50ry7yGi6KeEVj37btd9dPaFZyWXv5N2t2y6QDkzk0fIKxw6fFh9yNnJfLfJ70uFb2sQEBQCAgIJUoEBAQEBAQEBEiAghAQEBQCAgICCVKBAQEBAQESICAghAQEBQCAgICAglSgQEBARIgICCEBAQFAICAgICAgIP/2Q==') \ No newline at end of file diff --git a/test/expected/script.min.html b/test/expected/script.min.html index 90da342..9a49bd9 100644 --- a/test/expected/script.min.html +++ b/test/expected/script.min.html @@ -1 +1 @@ -test \ No newline at end of file +test \ No newline at end of file From 5614c62647b44884a4973a12ab2b9749efca34ed Mon Sep 17 00:00:00 2001 From: DveMac Date: Tue, 18 Nov 2014 11:15:59 +0000 Subject: [PATCH 05/13] Bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b74a83a..3d7333d 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ }, "name": "grunt-inline", "description": "Inlines img, script and link tags into the same file.", - "version": "0.3.3", + "version": "0.3.4", "keywords": [ "gruntplugin", "inline", From d1fb1ff2c8553c0ef803f0d03dae4615790808f6 Mon Sep 17 00:00:00 2001 From: DveMac Date: Tue, 18 Nov 2014 11:35:04 +0000 Subject: [PATCH 06/13] Revert package.json to tab spacing --- package.json | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 3d7333d..d195e2b 100644 --- a/package.json +++ b/package.json @@ -1,39 +1,39 @@ { "author": { - "name": "程序猿小卡", - "email": "chyingp@gmail.com", - "url": "https://github.com/chyingp" + "name": "程序猿小卡", + "email": "chyingp@gmail.com", + "url": "https://github.com/chyingp" }, "name": "grunt-inline", "description": "Inlines img, script and link tags into the same file.", "version": "0.3.4", "keywords": [ - "gruntplugin", - "inline", - "js", - "css" + "gruntplugin", + "inline", + "js", + "css" ], "main": "inline", "repository": { - "type": "git", - "url": "https://github.com/chyingp/grunt-inline.git" + "type": "git", + "url": "https://github.com/chyingp/grunt-inline.git" }, "engines": { - "node": ">=0.8.0" + "node": ">=0.8.0" }, "devDependencies": { - "grunt": "~0.4.0", - "grunt-contrib-clean": "~0.4.0", - "grunt-contrib-htmlmin": "~0.1.3", - "grunt-contrib-nodeunit": "~0.1.2" + "grunt": "~0.4.0", + "grunt-contrib-clean": "~0.4.0", + "grunt-contrib-htmlmin": "~0.1.3", + "grunt-contrib-nodeunit": "~0.1.2" }, "dependencies": { - "uglify-js": "2.4.1", - "datauri": "~0.2.0", - "clean-css": "1.1.7" + "uglify-js": "2.4.1", + "datauri": "~0.2.0", + "clean-css": "1.1.7" }, "scripts": { - "test": "grunt test" + "test": "grunt test" }, "_id": "grunt-inline@0.1.0", "_from": "grunt-inline@~0.1.0" From a8273f205d1c2053ccd9def51bbaec5695a4742e Mon Sep 17 00:00:00 2001 From: DveMac Date: Tue, 18 Nov 2014 11:36:03 +0000 Subject: [PATCH 07/13] Revert package.json to space spacing --- package.json | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index d195e2b..3d7333d 100644 --- a/package.json +++ b/package.json @@ -1,39 +1,39 @@ { "author": { - "name": "程序猿小卡", - "email": "chyingp@gmail.com", - "url": "https://github.com/chyingp" + "name": "程序猿小卡", + "email": "chyingp@gmail.com", + "url": "https://github.com/chyingp" }, "name": "grunt-inline", "description": "Inlines img, script and link tags into the same file.", "version": "0.3.4", "keywords": [ - "gruntplugin", - "inline", - "js", - "css" + "gruntplugin", + "inline", + "js", + "css" ], "main": "inline", "repository": { - "type": "git", - "url": "https://github.com/chyingp/grunt-inline.git" + "type": "git", + "url": "https://github.com/chyingp/grunt-inline.git" }, "engines": { - "node": ">=0.8.0" + "node": ">=0.8.0" }, "devDependencies": { - "grunt": "~0.4.0", - "grunt-contrib-clean": "~0.4.0", - "grunt-contrib-htmlmin": "~0.1.3", - "grunt-contrib-nodeunit": "~0.1.2" + "grunt": "~0.4.0", + "grunt-contrib-clean": "~0.4.0", + "grunt-contrib-htmlmin": "~0.1.3", + "grunt-contrib-nodeunit": "~0.1.2" }, "dependencies": { - "uglify-js": "2.4.1", - "datauri": "~0.2.0", - "clean-css": "1.1.7" + "uglify-js": "2.4.1", + "datauri": "~0.2.0", + "clean-css": "1.1.7" }, "scripts": { - "test": "grunt test" + "test": "grunt test" }, "_id": "grunt-inline@0.1.0", "_from": "grunt-inline@~0.1.0" From 8f4f8e53c9acf6611f892af79a0f95462dc17e57 Mon Sep 17 00:00:00 2001 From: Ludolph Neethling Date: Mon, 23 Mar 2015 20:35:38 +0200 Subject: [PATCH 08/13] .htm is a valid extension... ... in a invalid world. --- tasks/inline.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/inline.js b/tasks/inline.js index 556077d..1d22a49 100644 --- a/tasks/inline.js +++ b/tasks/inline.js @@ -36,7 +36,7 @@ module.exports = function(grunt) { grunt.log.write('Processing ' + filepath + '...') - if(fileType==='html' || (exts && exts.indexOf(fileType) > -1)){ + if(fileType==='html' || fileType==='htm' || (exts && exts.indexOf(fileType) > -1)){ fileContent = html(filepath, fileContent, relativeTo, options); }else if(fileType==='css'){ fileContent = css(filepath, fileContent, relativeTo, options); From d7dcb7ab55fc4c874f8f143d62fc84a7a6e1b981 Mon Sep 17 00:00:00 2001 From: Marcus Klaas Date: Thu, 9 Apr 2015 17:54:44 +0200 Subject: [PATCH 09/13] fix tests --- Gruntfile.js | 6 +-- npm-debug.log | 110 ------------------------------------------------ tasks/inline.js | 14 ++++-- 3 files changed, 13 insertions(+), 117 deletions(-) delete mode 100644 npm-debug.log diff --git a/Gruntfile.js b/Gruntfile.js index 59e6e32..c255ecf 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -4,13 +4,13 @@ module.exports = function(grunt) { grunt.initConfig({ inline: { dist: { - src: ['test/dist/*.html'], - dest: ['tmp/'] + src: 'test/dist/*.html', + dest: 'tmp/' } }, clean: { - tests: ['tmp/'] + tests: 'tmp/' }, htmlmin: { diff --git a/npm-debug.log b/npm-debug.log deleted file mode 100644 index eeac3e8..0000000 --- a/npm-debug.log +++ /dev/null @@ -1,110 +0,0 @@ -0 info it worked if it ends with ok -1 verbose cli [ 'node', '/usr/local/bin/npm', 'publish' ] -2 info using npm@1.4.14 -3 info using node@v0.10.29 -4 verbose publish [ '.' ] -5 verbose cache add [ '.', null ] -6 verbose cache add name=undefined spec="." args=[".",null] -7 verbose parsed url { protocol: null, -7 verbose parsed url slashes: null, -7 verbose parsed url auth: null, -7 verbose parsed url host: null, -7 verbose parsed url port: null, -7 verbose parsed url hostname: null, -7 verbose parsed url hash: null, -7 verbose parsed url search: null, -7 verbose parsed url query: null, -7 verbose parsed url pathname: '.', -7 verbose parsed url path: '.', -7 verbose parsed url href: '.' } -8 silly lockFile 3a52ce78- . -9 verbose lock . /Users/a/.npm/3a52ce78-.lock -10 verbose tar pack [ '/Users/a/.npm/grunt-inline/0.3.3/package.tgz', '.' ] -11 verbose tarball /Users/a/.npm/grunt-inline/0.3.3/package.tgz -12 verbose folder . -13 info prepublish grunt-inline@0.3.3 -14 silly lockFile 1f1177db-tar tar://. -15 verbose lock tar://. /Users/a/.npm/1f1177db-tar.lock -16 silly lockFile 9f87bd96-m-grunt-inline-0-3-3-package-tgz tar:///Users/a/.npm/grunt-inline/0.3.3/package.tgz -17 verbose lock tar:///Users/a/.npm/grunt-inline/0.3.3/package.tgz /Users/a/.npm/9f87bd96-m-grunt-inline-0-3-3-package-tgz.lock -18 silly lockFile 1f1177db-tar tar://. -19 silly lockFile 1f1177db-tar tar://. -20 silly lockFile 9f87bd96-m-grunt-inline-0-3-3-package-tgz tar:///Users/a/.npm/grunt-inline/0.3.3/package.tgz -21 silly lockFile 9f87bd96-m-grunt-inline-0-3-3-package-tgz tar:///Users/a/.npm/grunt-inline/0.3.3/package.tgz -22 silly lockFile f04d4788-a-npm-grunt-inline-0-3-3-package /Users/a/.npm/grunt-inline/0.3.3/package -23 verbose lock /Users/a/.npm/grunt-inline/0.3.3/package /Users/a/.npm/f04d4788-a-npm-grunt-inline-0-3-3-package.lock -24 silly lockFile f04d4788-a-npm-grunt-inline-0-3-3-package /Users/a/.npm/grunt-inline/0.3.3/package -25 silly lockFile f04d4788-a-npm-grunt-inline-0-3-3-package /Users/a/.npm/grunt-inline/0.3.3/package -26 silly lockFile 3a52ce78- . -27 silly lockFile 3a52ce78- . -28 silly publish { author: -28 silly publish { name: '程序猿小卡', -28 silly publish email: 'chyingp@gmail.com', -28 silly publish url: 'https://github.com/chyingp' }, -28 silly publish name: 'grunt-inline', -28 silly publish description: 'Inlines img, script and link tags into the same file.', -28 silly publish version: '0.3.3', -28 silly publish keywords: [ 'gruntplugin', 'inline', 'js', 'css' ], -28 silly publish main: 'inline', -28 silly publish repository: -28 silly publish { type: 'git', -28 silly publish url: 'https://github.com/chyingp/grunt-inline.git' }, -28 silly publish engines: { node: '>=0.8.0' }, -28 silly publish devDependencies: -28 silly publish { 'grunt-contrib-nodeunit': '~0.1.2', -28 silly publish 'grunt-contrib-clean': '~0.4.0', -28 silly publish 'grunt-contrib-htmlmin': '~0.1.3', -28 silly publish grunt: '~0.4.0' }, -28 silly publish dependencies: { 'uglify-js': '2.4.1', datauri: '~0.2.0', 'clean-css': '1.1.7' }, -28 silly publish scripts: { test: 'grunt test' }, -28 silly publish _id: 'grunt-inline@0.3.3', -28 silly publish _from: '.', -28 silly publish readme: '# grunt-inline[![build status](https://secure.travis-ci.org/miniflycn/grunt-inline.png)](http://travis-ci.org/miniflycn/grunt-inline)\r\n\r\nBrings externally referenced resources, such as js, css and images, into\r\na single file.\r\n\r\nFor exmample:\r\n\r\n````\r\n\r\n````\r\nis replaced with\r\n````\r\n\r\n```\r\n\r\nJavascript references are brought inline, and images in the html\r\nand css blocks are converted to base-64 data: urls.\r\n\r\nBy default, only urls marked with `__inline` are converted, however this\r\nbehavior can be overrided via the `tag:` option.\r\n\r\n\r\n## Getting Started\r\nThis plugin requires Grunt `~0.4.1`\r\n\r\nIf you haven\'t used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you\'re familiar with that process, you may install this plugin with this command:\r\n\r\n\tnpm install grunt-inline --save-dev\r\n\r\nOnce the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:\r\n\r\n\tgrunt.loadNpmTasks(\'grunt-inline\');\r\n\r\n## The "grunt-inline" task\r\n\r\n### Overview\r\nIn your project\'s Gruntfile, add a section named `inline` to the data object passed into `grunt.initConfig()`.\r\n\r\n\tgrunt.initConfig({\r\n\t inline: {\r\n\t dist: {\r\n\t src: \'src/index.html\',\r\n\t dest: \'dist/index.html\'\r\n\t }\r\n\t }\r\n\t})\r\n### Options\r\n\r\n#### dest\r\nIf dest is assigned, the the source file will be copied to the destination path. eg:\r\n`src/index.html` will be processed and then copied to `dist/index.html`\r\n\r\n```\r\ngrunt.initConfig({\r\n\tinline: {\r\n\t\tdist: {\r\n\t\t\tsrc: \'src/index.html\',\r\n\t\t\tdest: \'dist/index.html\'\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n\r\n### cssmin\r\nIf cssmin is assigned true, `.css` will be minified before inlined.\r\n\r\n```\r\ngrunt.initConfig({\r\n\tinline: {\r\n\t\tdist: {\r\n\t\t\toptions:{\r\n\t\t\t\tcssmin: true\r\n\t\t\t},\r\n\t\t\tsrc: \'src/index.html\',\r\n\t\t\tdest: \'dist/index.html\'\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n\r\n### tag (defaults to ```__inline```)\r\nOnly URLs that contain the value for ```tag``` will be inlined.\r\nSpecify ```tag: \'\'``` to include all urls.\r\n\r\n```\r\ngrunt.initConfig({\r\n\tinline: {\r\n\t\tdist: {\r\n\t\t\toptions:{\r\n\t\t\t\ttag: \'\'\r\n\t\t\t},\r\n\t\t\tsrc: \'src/index.html\',\r\n\t\t\tdest: \'dist/index.html\']\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n\r\n\r\n### inlineTagAttributes\r\nAbility to add attributes string to inline tag.\r\n\r\n```\r\ngrunt.initConfig({\r\n\tinline: {\r\n\t\tdist: {\r\n\t\t\toptions:{\r\n\t\t\t\tinlineTagAttributes: {\r\n\t\t\t\t\tjs: \'data-inlined="true"\',\t// Adds ``````\r\n\t\t\t\t\tcss: \'data-inlined="true"\'\t// Adds ``````\r\n\t\t\t},\r\n\t\t\tsrc: \'src/index.html\',\r\n\t\t\tdest: \'dist/index.html\'\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n\r\n\r\n### uglify\r\nIf uglify is assigned true, `.js` file will be minified before inlined.\r\n\r\n```\r\ngrunt.initConfig({\r\n\tinline: {\r\n\t\tdist: {\r\n\t\t\toptions:{\r\n\t\t\t\tuglify: true\r\n\t\t\t},\r\n\t\t\tsrc: \'src/index.html\',\r\n\t\t\tdest: \'dist/index.html\'\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n\r\n### exts\r\nSetting an exts array allows multiple file extensions to be processed as\r\nhtml.\r\n\r\n```\r\ngrunt.initConfig({\r\n\tinline: {\r\n\t\tdist: {\r\n\t\t\toptions:{\r\n\t\t\t exts: [\'jade\'],\r\n\t\t\t\tuglify: true\r\n\t\t\t},\r\n\t\t\tsrc: \'src/index.jade\',\r\n\t\t\tdest: \'dist/index.jade\'\r\n\t\t}\r\n\t}\r\n});\r\n```\r\n\r\n### Usage Examples\r\n\r\n> config\r\n\r\n\tgrunt.initConfig({\r\n\t inline: {\r\n\t dist: {\r\n\t src: \'src/index.html\'\r\n\t }\r\n\t }\r\n\t})\r\n\r\n> src/index.html\r\n\r\n\t\r\n\t\t\r\n\t\t\tdemo\r\n\t\t\t\r\n\t\t\r\n\t\t\r\n\t\t\t\r\n\r\n\t\t\t\r\n\t\t\r\n\t\r\n\r\n> after `grunt inline` was run, it will be something like\r\n\r\n\t\r\n\t\t\r\n\t\t\tdemo\r\n\t\t\t\r\n\t\t\r\n\t\t\r\n\t\t\t\r\n\t\t\t\r\n\r\n\t\t\t\r\n\t\t\r\n\t\r\n\r\n#### inline tag\r\nSuppose there is an `` tag in `index.html` like bellow\r\n\r\n```\r\n\r\n\r\n```\r\n\r\nThe content of `test.html` is\r\n\r\n```\r\n

I\'m inline html

\r\nhello world!\r\n```\r\n\r\nThen, after the `inline` task is run, the original content in `index.html` will be replaced with\r\n\r\n```\r\n

I\'m inline html

\r\nhello world!\r\n```\r\n\r\n## Contributing\r\nIn lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).\r\n\r\n## Release History\r\n* 2015-01-09 v0.3.3 bug fix: when processing files of a folder and then copy the processed content to another destination, the original files are changed unexpectedly, as mentioned in this issue [Support file globbing for input and output](https://github.com/chyingp/grunt-inline/issues/35)\r\n* 2014-06-16 v0.3.1 bug fix: protocol-relative urls in css are messed up\r\n* 2014-06-15 v0.3.1 bug fix: when options.tag is \'\', then all img tags, whose src attribute has already been inlined will be matched.\r\n* 2014-05-19 v0.3.0 support for new options.exts\r\n* 2014-05-19 v0.2.9 bug fix: options.tag is assigned \'\', bug image url in css are not converted to base64 formate\r\n* 2014-03-06 v0.2.6 bug fix: script tags like were not inlined\r\n* 2014-01-31 v0.2.3 radded tag option, encode url(..) images.\r\n* 2013-10-31  v0.2.2 bug fix: img urls like \'background: url(http://www.example.com/img/bg.png)\' will be transformed to \'background: url(url(http://www.example.com/img/bg.png))\'\r\n* 2013-10-30  v0.2.1 bug fix: when processing relative file path of img url in css stylesheet, forgot to transform "\\" to "/" for windows users\r\n* 2013-10-30  v0.2.0 new feature: Support for minifing js、css when they ar inlined into html.\r\n* 2013-08-30  v0.1.9 bug fix: stylesheets ended with ">" cannot be inlined\r\n* 2013-09-02  v0.1.9 add feature: add options.dest to assign a destination path where the source file will be copied\r\n* 2013-09-02  v0.1.8 add feature: support for `` tag\r\n', -28 silly publish readmeFilename: 'README.md', -28 silly publish gitHead: '497e222702d0c6564d3a9d8d1f7979cad803b08f', -28 silly publish bugs: { url: 'https://github.com/chyingp/grunt-inline/issues' }, -28 silly publish homepage: 'https://github.com/chyingp/grunt-inline', -28 silly publish _shasum: '0ae2fb5c1b1569bbea0003db01c015f4371f662d' } -29 verbose url raw grunt-inline -30 verbose url resolving [ 'https://registry.npmjs.org/', './grunt-inline' ] -31 verbose url resolved https://registry.npmjs.org/grunt-inline -32 info trying registry request attempt 1 at 02:27:12 -33 http PUT https://registry.npmjs.org/grunt-inline -34 http 403 https://registry.npmjs.org/grunt-inline -35 verbose headers { date: 'Thu, 08 Jan 2015 18:27:14 GMT', -35 verbose headers server: 'CouchDB/1.5.0 (Erlang OTP/R16B03)', -35 verbose headers 'content-type': 'application/json', -35 verbose headers 'cache-control': 'max-age=60', -35 verbose headers 'content-length': '230', -35 verbose headers 'accept-ranges': 'bytes', -35 verbose headers via: '1.1 varnish', -35 verbose headers 'x-served-by': 'cache-ty66-TYO', -35 verbose headers 'x-cache': 'MISS', -35 verbose headers 'x-cache-hits': '0', -35 verbose headers 'x-timer': 'S1420741634.005146,VS0,VE239', -35 verbose headers 'keep-alive': 'timeout=10, max=50', -35 verbose headers connection: 'Keep-Alive' } -36 error publish Failed PUT 403 -37 error Error: forbidden Attempting to modify version 0.3.3, -37 error which was previously published on 2015-01-08T17:00:33.229Z. -37 error This is forbidden, to maintain package integrity. -37 error Please update the version number and try again.: grunt-inline -37 error at RegClient. (/usr/local/lib/node_modules/npm/node_modules/npm-registry-client/lib/request.js:274:14) -37 error at Request._callback (/usr/local/lib/node_modules/npm/node_modules/npm-registry-client/lib/request.js:212:65) -37 error at Request.self.callback (/usr/local/lib/node_modules/npm/node_modules/request/request.js:123:22) -37 error at Request.emit (events.js:98:17) -37 error at Request. (/usr/local/lib/node_modules/npm/node_modules/request/request.js:893:14) -37 error at Request.emit (events.js:117:20) -37 error at IncomingMessage. (/usr/local/lib/node_modules/npm/node_modules/request/request.js:844:12) -37 error at IncomingMessage.emit (events.js:117:20) -37 error at _stream_readable.js:929:16 -37 error at process._tickCallback (node.js:419:13) -38 error If you need help, you may report this *entire* log, -38 error including the npm and node versions, at: -38 error -39 error System Darwin 13.4.0 -40 error command "node" "/usr/local/bin/npm" "publish" -41 error cwd /Users/a/Documents/git-code/grunt-inline -42 error node -v v0.10.29 -43 error npm -v 1.4.14 -44 verbose exit [ 1, true ] diff --git a/tasks/inline.js b/tasks/inline.js index 556077d..a053102 100644 --- a/tasks/inline.js +++ b/tasks/inline.js @@ -34,7 +34,7 @@ module.exports = function(grunt) { var fileContent = grunt.file.read(filepath); var destFilepath = ''; - grunt.log.write('Processing ' + filepath + '...') + grunt.log.write('Processing ' + filepath + '... '); if(fileType==='html' || (exts && exts.indexOf(fileType) > -1)){ fileContent = html(filepath, fileContent, relativeTo, options); @@ -43,17 +43,21 @@ module.exports = function(grunt) { } if(detectDestType(filePair.dest) === 'directory') { - destFilepath = (isExpandedPair) ? filePair.dest : unixifyPath(path.join(filePair.dest, filepath)); + destFilepath = (isExpandedPair) ? filePair.dest : unixifyPath(path.join(filePair.dest, fileName(filepath))); }else{ destFilepath = filePair.dest || filepath; } grunt.file.write(destFilepath, fileContent); - grunt.log.ok() + grunt.log.ok(); }); }); }); + function fileName(filePath) { + return filePath.replace(/^.*[\\\/]/, ''); + } + function isRemotePath( url ){ return url.match(/^'?https?:\/\//) || url.match(/^\/\//); } @@ -69,7 +73,7 @@ module.exports = function(grunt) { } else { return 'file'; } - } + } function unixifyPath(filepath) { if (process.platform === 'win32') { @@ -84,11 +88,13 @@ module.exports = function(grunt) { var isDestinationDirectory = (/\/$/).test(pathToDestinationFile); var fileName = path.basename(pathToSource); var newPathToDestination; + if (typeof pathToDestinationFile === 'undefined') { newPathToDestination = pathToSource; } else { newPathToDestination = pathToDestinationFile + (isDestinationDirectory ? fileName : ''); } + return newPathToDestination; } From c3de4686d7a6f8c83a76be5aff8bfae812df0aa0 Mon Sep 17 00:00:00 2001 From: Marcus Klaas Date: Thu, 9 Apr 2015 18:05:57 +0200 Subject: [PATCH 10/13] perform some trivial code cleanups --- tasks/inline.js | 127 ++++++++++++++++++------------------------------ 1 file changed, 46 insertions(+), 81 deletions(-) diff --git a/tasks/inline.js b/tasks/inline.js index a053102..9a72a5f 100644 --- a/tasks/inline.js +++ b/tasks/inline.js @@ -17,19 +17,15 @@ module.exports = function(grunt) { grunt.registerMultiTask('inline', "Replaces , '; - }else{ - grunt.log.error("Couldn't find " + inlineFilePath + '!'); + return ''; } - } - grunt.log.debug('ret = : ' + ret +'\n'); - - return ret; - }).replace(//g, function(matchedWord, src){ - var ret = matchedWord; + grunt.log.error("Couldn't find " + inlineFilePath + '!'); + } - if(!isRemotePath(src) && src.indexOf(options.tag)!=-1){ + return matchedWord; + }).replace(//g, function(matchedWord, src){ + if(!isRemotePath(src) && src.indexOf(options.tag)!=-1) { var inlineFilePath = path.resolve( path.dirname(filepath), src ).replace(/\?.*$/, ''); // 将参数去掉 if( grunt.file.exists(inlineFilePath) ){ var styleSheetContent = grunt.file.read( inlineFilePath ); - ret = ''; - }else{ - grunt.log.error("Couldn't find " + inlineFilePath + '!'); + + return ''; } + + grunt.log.error("Couldn't find " + inlineFilePath + '!'); } - grunt.log.debug('ret = : ' + ret +'\n'); - return ret; + return matchedWord; }).replace(//g, function(matchedWord, src){ - var ret = matchedWord; - if(!grunt.file.isPathAbsolute(src) && src.indexOf(options.tag)!=-1){ var inlineFilePath = path.resolve( path.dirname(filepath), src ).replace(/\?.*$/, ''); // 将参数去掉 if( grunt.file.exists(inlineFilePath) ){ - ret = matchedWord.replace(src, (new datauri(inlineFilePath)).content); - }else{ + return matchedWord.replace(src, (new datauri(inlineFilePath)).content); + } else { grunt.log.error("Couldn't find " + inlineFilePath + '!'); } - } - grunt.log.debug('ret = : ' + ret +'\n'); + } - return ret; + return matchedWord; }); return fileContent; } function css(filepath, fileContent, relativeTo, options) { - if(relativeTo){ + if(relativeTo) { filepath = filepath.replace(/[^\/]+\//g, relativeTo); } - fileContent = fileContent.replace(/url\(["']*([^)'"]+)["']*\)/g, function(matchedWord, imgUrl){ - var newUrl = imgUrl; + fileContent = fileContent.replace(/url\(["']*([^)'"]+)["']*\)/g, function(matchedWord, imgUrl) { var flag = imgUrl.indexOf(options.tag)!=-1; // 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); + var newUrl = path.relative( path.dirname(filepath), absoluteImgurl ); absoluteImgurl = absoluteImgurl.replace(/\?.*$/, ''); - if(flag && grunt.file.exists(absoluteImgurl)){ + + if(flag && grunt.file.exists(absoluteImgurl)) { newUrl = datauri(absoluteImgurl); - }else{ + } else { newUrl = newUrl.replace(/\\/g, '/'); } return matchedWord.replace(imgUrl, newUrl); }); - fileContent = options.cssmin ? CleanCSS.process(fileContent) : fileContent; - return fileContent; + return options.cssmin ? CleanCSS.process(fileContent) : fileContent; } function cssInlineToHtml(htmlFilepath, filepath, fileContent, relativeTo, options) { @@ -223,31 +193,26 @@ module.exports = function(grunt) { } 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 - grunt.log.debug('flag:'+flag); + 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 ); // img url relative to project root - grunt.log.debug( 'absoluteImgurl: '+absoluteImgurl); - newUrl = path.relative( path.dirname(htmlFilepath), absoluteImgurl ); // img url relative to the html file - grunt.log.debug([htmlFilepath, filepath, absoluteImgurl, imgUrl]); - grunt.log.debug( 'newUrl: '+newUrl); + + var absoluteImgurl = path.resolve( path.dirname(filepath), imgUrl ); // img url relative to project root + var newUrl = path.relative( path.dirname(htmlFilepath), absoluteImgurl ); // img url relative to the html file absoluteImgurl = absoluteImgurl.replace(/\?.*$/, ''); + if(flag && grunt.file.exists(absoluteImgurl)){ newUrl = datauri(absoluteImgurl); - }else{ + } else { newUrl = newUrl.replace(/\\/g, '/'); } return matchedWord.replace(imgUrl, newUrl); }); - fileContent = options.cssmin ? CleanCSS.process(fileContent) : fileContent; - return fileContent; + return options.cssmin ? CleanCSS.process(fileContent) : fileContent; } }; From 2f049ab36e51c7d2a218708ac765a752ac6df0bd Mon Sep 17 00:00:00 2001 From: Marcus Klaas Date: Thu, 9 Apr 2015 18:27:57 +0200 Subject: [PATCH 11/13] fix inline tag attributes --- .travis.yml | 1 - tasks/inline.js | 10 ++++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index e08909b..6ef04eb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ language: node_js node_js: - "0.10" - - "0.8" before_script: - npm install -g grunt-cli diff --git a/tasks/inline.js b/tasks/inline.js index 635abdb..026541d 100644 --- a/tasks/inline.js +++ b/tasks/inline.js @@ -16,7 +16,13 @@ module.exports = function(grunt) { grunt.registerMultiTask('inline', "Replaces , '; - }else{ - grunt.log.error("Couldn't find " + inlineFilePath + '!'); - } - } - - return matchedWord; - }).replace(//g, function(matchedWord, src){ - if(!isRemotePath(src) && src.indexOf(options.tag)!=-1) { - var inlineFilePath = path.resolve(path.dirname(filepath), src).replace(/\?.*$/, ''); + if( grunt.file.exists(inlineFilePath) ){ + var inlineTagAttributes = options.inlineTagAttributes.js; + return ''; + }else{ + grunt.log.error("Couldn't find " + inlineFilePath + '!'); + } + } - if (grunt.file.exists(inlineFilePath)) { - var styleSheetContent = grunt.file.read(inlineFilePath); + return matchedWord; + } - return ''; + function htmlInclusion(matchedWord, src){ + if(isRemotePath(src) || !grunt.file.isPathAbsolute(src)) { + var inlineFilePath = path.resolve( path.dirname(filepath), src ); + + if( grunt.file.exists(inlineFilePath) ){ + var ret = grunt.file.read( inlineFilePath ); + + // @otod need to be checked, add bye herbert + var _more = src.match(/^(..\/)+/ig); + if(_more = _more && _more[0]) { + var _addMore = function(){ + var _ret = arguments[0],_src = arguments[2]; + if(!_src.match(/^http\:\/\//)){ + _ret = arguments[1] + _more + arguments[2] + arguments[3]; + } + + return _ret; + }; + + ret = ret.replace(/(<\/script>)/g,_addMore); + } + + return ret; } else { grunt.log.error("Couldn't find " + inlineFilePath + '!'); } } - return matchedWord; - }).replace(//g, function(matchedWord, src) { - if(!grunt.file.isPathAbsolute(src) && src.indexOf(options.tag)!=-1) { - var inlineFilePath = path.resolve( path.dirname(filepath), src ).replace(/\?.*$/, ''); // 将参数去掉 - - if( grunt.file.exists(inlineFilePath) ){ - return matchedWord.replace(src, (new datauri(inlineFilePath)).content); - } else { - grunt.log.error("Couldn't find " + inlineFilePath + '!'); - } - } - - return matchedWord; - }); + return matchedWord; + } - return fileContent; + return fileContent.replace(//gi, htmlInclusion) + .replace(/\s*<\/script>/gi, scriptReplacement) + .replace(//gi, imageReplacement) + .replace(//gi, cssReplacement) + .replace(//gi, imageReplacement); } function css(filepath, fileContent, relativeTo, options) { diff --git a/test/dist/css.html b/test/dist/css.html index ffede39..0f2de95 100644 --- a/test/dist/css.html +++ b/test/dist/css.html @@ -6,7 +6,7 @@ - + diff --git a/test/dist/icon.html b/test/dist/icon.html new file mode 100644 index 0000000..54b518e --- /dev/null +++ b/test/dist/icon.html @@ -0,0 +1,13 @@ + + + + test + + + + + + + + + \ No newline at end of file diff --git a/test/expected/icon.min.html b/test/expected/icon.min.html new file mode 100644 index 0000000..5b110b9 --- /dev/null +++ b/test/expected/icon.min.html @@ -0,0 +1,6 @@ +test \ No newline at end of file diff --git a/test/inline_test.js b/test/inline_test.js index f8dc6f2..ee64332 100644 --- a/test/inline_test.js +++ b/test/inline_test.js @@ -22,7 +22,7 @@ function assertFileEquality(test, pathToActual, pathToExpected, message) { exports.inline = function(test) { 'use strict'; - test.expect(4); + test.expect(5); assertFileEquality(test, 'tmp/css.min.html', @@ -44,5 +44,10 @@ exports.inline = function(test) { 'test/expected/script.min.html', 'Should compile script inline'); + assertFileEquality(test, + 'tmp/icon.min.html', + 'test/expected/icon.min.html', + 'Should not inline non-stylesheet links'); + test.done(); }; \ No newline at end of file