Extract inlined styles

Fixes #2 
Yeah, we could use https://www.npmjs.org/package/reaver, it's basically the
same thing but in an actual package



github <https://github.com/bevacqua> · blog <http://blog.ponyfoo.com/> ·
twitter <https://twitter.com/nzgb> · book <http://bevacqua.io/buildfirst> ·
career <http://careers.stackoverflow.com/bevacqua> ·about
<http://bevacqua.io/>

On Mon, Oct 20, 2014 at 12:45 AM, Ben Zörb <notifications@github.com> wrote:

> In index.js:
>
> > @@ -36,6 +41,21 @@ module.exports = function(html, styles, minify) {
> >      return el.attr('href');
> >    }).toArray();
> >
> > +  // extract styles from stylesheets if extract option is set
> > +  if (o.extract) {
> > +    if (!o.basePath) {
> > +      throw new Error('Option `basePath` is missing and required when using `extract`!');
> > +    }
> > +    hrefs.forEach(function(href) {
> > +      var file = path.resolve(o.basePath, href);
> > +      if (!fs.existsSync(file)) {
> > +        return;
> > +      }
> > +      var diff = cave(file, { css: styles });
> > +      fs.writeFileSync(file, diff);
>
> Yes, i thought about something like this:
> https://github.com/yeoman/grunt-filerev/blob/master/tasks/filerev.js#L46.
> Of course the filename used in
> https://github.com/bezoerb/inline-critical/blob/master/index.js#L32 and
> https://github.com/bezoerb/inline-critical/blob/master/index.js#L52 need
> to be changed as well.
> I think this is the only way to avoid conflicts. If you've got another
> idea please let me know.
> The rest looks good to me.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/bezoerb/inline-critical/pull/3/files#r19067376>.
>