diff options
| author | Ross Allen <[email protected]> | 2013-12-18 20:15:23 -0800 |
|---|---|---|
| committer | Ross Allen <[email protected]> | 2013-12-18 20:15:51 -0800 |
| commit | b048ea545f06621e42d2f55afcc0ff819b5805ba (patch) | |
| tree | 11134a74378bd2c70c80012e1a59543396446537 /Gruntfile.js | |
| parent | 4eaa297e683ffb1e0718ea2d77d2babfae1863bc (diff) | |
| download | bootstrap-b048ea545f06621e42d2f55afcc0ff819b5805ba.tar.xz bootstrap-b048ea545f06621e42d2f55afcc0ff819b5805ba.zip | |
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
Diffstat (limited to 'Gruntfile.js')
| -rw-r--r-- | Gruntfile.js | 29 |
1 files changed, 28 insertions, 1 deletions
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') |
