-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ahoek/inline-images
Add inline images task
- Loading branch information
Showing
6 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "gulp-tasks", | ||
"version": "2.1.2", | ||
"version": "2.2.0", | ||
"homepage": "https://github.com/ConnectHolland/gulp-tasks", | ||
"authors": [ | ||
"Arjen Smit <[email protected]>", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* Generate inline scss images task | ||
*/ | ||
'use strict'; | ||
|
||
module.exports = function(gulp, config, plugins) { | ||
var imageDataURI = require('gulp-image-data-uri'); | ||
var concat = require('gulp-concat'); | ||
var addsrc = require('gulp-add-src'); | ||
|
||
return function() { | ||
return gulp.src(config['inline-images'].src) | ||
// Create the data uris of the images | ||
.pipe(imageDataURI({ | ||
template: { | ||
file: __dirname + '/inline-images/image-data-uri-template.scss' | ||
} | ||
})) | ||
// Prepend and append scss to make the mixins | ||
.pipe(addsrc.prepend(__dirname + '/inline-images/_inline-images-prepend.scss')) | ||
.pipe(addsrc.append(__dirname + '/inline-images/_inline-images-append.scss')) | ||
// Output to generated scss file | ||
.pipe(concat('_inline-images.scss')) | ||
.pipe(gulp.dest('./style/generated')); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Inline image mixin | ||
@mixin inline-image($name) { | ||
$image-uri: map-get($inline-images, $name); | ||
background-image: url('#{$image-uri}'); | ||
background-size: 100%; | ||
|
||
@content; | ||
} | ||
|
||
// Create css classes | ||
@each $name, $url in $inline-images { | ||
.inline-image-#{$name} { | ||
@include inline-image('#{$name}'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Initialize the inline images map | ||
@function map-set($map, $key, $value) { | ||
$new: ($key: $value); | ||
@return map-merge($map, $new); | ||
} | ||
$inline-images: (); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
$inline-images: map-set($inline-images, '{{className}}', '{{dataURISchema}}'); |