cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject docs commit: CB-8259 Report error during generation (close #257)
Date Sun, 18 Jan 2015 01:01:31 GMT
Repository: cordova-docs
Updated Branches:
  refs/heads/master aa653be21 -> f3c7010ba


CB-8259 Report error during generation (close #257)


Project: http://git-wip-us.apache.org/repos/asf/cordova-docs/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-docs/commit/f3c7010b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-docs/tree/f3c7010b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-docs/diff/f3c7010b

Branch: refs/heads/master
Commit: f3c7010ba835127ba89c836684b4f622a6e9e300
Parents: aa653be
Author: Andrey Kurdyumov <kant2002@gmail.com>
Authored: Wed Jan 7 16:41:36 2015 +0600
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Sat Jan 17 20:00:54 2015 -0500

----------------------------------------------------------------------
 lib/cordova/post/addtitle.js           |  2 --
 lib/cordova/post/navigationmenu.js     |  2 --
 lib/cordova/post/prettify.js           |  2 --
 lib/cordova/post/stepprocessor.js      | 50 ++++++++++++++++++++++++++---
 lib/cordova/post/tableofcontents.js    |  2 +-
 lib/cordova/post/versionmenu.js        | 17 ++++++----
 lib/cordova/pre/filemerger.js          |  8 +++--
 lib/docs_generator.js                  | 10 +++++-
 spec/cordova/add_title_spec.js         | 11 ++++---
 spec/cordova/prettify_spec.js          |  8 ++---
 spec/cordova/table_of_contents_spec.js | 26 +++++++++------
 11 files changed, 97 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/f3c7010b/lib/cordova/post/addtitle.js
----------------------------------------------------------------------
diff --git a/lib/cordova/post/addtitle.js b/lib/cordova/post/addtitle.js
index 4e6c696..5920f92 100644
--- a/lib/cordova/post/addtitle.js
+++ b/lib/cordova/post/addtitle.js
@@ -17,9 +17,7 @@
        under the License.
 */
 /*jslint node: true */
-var fs = require("fs-extra");
 var path = require("path");
-var cheerio = require('cheerio');
 
 /**
 * Preprocessor which updates top stripe with header or the page.

http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/f3c7010b/lib/cordova/post/navigationmenu.js
----------------------------------------------------------------------
diff --git a/lib/cordova/post/navigationmenu.js b/lib/cordova/post/navigationmenu.js
index c671d00..869d223 100644
--- a/lib/cordova/post/navigationmenu.js
+++ b/lib/cordova/post/navigationmenu.js
@@ -90,8 +90,6 @@ var NavigationMenu = (function () {
             this.insertTitle(section.title, $);
             this.insertLinks(section.links, $);
         }
-
-        return $.html();
     };
 
     NavigationMenu.prototype.insertTitle = function (title, $) {

http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/f3c7010b/lib/cordova/post/prettify.js
----------------------------------------------------------------------
diff --git a/lib/cordova/post/prettify.js b/lib/cordova/post/prettify.js
index 94744ee..66975a7 100644
--- a/lib/cordova/post/prettify.js
+++ b/lib/cordova/post/prettify.js
@@ -17,9 +17,7 @@
        under the License.
 */
 /*jslint node: true */
-var fs = require("fs-extra");
 var path = require("path");
-var cheerio = require('cheerio');
 
 /**
 * Preprocessor which updates top stripe with header or the page.

http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/f3c7010b/lib/cordova/post/stepprocessor.js
----------------------------------------------------------------------
diff --git a/lib/cordova/post/stepprocessor.js b/lib/cordova/post/stepprocessor.js
index 8fcc26f..14dd28a 100644
--- a/lib/cordova/post/stepprocessor.js
+++ b/lib/cordova/post/stepprocessor.js
@@ -38,8 +38,16 @@ var StepProcessor = (function () {
     * @param options Options for the generation process.
     */
     function StepProcessor(options) {
+        var self = this;
         this.options = options || { verbose: 0, timing: -1 };
         this.stage = "Step 1";
+        this.processors = [AddTitle,  TableOfContents, VersionMenu, NavigationMenu, Prettify,
NoIndex].map(function (StepConstructor) {
+            var stepObject;
+            self.captureExecutionTime(" Substep init " + StepConstructor, 2, function ()
{
+                stepObject = new StepConstructor(self.options);
+            });
+            return stepObject;
+        });
     }
 
     StepProcessor.prototype.run = function (file) {
@@ -51,14 +59,46 @@ var StepProcessor = (function () {
         }
 
         $ = cheerio.load(fs.readFileSync(file));
-        steps = [AddTitle,  TableOfContents, VersionMenu, NavigationMenu, Prettify, NoIndex];
-        steps.forEach(function (StepConstructor) {
-            var stepObject = new StepConstructor(self.options);
-            stepObject.run(file, $);
+        this.processors.forEach(function (stepObject) {
+            self.captureExecutionTime(" Substep run: " + stepObject.stage, 2, function ()
{
+                stepObject.run(file, $);
+            });
         });
-        // Do actual work here
+        // Save all content to file
         fs.writeFileSync(file, $.html());
     };
+    
+    StepProcessor.prototype.captureExecutionTime = function (step_name, level, callback)
{
+        var startDate,
+            finishDate,
+            timingLevel = -1,
+            secondsPassed;
+        if (this.options.timing) {
+            if (this.options.timing === true) {
+                timingLevel = 0;
+            } else {
+                timingLevel = this.options.timing;
+            }
+        }
+        
+        if (timingLevel >= level) {
+            startDate = new Date();
+            if (this.options.verbose > 0) {
+                console.log(startDate, "Start " + step_name);
+            }
+        }
+        
+        callback.apply(this);
+        if (timingLevel >= level) {
+            finishDate = new Date();
+            if (this.options.verbose > 0) {
+                console.log(finishDate, "Finish " + step_name);
+            }
+            
+            secondsPassed = (finishDate.valueOf() - startDate.valueOf()) / 1000;
+            console.log(step_name + ". Total time: ", secondsPassed);
+        }
+    };
 
     return StepProcessor;
 }());

http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/f3c7010b/lib/cordova/post/tableofcontents.js
----------------------------------------------------------------------
diff --git a/lib/cordova/post/tableofcontents.js b/lib/cordova/post/tableofcontents.js
index 6deaea3..565e42b 100644
--- a/lib/cordova/post/tableofcontents.js
+++ b/lib/cordova/post/tableofcontents.js
@@ -100,7 +100,7 @@ var TableOfContents = (function () {
         // Add select menu to the subheader
         select = cheerio("<select></select>");
         option_set.forEach(function (optionGroup) {
-            select.append(optionGroup.clone());
+            select.append(optionGroup);
         });
         subheader = doc("#subheader > small").first();
         if (subheader.length === 0) {

http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/f3c7010b/lib/cordova/post/versionmenu.js
----------------------------------------------------------------------
diff --git a/lib/cordova/post/versionmenu.js b/lib/cordova/post/versionmenu.js
index eb595e0..84bda9b 100644
--- a/lib/cordova/post/versionmenu.js
+++ b/lib/cordova/post/versionmenu.js
@@ -26,9 +26,8 @@ var cheerio = require('cheerio');
 */
 var VersionMenu = (function () {
     'use strict';
-    var languages = [],
-        versions = [];
-
+    var languages = null,
+        versions = null;
 
     /**
     * Creates a new instance of FileMerger
@@ -37,9 +36,13 @@ var VersionMenu = (function () {
     function VersionMenu(options) {
         this.options = options || { verbose: 0 };
         this.stage = "Populate version menu";
-        languages = [];
-        versions = [];
-        this.buildVersionsData();
+        if (languages === null) {
+            languages = [];
+            versions = [];
+            this.buildVersionsData();
+        }
+        
+        this.generatedMenu = this.generateMenu();
     }
 
     VersionMenu.prototype.run = function (file, $) {
@@ -54,7 +57,7 @@ var VersionMenu = (function () {
         var element;
 
         element = $('#header small select').first();
-        this.generateMenu().forEach(function (optionGroup) {
+        this.generatedMenu.forEach(function (optionGroup) {
             element.append(optionGroup).append("\n");
         });
     };

http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/f3c7010b/lib/cordova/pre/filemerger.js
----------------------------------------------------------------------
diff --git a/lib/cordova/pre/filemerger.js b/lib/cordova/pre/filemerger.js
index 5f8debf..e55da60 100644
--- a/lib/cordova/pre/filemerger.js
+++ b/lib/cordova/pre/filemerger.js
@@ -73,8 +73,12 @@ var FileMerger = (function () {
             } else {
                 filepath = path.join(FileHelpers.getTmpDirectory(), 'docs', filepath);
                 fs.appendFileSync(file, "\n\n---\n");
-                fs.appendFileSync(file, fs.readFileSync(filepath, "utf-8").trim());
-                fs.removeSync(filepath);
+                if (!fs.existsSync(filepath)) {
+                    console.log("File " + filepath + " is missing and thus don't merged with
" + file);
+                } else {
+                    fs.appendFileSync(file, fs.readFileSync(filepath, "utf-8").trim());
+                    fs.removeSync(filepath);
+                }
             }
         }
     };

http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/f3c7010b/lib/docs_generator.js
----------------------------------------------------------------------
diff --git a/lib/docs_generator.js b/lib/docs_generator.js
index f756763..1250e2b 100644
--- a/lib/docs_generator.js
+++ b/lib/docs_generator.js
@@ -118,7 +118,15 @@ var DocsGenerator = (function () {
                     self.options = options;
                     console.log(" => Generating the Cordova Documentation for " + version_dir
+ "-" + language_dir + "...");
                     self.captureExecutionTime("Generate docs for " + version_dir + "-" +
language_dir, 0, function () {
-                        self.process(input_path, output_path, options);
+                        try {
+                            self.process(input_path, output_path, options);
+                        } catch (e) {
+                            console.log("=================================================");
+                            console.log("ERROR: Generating the Cordova Documentation for
" + version_dir + "-" + language_dir + " failed.");
+                            console.log("Stack trace:");
+                            console.log(e.stack);
+                            console.log("=================================================");
+                        }
                     });
                     self.options = {
                         verbose: verbose_mode,

http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/f3c7010b/spec/cordova/add_title_spec.js
----------------------------------------------------------------------
diff --git a/spec/cordova/add_title_spec.js b/spec/cordova/add_title_spec.js
index ce070d1..9219d01 100644
--- a/spec/cordova/add_title_spec.js
+++ b/spec/cordova/add_title_spec.js
@@ -49,20 +49,21 @@
 
         it('should set the title', function () {
             var testing_file = files.normal,
-                result = sut.run(testing_file),
-                dom;
+                dom = cheerio.load(fs.readFileSync(testing_file)),
+                result = sut.run(testing_file, dom);
             assert.strictEqual('Accelerometer', result);
-            dom = cheerio.load(fs.readFileSync(testing_file));
             assert.strictEqual('Accelerometer', dom('#subheader > h1').first().html());
         });
 
         it('should skip files with no source title', function () {
-            var result = sut.run(files.no_source);
+            var dom = cheerio.load(fs.readFileSync(files.no_source)),
+                result = sut.run(files.no_source, dom);
             assert.strictEqual(null, result);
         });
 
         it('should skip files with no target title', function () {
-            var result = sut.run(files.no_target);
+            var dom = cheerio.load(fs.readFileSync(files.no_target)),
+                result = sut.run(files.no_target, dom);
             assert.strictEqual(null, result);
         });
     });

http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/f3c7010b/spec/cordova/prettify_spec.js
----------------------------------------------------------------------
diff --git a/spec/cordova/prettify_spec.js b/spec/cordova/prettify_spec.js
index f699f9b..25186f0 100644
--- a/spec/cordova/prettify_spec.js
+++ b/spec/cordova/prettify_spec.js
@@ -46,17 +46,17 @@
         });
 
         it('should find some code blocks', function () {
-            var code_tags = sut.run(files.normal);
+            var dom = cheerio.load(fs.readFileSync(files.normal)),
+                code_tags = sut.run(files.normal, dom);
             assert.ok(code_tags.length > 0);
         });
 
         it('should add the prettyprint class to each code block', function () {
             var testing_file = files.normal,
-                dom,
+                dom = cheerio.load(fs.readFileSync(files.normal)),
                 initial_title,
                 new_title;
-            sut.run(files.normal);
-            dom = cheerio.load(fs.readFileSync(files.normal));
+            sut.run(files.normal, dom);
             assert.ok(dom('#content pre.prettyprint').length > 0);
         });
     });

http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/f3c7010b/spec/cordova/table_of_contents_spec.js
----------------------------------------------------------------------
diff --git a/spec/cordova/table_of_contents_spec.js b/spec/cordova/table_of_contents_spec.js
index 29fe2f7..f537b83 100644
--- a/spec/cordova/table_of_contents_spec.js
+++ b/spec/cordova/table_of_contents_spec.js
@@ -49,12 +49,14 @@
         });
 
         it('should find the table of content values', function () {
-            var result = sut.run(files.normal);
+            var dom = cheerio.load(fs.readFileSync(files.normal)),
+                result = sut.run(files.normal, dom);
             assert.strictEqual(32, result.length);
         });
 
         it('should find all <h1> elements', function () {
-            var result = sut.run(files.normal),
+            var dom = cheerio.load(fs.readFileSync(files.normal)),
+                result = sut.run(files.normal, dom),
                 headers = [];
             
             result.forEach(function (header, index) {
@@ -67,7 +69,8 @@
         });
 
         it('should find all <h2> elements', function () {
-            var result = sut.run(files.normal),
+            var dom = cheerio.load(fs.readFileSync(files.normal)),
+                result = sut.run(files.normal, dom),
                 headers = [];
             
             result.forEach(function (header, index) {
@@ -81,9 +84,10 @@
         });
 
         it('should ignore whitespace in the target name', function () {
-            var result = sut.run(files.normal),
+            var dom = cheerio.load(fs.readFileSync(files.normal)),
+                result = sut.run(files.normal, dom),
                 names = [],
-                doc = cheerio.load(fs.readFileSync(files.normal));
+                doc = dom;
             
             //result = result.reverse();
             //console.log(result[0]);
@@ -99,19 +103,21 @@
         });
 
         it('should create a HTML select element', function () {
-            var result = sut.run(files.normal),
-                doc = cheerio.load(files.normal);
+            var dom = cheerio.load(fs.readFileSync(files.normal)),
+                result = sut.run(files.normal, dom);
             
-            assert.ok(('#subheader > small > select').length > 0);
+            assert.ok(dom('#subheader > small > select').length > 0);
         });
 
         it('should skip files with no source title', function () {
-            var result = sut.run(files.no_source);
+            var dom = cheerio.load(fs.readFileSync(files.no_source)),
+                result = sut.run(files.no_source, dom);
             assert.strictEqual(null, result);
         });
 
         it('should skip files with no target title', function () {
-            var result = sut.run(files.no_target);
+            var dom = cheerio.load(fs.readFileSync(files.no_target)),
+                result = sut.run(files.no_target, dom);
             assert.ok(null === result, "Find something when should not");
         });
     });


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message