Browse Source

added function that write to the output html file

main
Connor McSheffrey 11 years ago
parent
commit
8d3d63cd96
  1. 22
      Gruntfile.js

22
Gruntfile.js

@ -5,17 +5,30 @@ module.exports = function(grunt) {
pkg: grunt.file.readJSON('../package.json') pkg: grunt.file.readJSON('../package.json')
}); });
function writeToLiveSampleJS(matchedJS) { /**
* Write React component to js file
* @param {String} liveEditJS
* @param {String} componentName
*/
function writeToLiveSampleJS(liveEditJS, componentName) {
grunt.file.write('js/cookbook/' + componentName + '.js', liveEditJS); grunt.file.write('js/cookbook/' + componentName + '.js', liveEditJS);
} }
/**
* Update HTML file to include an ID and script src link
*/
function writeToHTML() {
grunt.file.write('_site/cookbook' + componentName + '.html', liveEditJS);
}
function readFromCookbookEntry(abspath, rootdir, subdir, filename) { function readFromCookbookEntry(abspath, rootdir, subdir, filename) {
var markdown = grunt.file.read(abspath), var markdown = grunt.file.read(abspath),
codeSample = /```[\S]+\s*[\s\S]*?```/g,
// read markdown file for code sample // read markdown file for code sample
matchedJS = markdown.match(/`{3}[\s\S]*?`{3}/g), matchedJS = markdown.match(codeSample),
trimmedJS, trimmedJS,
componentName, componentName,
componentNameCamelCase, componentNameCamelCase,
@ -44,11 +57,12 @@ module.exports = function(grunt) {
// Add code sample to live edit // Add code sample to live edit
liveEditJS = '/**\n * @jsx React.DOM\n */\n\n var ' + componentNameUpperCase + '_COMPONENT = "' + matchedJS + '";\n React.renderComponent(\n ReactPlayground( {codeText:' + componentNameUpperCase + '_COMPONENT} ),\n document.getElementById("' + componentNameCamelCase + 'Example")\n );' liveEditJS = '/**\n * @jsx React.DOM\n */\n\n var ' + componentNameUpperCase + '_COMPONENT = "' + matchedJS + '";\n React.renderComponent(\n ReactPlayground( {codeText:' + componentNameUpperCase + '_COMPONENT} ),\n document.getElementById("' + componentNameCamelCase + 'Example")\n );'
console.log(componentName);
writeToLiveSampleJS(liveEditJS, componentName); writeToLiveSampleJS(liveEditJS, componentName);
} }
grunt.registerTask('makeLiveSamples', 'Out live edit JS file for code samples in React Cookbook entries', function() { grunt.registerTask('makeLiveSamples', 'Create live edit JS file for code samples in React Cookbook entries', function() {
var rootdir = 'cookbook/'; var rootdir = 'cookbook/';
// Recurse through cookbook directory // Recurse through cookbook directory

Loading…
Cancel
Save