From b048ea545f06621e42d2f55afcc0ff819b5805ba Mon Sep 17 00:00:00 2001 From: Ross Allen Date: Wed, 18 Dec 2013 20:15:23 -0800 Subject: Write Glyphicons to _data, generate Glyphicons markup This generates a glyphicons.yml file from the glyphicons.less source, and then components.html uses that data to generate the Glyphicons docs by iterating through the data. The _data directory was introduced in Jekyll 1.3.0, and GitHub Pages is already on [version 1.4.2][1]. Fixes #11862. [1] https://github.com/github/pages-gem/blob/master/github-pages.gemspec#L16 --- Gruntfile.js | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'Gruntfile.js') diff --git a/Gruntfile.js b/Gruntfile.js index d2b371ed7..04ff10a10 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -299,13 +299,40 @@ module.exports = function (grunt) { grunt.registerTask('dist', ['clean', 'dist-css', 'dist-fonts', 'dist-js']); // Default task. - grunt.registerTask('default', ['test', 'dist', 'build-customizer']); + grunt.registerTask('default', ['test', 'dist', 'build-glyphicons-data', 'build-customizer']); // Version numbering task. // grunt change-version-number --oldver=A.B.C --newver=X.Y.Z // This can be overzealous, so its changes should always be manually reviewed! grunt.registerTask('change-version-number', ['sed']); + grunt.registerTask('build-glyphicons-data', function () { + var fs = require('fs') + + // Pass encoding, utf8, so `readFileSync` will return a string instead of a + // buffer + var glyphiconsFile = fs.readFileSync('less/glyphicons.less', 'utf8') + var glpyhiconsLines = glyphiconsFile.split('\n') + + // Use any line that starts with ".glyphicon-" and capture the class name + var iconClassName = /^\.(glyphicon-[^\s]+)/ + var glyphiconsData = '# Generated on ' + (new Date()) + '\n' + + '# **Don\'t edit this directly!**\n' + + '# Look at the \'build-glyphicons-data\' task in Gruntfile.js\n\n'; + for (var i = 0, len = glpyhiconsLines.length; i < len; i++) { + var match = glpyhiconsLines[i].match(iconClassName) + + if (match != null) { + glyphiconsData += '- ' + match[1] + '\n' + } + } + + // Create the `_data` directory if it doesn't already exist + if (!fs.existsSync('_data')) fs.mkdirSync('_data') + + fs.writeFileSync('_data/glyphicons.yml', glyphiconsData) + }); + // task for building customizer grunt.registerTask('build-customizer', 'Add scripts/less files to customizer.', function () { var fs = require('fs') -- cgit v1.2.3