Skip to content

Instantly share code, notes, and snippets.

@esmarkowski
Created January 22, 2016 00:52
Show Gist options
  • Save esmarkowski/186328d4bb1afdae47dd to your computer and use it in GitHub Desktop.
Save esmarkowski/186328d4bb1afdae47dd to your computer and use it in GitHub Desktop.
Bootstrap Themes in Rails
var gulp = require('gulp')
var path = require('path')
var less = require('gulp-less')
var autoprefixer = require('gulp-autoprefixer')
var sourcemaps = require('gulp-sourcemaps')
var minifyCSS = require('gulp-minify-css')
var rename = require('gulp-rename')
var concat = require('gulp-concat')
var uglify = require('gulp-uglify')
var connect = require('gulp-connect')
var open = require('gulp-open')
var Paths = {
HERE : './',
DIST : 'app/assets/stylesheets',
DIST_JS : 'app/assets/javascripts',
DIST_TOOLKIT_JS : 'app/assets/javascripts/toolkit.js',
LESS_TOOLKIT_SOURCES : './lib/bootstrap_theme/less/toolkit*',
LESS : './lib/bootstrap_theme/less/**/**',
JS : [
'./lib/bootstrap_theme/js/bootstrap/transition.js',
'./lib/bootstrap_theme/js/bootstrap/alert.js',
'./lib/bootstrap_theme/js/bootstrap/affix.js',
'./lib/bootstrap_theme/js/bootstrap/button.js',
'./lib/bootstrap_theme/js/bootstrap/carousel.js',
'./lib/bootstrap_theme/js/bootstrap/collapse.js',
'./lib/bootstrap_theme/js/bootstrap/dropdown.js',
'./lib/bootstrap_theme/js/bootstrap/modal.js',
'./lib/bootstrap_theme/js/bootstrap/tooltip.js',
'./lib/bootstrap_theme/js/bootstrap/popover.js',
'./lib/bootstrap_theme/js/bootstrap/scrollspy.js',
'./lib/bootstrap_theme/js/bootstrap/tab.js',
'./lib/bootstrap_theme/js/custom/*'
]
}
gulp.task('default', ['less', 'js'])
gulp.task('watch', function () {
gulp.watch(Paths.LESS, ['less-min']);
gulp.watch(Paths.JS, ['js-min']);
})
gulp.task('docs', ['server'], function () {
gulp.src(__filename)
.pipe(open({uri: 'http://localhost:9001/docs/'}))
})
gulp.task('server', function () {
connect.server({
root: 'docs',
port: 9001,
livereload: true
})
})
gulp.task('less', function () {
return gulp.src(Paths.LESS_TOOLKIT_SOURCES)
.pipe(sourcemaps.init())
.pipe(less())
.pipe(autoprefixer())
.pipe(sourcemaps.write(Paths.HERE))
.pipe(gulp.dest('dist'))
})
gulp.task('less-min', ['less'], function () {
return gulp.src(Paths.LESS_TOOLKIT_SOURCES)
.pipe(sourcemaps.init())
.pipe(less())
.pipe(minifyCSS())
.pipe(autoprefixer())
.pipe(rename({
suffix: '.min'
}))
.pipe(sourcemaps.write(Paths.HERE))
.pipe(gulp.dest(Paths.DIST))
})
gulp.task('js', function () {
return gulp.src(Paths.JS)
.pipe(concat('toolkit.js'))
.pipe(gulp.dest(Paths.DIST_JS))
})
gulp.task('js-min', ['js'], function () {
return gulp.src(Paths.DIST_TOOLKIT_JS)
.pipe(uglify())
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest(Paths.DIST_JS))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment