[FEATURE] Extend mustache template context using global options.context variable…
[FEATURE] Extend mustache template context using global options.context variable or alter context of SVG data
Merge request reports
Activity
Filter activity
Hi,
Great plugin!
We've made some adjustments. With these changes you can add context on the root template and/or modify the context per SVG, allowing this template to be used:
{{message}} {{#svgs}} ${{prefix}}-{{{variableName}}}: "{{{inline}}}"; {{/svgs}}
// gulpfile.js gulp.task('inline-svg', function() { return gulp.src('assets/icons/**/*.svg') .pipe(inlineSvg({ filename: 'icons.scss', template: 'assets/icons/template.mustache', context: { message: '// GENERATED BY gulpfile.js' }, interceptor: function (svgData, file) { return Object.assign(svgData, { variableName: path.basename(file.path, '.svg').toLowerCase(), prefix: 'dso-icon' }); } })) .pipe(gulp.dest('src/styles/icons')); });
Output:
// GENERATED BY gulpfile.js $icon-error_32x32: "data:image/svg+xml;charset=utf8,%3C?xml version='1.0' [..] %3C/g%3E %3C/svg%3E"; $icon-information_32x32: "data:image/svg+xml;charset=utf8,%3C?xml version='1.0' [..] %3C/g%3E %3C/svg%3E"; $icon-succes_32x32: "data:image/svg+xml;charset=utf8,%3C?xml version='1.0' [..] %3C/g%3E %3C/svg%3E"; $icon-warning_32x32: "data:image/svg+xml;charset=utf8,%3C?xml version='1.0' [..] %3C/g%3E %3C/svg%3E";
This is a simple example, but basically we want to control the
name
variable: We want to generate the variable name using the SVG's filename AND pathEdited by Thomasassigned to @pnowinski
mentioned in commit 095c5dbf
Hi @thomas,
thanks so much for contributing! This looks like a great addition. I just merged your changes and released it to NPM as version 1.2.0 :-)
Please register or sign in to reply