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

Add 'transformContent' option #32

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

antixrist
Copy link

@antixrist antixrist commented Apr 28, 2016

I use it for custom url resolver.
Example:

  // ...
    .pipe(gulpSass({
      precision: 10,
      importer: require('node-sass-import-once'),
      importOnce: {
        index: true,
        css: true,
        bower: false,

        /**
         * It's new option
         * 
         * @param {string} filename
         * @param {string} contents
         * @returns {string}
         */
        transformContent: function (filename, contents) {
          return [
            '$__filepath: unquote("'+ filename +'");',
            '@function url($url: null, $args...) {',
            '  @return __url($__filepath, $url);',
            '}',
            contents
          ].join('\n');
        }
      },
      functions: {
        '__url($filepath, $url)': function(filepath, url, done) {
          url = url.getValue();
          filepath = filepath.getValue();

          var resolvedUrl = url;
          /* ...custom url resolve here... */
          done(new sass.types.String('url('+ resolvedUrl +')'));
        },
      }
    }))
  // ...

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

Successfully merging this pull request may close these issues.

1 participant