'use strict';
// -----------------------------------------------------------------------------
// Sass
// -----------------------------------------------------------------------------
var gulp = require('gulp');
var sass = require('gulp-sass');
var autoprefixer = require('gulp-autoprefixer');
var pixrem = require('gulp-pixrem');
var rename = require('gulp-rename');
var minifyCSS = require('gulp-minify-css');
var notify = require('gulp-notify');

//------------------------------------------------------------------------
// Error handling
//------------------------------------------------------------------------
var handleErrors = function(errorObject, callback) {
  notify.onError(errorObject.toString().split(': ').join(':\n')).apply(this, arguments);
  // Keep gulp from hanging on this task
  if (typeof this.emit === 'function') {
    this.emit('end');
  }
};

//------------------------------------------------------------------------
// Build
//------------------------------------------------------------------------
gulp.task('sass', function() {
  return gulp.src('*.scss')
  .pipe( sass({
      outputStyle: 'expanded',
      precision: 6
    }))
    .on('error', handleErrors)
    // Add rem fallbacks using pixrem
    .pipe( pixrem() )// options https://github.com/robwierzbowski/node-pixrem#options
    .on('error', handleErrors)
    .pipe( autoprefixer({
      browsers: [
        'ie >= 8',
        'ie_mob >= 10',
        'ff >= 25',
        'chrome >= 32',
        'safari >= 7',
        'opera >= 19',
        'ios >= 6',
        'android >= 2',
        'bb >= 10'
      ],
      cascade: false
    }))
    .on('error', handleErrors)
    .pipe( gulp.dest('./dist'))
    // Minify
    .pipe( minifyCSS({
      advanced: false,
      // TODO: urlQuotes does not seem to be working
      compatibility: {
        '*': {
          properties: {
            urlQuotes: true// Required for inline SVGs
          }
        }
      }
    }))
    .pipe( rename({ suffix: '.min' }) )
    .pipe( gulp.dest('./dist'))
});

// -----------------------------------------------------------------------------
// Lint
// -----------------------------------------------------------------------------
var sassLint = require('gulp-sass-lint');

gulp.task('lint', function() {
  return gulp.src('*.scss')
    .pipe(sassLint())
    .pipe(sassLint.format())
    .pipe(sassLint.failOnError());
});

// -----------------------------------------------------------------------------
// Default task
// -----------------------------------------------------------------------------
gulp.task('default', ['sass', 'lint']);

@@ -1400,106 +1400,49 @@
    '
-ie %3E= 8',%0A        'ie_mob %3E= 10',%0A        'ff %3E= 25',%0A        'chrome %3E= 32',%0A        'safari
+last 2 versions',%0A        'Android
  %3E= 
-7
+4.4
 ',%0A 
@@ -1453,18 +1453,20 @@
    '
-op
+Explor
 er
-a
  %3E= 
-1
 9',%0A
@@ -1479,59 +1479,15 @@
   'i
-os
+OS
  %3E= 
-6',%0A        'android %3E= 2',%0A        'bb %3E= 10
+8
 '%0A  

Update autoprefixer config to only support more recent browsers