Skip to content

Commit

Permalink
Version 1.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mihhail-lapushkin committed May 30, 2015
1 parent 35ccece commit cebf8ab
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ Specifies the mode of embedding.
* `true` (inclusive) means that you have to manually mark each URL that needs to be embedded using the `/* embed */` comment.
* `false` (exclusive) means that every URL is embedded, except those that are marked with `/* noembed */` comment.

#### useMimeTypeSniffing

Type: `Boolean`

Default: `true`

Should we try to use the `mmmagic` MIME-type sniffing library or should we always determine MIME-type only from the extension of the URL?

When set to `false` the extension checking is always used. When set to `true` it will first try use the `mmmagic` library. However, in case the library failed to install it will fallback to extension checking.

### Usage Examples

#### Map input and output files directly
Expand Down Expand Up @@ -124,6 +134,22 @@ cssUrlEmbed: {
}
```

#### Disable MIME-type sniffing in favor of extension checking
```js
cssUrlEmbed: {
encode: {
options: {
useMimeTypeSniffing: false
},

expand: true,
cwd: 'target/css',
src: [ '**/*.css' ],
dest: 'target/css'
}
}
```

#### Excluding URLs manually (when `inclusive: false`)
```css
.exclude-me {
Expand All @@ -150,6 +176,8 @@ cssUrlEmbed: {
```

## Release History
* **1.6.0** / 2015-05-30
* Implemented [#24](https://github.com/mihhail-lapushkin/grunt-css-url-embed/issues/24).
* **1.5.2** / 2015-04-22
* Fixed [#23](https://github.com/mihhail-lapushkin/grunt-css-url-embed/issues/23).
* **1.5.1** / 2015-02-17
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "grunt-css-url-embed",
"description": "Embed URL's as base64 strings inside your stylesheets",
"version": "1.5.2",
"version": "1.6.0",
"homepage": "https://github.com/mihhail-lapushkin/grunt-css-url-embed",
"author": {
"name": "Mihhail Lapushkin",
Expand Down
11 changes: 6 additions & 5 deletions tasks/css-url-embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ module.exports = function(grunt) {
nextUrl();
}

function resolveMimeTypeEmbedUrlAndGoToNext(url, urlContent, fileContent, nextUrl) {
function resolveMimeTypeEmbedUrlAndGoToNext(url, urlContent, fileContent, nextUrl, options) {
var urlContentInBuffer = new Buffer(urlContent);

if (mmmagicMimeType) {
if (mmmagicMimeType && options.useMimeTypeSniffing) {
mmmagicMimeType.detect(urlContentInBuffer, function(error, mimeType) {
if (error) {
mimeType = 'application/octet-stream';
Expand Down Expand Up @@ -93,7 +93,7 @@ module.exports = function(grunt) {
return nextUrl();
}

resolveMimeTypeEmbedUrlAndGoToNext(url, body, fileContent, nextUrl);
resolveMimeTypeEmbedUrlAndGoToNext(url, body, fileContent, nextUrl, options);
});
} else {
var noArgumentUrl = url;
Expand Down Expand Up @@ -134,7 +134,7 @@ module.exports = function(grunt) {

var urlContent = fs.readFileSync(urlFullPath);

resolveMimeTypeEmbedUrlAndGoToNext(url, urlContent, fileContent, nextUrl);
resolveMimeTypeEmbedUrlAndGoToNext(url, urlContent, fileContent, nextUrl, options);
}
} catch (e) {
grunt.log.error(e);
Expand Down Expand Up @@ -192,7 +192,8 @@ module.exports = function(grunt) {

var options = this.options({
failOnMissingUrl: true,
inclusive: false
inclusive: false,
useMimeTypeSniffing: true
});

var existingFiles = this.files.filter(function(file) {
Expand Down

0 comments on commit cebf8ab

Please sign in to comment.