Skip to content

Latest commit

 

History

History
33 lines (26 loc) · 934 Bytes

custom-template-and-template-adapter.md

File metadata and controls

33 lines (26 loc) · 934 Bytes

Custom template and template adapter

In this example, handlebars is used as the templating engine (via the template.adapter option).

var gulp = require('gulp');
var concat = require('gulp-concat');
var imageDataURI = require('gulp-image-data-uri');
var handlebars = require('handlebars');

gulp.task('prepare', function() {
    gulp.src('./images/*')
        .pipe(imageDataURI({
            template: {
                file: './other/data-uri-template.css',
                adapter: function (templateContent) {
                     var tpl = handlebars.compile(templateContent);

                     // bind is used to ensure scope
                     return tpl.bind(handlebars);
                 }
            }
        }))
        .pipe(concat('inline-images.css'))
        .pipe(gulp.dest('./dist'));
});

gulp.task('default', ['prepare']);

Back to readme