@samitouri / QOS-React-2 / commits / 9585c407e2

added function that write to the output html file

Connor McSheffrey committed Oct 10, 2013 at 20:34 UTC 9585c407e27c795dfb5748c095d3e94927b68bf6
1 file changed +18 -4
docs/Gruntfile.js
+18 -4
@@ -5,17 +5,30 @@ module.exports = function(grunt) {
5 pkg: grunt.file.readJSON('../package.json')
6 });
7
8 - function writeToLiveSampleJS(matchedJS) {
8 + /**
9 + * Write React component to js file
10 + * @param {String} liveEditJS
11 + * @param {String} componentName
12 + */
13 + function writeToLiveSampleJS(liveEditJS, componentName) {
14
15 grunt.file.write('js/cookbook/' + componentName + '.js', liveEditJS);
16 }
17
18 + /**
19 + * Update HTML file to include an ID and script src link
20 + */
21 + function writeToHTML() {
22 + grunt.file.write('_site/cookbook' + componentName + '.html', liveEditJS);
23 + }
24 +
25 function readFromCookbookEntry(abspath, rootdir, subdir, filename) {
26
27 var markdown = grunt.file.read(abspath),
28 + codeSample = /```[\S]+\s*[\s\S]*?```/g,
29
30 // read markdown file for code sample
18 - matchedJS = markdown.match(/`{3}[\s\S]*?`{3}/g),
31 + matchedJS = markdown.match(codeSample),
32 trimmedJS,
33 componentName,
34 componentNameCamelCase,
@@ -44,11 +57,12 @@ module.exports = function(grunt) {
57
58 // Add code sample to live edit
59 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 );'
47 -
60 + console.log(componentName);
61 +
62 writeToLiveSampleJS(liveEditJS, componentName);
63 }
64
51 - grunt.registerTask('makeLiveSamples', 'Out live edit JS file for code samples in React Cookbook entries', function() {
65 + grunt.registerTask('makeLiveSamples', 'Create live edit JS file for code samples in React Cookbook entries', function() {
66 var rootdir = 'cookbook/';
67
68 // Recurse through cookbook directory