ratchicons-data-generator.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /*!
  2. * Ratchet Grunt task for Ratchicons data generation
  3. * http://goratchet.com
  4. * Original script from Bootstrap (http://getbootstrap.com).
  5. * Bootstrap is copyright 2014 Twitter, Inc. and licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE).
  6. */
  7. /* jshint node: true */
  8. 'use strict';
  9. var fs = require('fs');
  10. module.exports = function generateRatchiconsData() {
  11. // Pass encoding, utf8, so `readFileSync` will return a string instead of a
  12. // buffer
  13. var ratchiconsFile = fs.readFileSync('sass/ratchicons.scss', 'utf8');
  14. var ratchiconsLines = ratchiconsFile.split('\n');
  15. // Use any line that starts with ".icon-" and capture the class name
  16. var iconClassName = /^\.(icon-[^\s]+)/;
  17. var ratchiconsData = '# This file is generated via Grunt task. **Do not edit directly.**\n' +
  18. '# See the \'build-ratchicons-data\' task in Gruntfile.js.\n\n';
  19. for (var i = 0, len = ratchiconsLines.length; i < len; i++) {
  20. var match = ratchiconsLines[i].match(iconClassName);
  21. if (match !== null) {
  22. ratchiconsData += '- ' + 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. fs.writeFileSync('docs/_data/ratchicons.yml', ratchiconsData);
  30. };