description and source-codegulp-kss = function (opt) {
'use strict';
if (!opt) opt = {};
if (!opt.templateDirectory) opt.templateDirectory = __dirname + '/node_modules/kss/lib/template';
if (!opt.kssOpts) opt.kssOpts = {};
var buffer = [];
var firstFile = null;
function bufferContents(file){
if (file.isNull()) return; // ignore
if (file.isStream()) return this.emit('error', new PluginError('gulp-kss', 'Streaming not supported'));
if (!firstFile) firstFile = file;
buffer.push(file.contents.toString('utf8'));
}
/* Is called when all files were added to buffer */
function endStream(){
var template = fs.readFileSync(path.join(opt.templateDirectory, 'index.html'), 'utf8');
template = handlebars.compile(template);
var self = this;
kss.parse(buffer, opt.kssOpts, function (err, styleguide) {
if (err) console.log('Error', error);
var sections = styleguide.section('*.'),
i, sectionCount = sections.length,
sectionRoots = [], currentRoot,
rootCount, childSections = [];
// Accumulate all of the sections' first indexes
// in case they don't have a root element.
for (i = 0; i < sectionCount; i += 1) {
currentRoot = sections[i].reference().match(/[0-9]*\.?/)[0].replace('.', '');
if (!~sectionRoots.indexOf(currentRoot)) {
sectionRoots.push(currentRoot);
}
}
sectionRoots.sort();
rootCount = sectionRoots.length;
handlebarHelpers(handlebars, styleguide);
// Now, group all of the sections by their root
// reference, and make a page for each.
for (i = 0; i < rootCount; i += 1) {
childSections = styleguide.section(sectionRoots[i]+'.*');
var content = template({
styleguide: styleguide,
sections: jsonSections(childSections),
rootNumber: sectionRoots[i],
sectionRoots: sectionRoots,
overview: false,
argv: {}
});
var joinedPath = path.join(firstFile.base, 'section-' + sectionRoots[i] + '.html');
var file = new File({
cwd: firstFile.cwd,
base: firstFile.base,
path: joinedPath,
contents: new Buffer(content)
});
self.emit('data', file);
}
// Generate Overview File
if (opt.overview) {
gulp.src(opt.overview)
.pipe(through(function (file) {
var content = template({
styleguide: styleguide,
sectionRoots: sectionRoots,
sections: jsonSections(childSections),
rootNumber: 0,
argv: {},
overview: marked(file.contents.toString('utf8'), 'utf8')
});
var joinedPath = path.join(firstFile.base, 'index.html');
var file = new File({
cwd: firstFile.cwd,
base: firstFile.base,
path: joinedPath,
contents: new Buffer(content)
});
self.emit('data', file);
}));
}
// Copy template assets, less compilation added because default template uses it
gulp.src(path.join(opt.templateDirectory, '/**/*.less'))
.pipe(gulpless())
.pipe(through(function (file) {
self.emit('data', file);
}));
gulp.src(path.join(opt.templateDirectory, '/**/*.js')) ...