var gulp = require('gulp')
var pug = require('gulp-pug')
var less = require('gulp-less')
var autoprefixer = require('gulp-autoprefixer')
var clean_css = require('gulp-clean-css')
var sourcemaps = require('gulp-sourcemaps')

gulp.task('pug:index', function () {
  return gulp.src('index.pug')
    .pipe(pug({
      basedir: './',
    }))
    .pipe(gulp.dest('./'))
})

gulp.task('pug:docs', function () {
  return gulp.src('docs/{index,principles,base,obj,comp,org,help,atom}.pug')
    .pipe(pug({
      basedir: './',
      locals: {
        Color             : require('csscolor').Color,
        Docs              : require('./docs/_models/Docs.class.js'),
        Util              : require('./_models/Util.class.js'),
        ConfSite          : require('./_models/ConfSite.class.js'),
        ConfPage          : require('./_models/ConfPage.class.js'),
        Conference        : require('./_models/Conference.class.js'),
        SupporterLevel    : require('./_models/SupporterLevel.class.js'),
        Supporter         : require('./_models/Supporter.class.js'),
        Person            : require('./_models/Person.class.js'),
        Place             : require('./_models/Place.class.js'),
        RegistrationPeriod: require('./_models/RegistrationPeriod.class.js'),
        Pass              : require('./_models/Pass.class.js'),
        Session           : require('./_models/Session.class.js'),
        ImportantDate     : require('./_models/ImportantDate.class.js'),
      },
    }))
    .pipe(gulp.dest('./docs/'))
})

gulp.task('pug:all', ['pug:index', 'pug:docs'])

gulp.task('lessc:neo', function () {
  return gulp.src('neo.less')
    .pipe(less())
    .pipe(autoprefixer({
      grid: true,
      cascade: false,
    }))
    .pipe(gulp.dest('./'))
})

gulp.task('lessc:docs', function () {
  return gulp.src('./docs/styles/docs.less')
    .pipe(less())
    .pipe(autoprefixer({
      grid: true,
      cascade: false,
    }))
    .pipe(gulp.dest('./docs/styles/'))
})

gulp.task('lessc:all', ['lessc:neo', 'lessc:docs'])

gulp.task('minify:neo', ['lessc:neo'], function () {
  return gulp.src('neo.css')
    .pipe(sourcemaps.init())
    .pipe(clean_css())
    .pipe(sourcemaps.write('./')) // write to an external .map file
    .pipe(gulp.dest('./'))
})

gulp.task('minify:docs', ['lessc:docs'], function () {
  return gulp.src('./docs/styles/docs.css')
    .pipe(sourcemaps.init())
    .pipe(clean_css())
    .pipe(sourcemaps.write('./')) // write to an external .map file
    .pipe(gulp.dest('./docs/styles/'))
})

gulp.task('minify:all', ['minify:neo', 'minify:docs'])

gulp.task('build', ['pug:all', 'lessc:all', 'minify:all'])

@@ -1596,19 +1596,20 @@
 ('lessc:
-neo
+core
 ', funct
@@ -1757,32 +1757,179 @@
 ulp.dest('./'))%0A
+    .pipe(sourcemaps.init())%0A    .pipe(clean_css())%0A    .pipe(sourcemaps.write('./')) // write to an external .map file%0A    .pipe(gulp.dest('./'))%0A
 %7D)%0A%0Agulp.task('l
@@ -2168,289 +2168,15 @@
 ssc:
-neo', 'lessc:docs'%5D)%0A%0Agulp.task('minify:neo', %5B'lessc:neo'%5D, function () %7B%0A  return gulp.src('neo.css')%0A    .pipe(sourcemaps.init())%0A    .pipe(clean_css())%0A    .pipe(sourcemaps.write('./')) // write to an external .map file%0A    .pipe(gulp.dest('./'))%0A%7D)%0A%0Agulp.task('minify:docs
+core
 ', 
-%5B
 'les
@@ -2188,284 +2188,8 @@
 cs'%5D
-, function () %7B%0A  return gulp.src('./docs/styles/docs.css')%0A    .pipe(sourcemaps.init())%0A    .pipe(clean_css())%0A    .pipe(sourcemaps.write('./')) // write to an external .map file%0A    .pipe(gulp.dest('./docs/styles/'))%0A%7D)%0A%0Agulp.task('minify:all', %5B'minify:neo', 'minify:docs'%5D
 )%0A%0Ag
@@ -2233,21 +2233,7 @@
 all'
-, 'minify:all'
 %5D)%0A

update gulp tasks