You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 line
1.4KB

  1. /*!
  2. * Bootstrap Grunt task for Glyphicons data generation
  3. * http://getbootstrap.com
  4. * Copyright 2014-2015 Twitter, Inc.
  5. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
  6. */
  7. 'use strict';
  8. var fs = require('fs');
  9. module.exports = function generateGlyphiconsData(grunt) {
  10. // Pass encoding, utf8, so `readFileSync` will return a string instead of a
  11. // buffer
  12. var glyphiconsFile = fs.readFileSync('less/glyphicons.less', 'utf8');
  13. var glyphiconsLines = glyphiconsFile.split('\n');
  14. // Use any line that starts with ".glyphicon-" and capture the class name
  15. var iconClassName = /^\.(glyphicon-[a-zA-Z0-9-]+)/;
  16. var glyphiconsData = '# This file is generated via Grunt task. **Do not edit directly.**\n' +
  17. '# See the \'build-glyphicons-data\' task in Gruntfile.js.\n\n';
  18. var glyphiconsYml = 'docs/_data/glyphicons.yml';
  19. for (var i = 0, len = glyphiconsLines.length; i < len; i++) {
  20. var match = glyphiconsLines[i].match(iconClassName);
  21. if (match !== null) {
  22. glyphiconsData += '- ' + match[1] + '\n';
  23. }
  24. }
  25. // Create the `_data` directory if it doesn't already exist
  26. if (!fs.existsSync('docs/_data')) {
  27. fs.mkdirSync('docs/_data');
  28. }
  29. try {
  30. fs.writeFileSync(glyphiconsYml, glyphiconsData);
  31. } catch (err) {
  32. grunt.fail.warn(err);
  33. }
  34. grunt.log.writeln('File ' + glyphiconsYml.cyan + ' created.');
  35. };