From ff752e56fbc22c96229281adea984d98f43a89fa Mon Sep 17 00:00:00 2001 From: Jos van den Oever Date: Tue, 2 Nov 2010 22:22:31 +0100 Subject: [PATCH] Add more documentation and generate documentation from the Makefile. --- webodf/Makefile | 34 ++++++++++++++++++++++++++++------ webodf/lib/core/Cursor.js | 21 ++++++++++++++++----- webodf/lib/core/UnitTester.js | 10 +++++----- webodf/lib/packages.js | 6 ++++++ 4 files changed, 55 insertions(+), 16 deletions(-) diff --git a/webodf/Makefile b/webodf/Makefile index 4697ef84..0b1a6b8e 100644 --- a/webodf/Makefile +++ b/webodf/Makefile @@ -1,13 +1,35 @@ +# This makefile performs a number of tasks: +# * run unit tests in +# - node.js +# - rhino +# * compile javascript into a single file with only whitespace cleaned up and +# run unit tests in node.js and rhino with that file simplecompiled.js +# * compile javascript into a single file while optimizing. This resulting file, +# compiled.js is not used anywhere but the compilation step will perform nice +# checks on the source code. +# * instrument the unit tests for determining unit test coverage. +# * generated documentation with jsdoc + COMPILERJAR=/tmp/compiler.jar RHINOJAR=/usr/share/java/rhino.jar NODE=/tmp/node-v0.2.4/node -JSFILES := $(wildcard lib/*.js lib/*/*.js lib/*/*/*.js tests/*/*.js tests/*/*/*.js tests/*.js) -CMD := $(foreach JSFILE,$(JSFILES), --js $(JSFILE)) +JSCOVERAGE=/tmp/jscoverage-0.5.1/jscoverage +JSDOCDIR=/tmp/jsdoc_toolkit-2.3.2/jsdoc-toolkit -all: test +LIBJSFILES := $(wildcard lib/*.js lib/*/*.js lib/*/*/*.js) +TESTJSFILES := $(wildcard tests/*/*.js tests/*/*/*.js tests/*.js) +JSFILES := $(LIBJSFILES) $(TESTJSFILES) -test: nodetest rhinotest simplecompiled.js compilednodetest compiledrhinotest -#test: nodetest rhinotest compiled.js +all: test compiled.js doc instrumented + +doc: $(LIBJSFILES) + java -jar $(JSDOCDIR)/jsrun.jar $(JSDOCDIR)/app/run.js -d=docs \ + -t=$(JSDOCDIR)/templates/jsdoc $(LIBJSFILES) + +instrumented: $(JSFILES) + $(JSCOVERAGE) . --exclude=extjs ../instrumented/ + +test: nodetest rhinotest compilednodetest compiledrhinotest nodetest: $(JSFILES) $(NODE) lib/runtime.js tests/tests.js @@ -30,7 +52,7 @@ compiled.js: $(JSFILES) externs.js java -jar $(COMPILERJAR) --define='IS_COMPILED_CODE=true' --warning_level VERBOSE --compilation_level ADVANCED_OPTIMIZATIONS --formatting PRETTY_PRINT --externs externs.js --use_only_custom_externs true $(foreach JSFILE,$(JSFILES), --js $(JSFILE)) > compiled.js clean: - $(RM) compiled.js simplecompiled.js + $(RM) -rf compiled.js simplecompiled.js docs instrumented # make sure targets are deleted if a build exits with a non-zero status code .DELETE_ON_ERROR: diff --git a/webodf/lib/core/Cursor.js b/webodf/lib/core/Cursor.js index 135e95de..28dac6f9 100644 --- a/webodf/lib/core/Cursor.js +++ b/webodf/lib/core/Cursor.js @@ -1,5 +1,6 @@ /*global core*/ /** + * @class * A cursor is a dom node that visually represents a cursor in a DOM tree. * It should stay synchronized with the selection in the document. When * there is only one collapsed selection range, a cursor should be shown at @@ -18,9 +19,10 @@ * * Even when the selection allows for a cursor, it might be desireable to hide * the cursor by not letting it be part of the DOM. - **/ -/** + * * @constructor + * @param {Selection} selection The selection to which the cursor corresponds + * @param {Document} document The document in which the cursor is placed */ core.Cursor = function Cursor(selection, document) { "use strict"; @@ -148,24 +150,33 @@ core.Cursor = function Cursor(selection, document) { putCursorIntoContainer(container, offset); } } + /** + * Obtain the node representing the cursor. + * @return {Element} + */ this.getNode = function () { return cursorNode; }; /** * Synchronize the cursor with the current selection. - **/ + * If there is a single collapsed selection range, the cursor will be placed + * there. If not, the cursor will be removed from the document tree. + * @return {undefined} + */ this.updateToSelection = function () { var range; removeCursor(); -runtime.log("HMM " + selection.rangeCount); if (selection.rangeCount === 1) { -runtime.log("HMM "); range = selection.getRangeAt(0); if (range.collapsed) { putCursor(range.startContainer, range.startOffset); } } }; + /** + * Remove the cursor from the document tree. + * @return {undefined} + */ this.remove = function () { removeCursor(); }; diff --git a/webodf/lib/core/UnitTester.js b/webodf/lib/core/UnitTester.js index 7da815d9..2c099660 100644 --- a/webodf/lib/core/UnitTester.js +++ b/webodf/lib/core/UnitTester.js @@ -3,7 +3,7 @@ /** * @interface */ -core.UnitTest = function () {}; +core.UnitTest = function UnitTest() {}; /** * @return {undefined} */ @@ -100,8 +100,8 @@ core.UnitTestRunner = function UnitTestRunner() { } } /** - * @param {Object} t - * @param {string} a + * @param {Object} t context in which values to be tested are placed + * @param {string} a the value to be checked * @return {undefined} */ function shouldBeNonNull(t, a) { @@ -121,8 +121,8 @@ core.UnitTestRunner = function UnitTestRunner() { } } /** - * @param {Object} t - * @param {string} a + * @param {Object} t context in which values to be tested are placed + * @param {string} a the value to be checked * @return {undefined} */ function shouldBeNull(t, a) { diff --git a/webodf/lib/packages.js b/webodf/lib/packages.js index ab94b277..d400d7da 100644 --- a/webodf/lib/packages.js +++ b/webodf/lib/packages.js @@ -1,2 +1,8 @@ +/** + * The core package. + */ var core = {}; +/** + * The gui package. + */ var gui = {};