Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to split symbols wrapped inside on one svg into single files? #59

Closed
harshes53 opened this issue Mar 8, 2016 · 5 comments

Comments

@harshes53
Copy link

No description provided.

@TrySound
Copy link
Contributor

TrySound commented Mar 9, 2016

@hatchbee This module combines many svg, not splits.

@harshes53
Copy link
Author

@TrySound Yes I know that and been using in one of my projects too. Great tool indeed.

But now that I have to change all the font icons in my project and I have 5-6 svg files with lots of symbols in each.

I was wondering if there would be any option/module which could split all the symbols in every files and bundle up into one final svg.

Thanks! This is more of a question rather than issue.

@w0rm
Copy link
Owner

w0rm commented Mar 9, 2016

@hatchbee I don't know such module, you can create it yourself, something like this (not tested):

var cheerio = require('cheerio')
var path = require('path')
var gutil = require('gulp-util')
var Stream = require('stream')

function extractSymbols() {
   var stream = new Stream.Transform({ objectMode: true })

  stream._transform = function transform (file, encoding, cb) {
      var self = this;
      var $ = cheerio.load(file.contents.toString(), { xmlMode: true });
      $('symbol').each(function(idx, symbol) {
          var content = // extract what you need from symbol and wrap in <svg>
          var file = new gutil.File({ path:  $(symbol).attr('id') + '.svg', contents: new Buffer(content) });
          self.push(file);
      }
      cb();
  }

   return stream;
});

Usage:

gulp.task('extract-svg', function () {
  return gulp.src('*.svg')
    .pipe(extractSymbols())
    .pipe(gulp.dest('.'))
})

@w0rm w0rm closed this as completed Mar 9, 2016
@harshes53
Copy link
Author

@w0rm thanks! Appreciate 👍

@w0rm
Copy link
Owner

w0rm commented Mar 9, 2016

@hatchbee you're welcome, its just a rough idea :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants