[rkward-cvs] SF.net SVN: rkward:[3877] trunk/rkward/packages/rkwarddev

m-eik at users.sourceforge.net m-eik at users.sourceforge.net
Mon Oct 3 19:31:01 UTC 2011


Revision: 3877
          http://rkward.svn.sourceforge.net/rkward/?rev=3877&view=rev
Author:   m-eik
Date:     2011-10-03 19:31:00 +0000 (Mon, 03 Oct 2011)
Log Message:
-----------
rkwarddev: JS improvements

Modified Paths:
--------------
    trunk/rkward/packages/rkwarddev/ChangeLog
    trunk/rkward/packages/rkwarddev/DESCRIPTION
    trunk/rkward/packages/rkwarddev/NAMESPACE
    trunk/rkward/packages/rkwarddev/R/echo.R
    trunk/rkward/packages/rkwarddev/R/id.R
    trunk/rkward/packages/rkwarddev/R/ite.R
    trunk/rkward/packages/rkwarddev/R/rk-internal.R
    trunk/rkward/packages/rkwarddev/R/rk.JS.array.R
    trunk/rkward/packages/rkwarddev/R/rk.JS.doc.R
    trunk/rkward/packages/rkwarddev/R/rk.JS.ite-class.R
    trunk/rkward/packages/rkwarddev/R/rk.paste.JS.R
    trunk/rkward/packages/rkwarddev/man/echo.Rd
    trunk/rkward/packages/rkwarddev/man/id.Rd
    trunk/rkward/packages/rkwarddev/man/ite.Rd
    trunk/rkward/packages/rkwarddev/man/rk.JS.array.Rd
    trunk/rkward/packages/rkwarddev/man/rk.JS.doc.Rd
    trunk/rkward/packages/rkwarddev/man/rk.paste.JS.Rd

Added Paths:
-----------
    trunk/rkward/packages/rkwarddev/R/rk.JS.arr-class.R
    trunk/rkward/packages/rkwarddev/R/rk.JS.vars.R
    trunk/rkward/packages/rkwarddev/R/show-methods.R
    trunk/rkward/packages/rkwarddev/man/rk.JS.vars.Rd

Removed Paths:
-------------
    trunk/rkward/packages/rkwarddev/R/show.rk.JS.ite.R

Modified: trunk/rkward/packages/rkwarddev/ChangeLog
===================================================================
--- trunk/rkward/packages/rkwarddev/ChangeLog	2011-10-03 16:47:37 UTC (rev 3876)
+++ trunk/rkward/packages/rkwarddev/ChangeLog	2011-10-03 19:31:00 UTC (rev 3877)
@@ -1,9 +1,10 @@
 ChangeLog for package rkwarddev
 
-## 0.02-4 (2011-10-02)
+## 0.02-4 (2011-10-03)
   - some experimental JavaScript generator tools added, might very well be changed soon again:
-    - added functions echo(), id(), ite() and rk.paste.JS() to help generate JavaScript code
-    - added class rk.JS.ite and show method for it
+    - added functions rk.JS.vars(), echo(), id(), ite() and rk.paste.JS() to help generate JavaScript code
+    - added classes rk.JS.ite, rk.JS.arr and show methods for them
+    - function rk.JS.array() now returns an object of class rk.JS.arr (use rk.paste.JS() on that)
 
 ## 0.02-3 (2011-09-30)
   - added functions rk.XML.attribute(), rk.XML.component(), rk.XML.components(), rk.XML.context(),

Modified: trunk/rkward/packages/rkwarddev/DESCRIPTION
===================================================================
--- trunk/rkward/packages/rkwarddev/DESCRIPTION	2011-10-03 16:47:37 UTC (rev 3876)
+++ trunk/rkward/packages/rkwarddev/DESCRIPTION	2011-10-03 19:31:00 UTC (rev 3877)
@@ -24,8 +24,10 @@
     'rk.build.plugin.R'
     'rk-internal.R'
     'rk.JS.array.R'
+    'rk.JS.arr-class.R'
     'rk.JS.doc.R'
     'rk.JS.scan.R'
+    'rk.JS.vars.R'
     'rk.paste.JS.R'
     'rk.plugin.skeleton.R'
     'rk.rkh.doc.R'
@@ -76,4 +78,4 @@
     'rk.XML.varslot.R'
     'rk.XML.vars.R'
     'rk.XML.wizard.R'
-    'show.rk.JS.ite.R'
+    'show-methods.R'

Modified: trunk/rkward/packages/rkwarddev/NAMESPACE
===================================================================
--- trunk/rkward/packages/rkwarddev/NAMESPACE	2011-10-03 16:47:37 UTC (rev 3876)
+++ trunk/rkward/packages/rkwarddev/NAMESPACE	2011-10-03 19:31:00 UTC (rev 3877)
@@ -1,3 +1,4 @@
+exportClasses(rk.JS.arr)
 exportClasses(rk.JS.ite)
 export(echo)
 export(id)
@@ -7,6 +8,7 @@
 export(rk.JS.array)
 export(rk.JS.doc)
 export(rk.JS.scan)
+export(rk.JS.vars)
 export(rk.paste.JS)
 export(rk.plugin.skeleton)
 export(rk.rkh.doc)

Modified: trunk/rkward/packages/rkwarddev/R/echo.R
===================================================================
--- trunk/rkward/packages/rkwarddev/R/echo.R	2011-10-03 16:47:37 UTC (rev 3876)
+++ trunk/rkward/packages/rkwarddev/R/echo.R	2011-10-03 19:31:00 UTC (rev 3877)
@@ -8,7 +8,14 @@
 #'		simply separated by comma.
 #' @param newline Character string, can be set to e.g. \code{"\n"} to force a newline after the call.
 #' @return A character string.
+#' @seealso \code{\link[rkwarddev:rk.JS.vars]{rk.JS.vars}},
+#'		\code{\link[rkwarddev:rk.JS.array]{rk.JS.array}},
+#'		\code{\link[rkwarddev:ite]{ite}},
+#'		\code{\link[rkwarddev:id]{id}}
 #' @export
+#' @examples
+#' cbox1 <- rk.XML.cbox(label="foo", value="foo1", id.name="CheckboxFoo.ID")
+#' echo("bar <- \"", cbox1, "\"")
 
 echo <- function(..., newline=""){
 	ID.content <- id(..., quote=TRUE,  collapse=" + ")

Modified: trunk/rkward/packages/rkwarddev/R/id.R
===================================================================
--- trunk/rkward/packages/rkwarddev/R/id.R	2011-10-03 16:47:37 UTC (rev 3876)
+++ trunk/rkward/packages/rkwarddev/R/id.R	2011-10-03 19:31:00 UTC (rev 3877)
@@ -12,6 +12,13 @@
 #' @param collapse Character string, defining if and how the individual elements should be glued together.
 #' @return A character string.
 #' @export
+#' @seealso \code{\link[rkwarddev:rk.JS.vars]{rk.JS.vars}},
+#'		\code{\link[rkwarddev:rk.JS.array]{rk.JS.array}},
+#'		\code{\link[rkwarddev:echo]{echo}},
+#' @examples
+#' # an example checkbox XML node
+#' cbox1 <- rk.XML.cbox(label="foo", value="foo1", id.name="CheckboxFoo.ID")
+#' id("The ID is: ", cbox1, "!", quote=TRUE, collapse=" + ")
 
 id <- function(..., quote=FALSE, collapse=""){
 	full.content <- list(...)

Modified: trunk/rkward/packages/rkwarddev/R/ite.R
===================================================================
--- trunk/rkward/packages/rkwarddev/R/ite.R	2011-10-03 16:47:37 UTC (rev 3876)
+++ trunk/rkward/packages/rkwarddev/R/ite.R	2011-10-03 19:31:00 UTC (rev 3877)
@@ -5,13 +5,34 @@
 #' @param elsejs A character string, the code to be executed in case the \code{if()} statement is not true.
 #' @return An object of class \code{rk.JS.ite}
 #' @include rk.JS.ite-class.R
+#' @seealso \code{\link[rkwarddev:rk.paste.JS]{rk.paste.JS}},
+#'		\code{\link[rkwarddev:rk.JS.vars]{rk.JS.vars}},
+#'		\code{\link[rkwarddev:rk.JS.array]{rk.JS.array}},
+#'		\code{\link[rkwarddev:echo]{echo}},
+#'		\code{\link[rkwarddev:id]{id}}
 #' @export
+#' @examples
+#' # first create an example checkbox XML node
+#' cbox1 <- rk.XML.cbox(label="foo", value="foo1", id.name="CheckboxFoo.ID")
+#' # now some JavaScript generation
+#' ite(id(cbox1), echo("bar <- \"", cbox1, "\""), echo("bar <- NULL"))
 
 ite <- function(ifjs, thenjs, elsejs=NULL){
+	#check for recursion
+	if(inherits(elsejs, "rk.JS.ite")){
+		elifJS <- list(elsejs)
+		elsejs <- ""
+	} else {
+		elifJS <- list()
+		if(is.null(elsejs)){
+			elsejs <- ""
+		} else {}
+	}
 	result <- new("rk.JS.ite",
 		ifJS=ifjs,
 		thenJS=thenjs,
-		elseJS=elsejs
+		elseJS=elsejs,
+		elifJS=elifJS
 	)
 	return(result)
 }

Modified: trunk/rkward/packages/rkwarddev/R/rk-internal.R
===================================================================
--- trunk/rkward/packages/rkwarddev/R/rk-internal.R	2011-10-03 16:47:37 UTC (rev 3876)
+++ trunk/rkward/packages/rkwarddev/R/rk-internal.R	2011-10-03 19:31:00 UTC (rev 3877)
@@ -1,5 +1,6 @@
 # internal functions for the rk.* functions
 
+## function auto.ids()
 auto.ids <- function(identifiers, prefix=NULL, suffix=NULL, chars=8){
 	identifiers <- gsub("[[:space:]]*[^[:alnum:]]*", "", identifiers)
 	id.names <- ifelse(nchar(identifiers) > 8, abbreviate(identifiers, minlength=chars), identifiers)
@@ -9,15 +10,16 @@
 	} else {}
 	ids <- paste(prefix, id.names, suffix, sep="")
 	return(ids)
-}
+} ## end function auto.ids()
 
+## function child.list()
 # convenience function to let single children be provided without list()
 child.list <- function(children){
 	if(inherits(children, "XiMpLe.node")){
 		children <- list(children)
 	} else {}
 	return(children)
-}
+} ## end function child.list()
 
 ## function trim()
 # cuts off space at start and end of a character string
@@ -196,8 +198,7 @@
 	} else {}
 
 	return(node.ID)
-}
-## end function check.ID()
+} ## end function check.ID()
 
 ## function prop.validity()
 # checks if a property is valid for an XML node, if source is XiMpLe.node
@@ -267,8 +268,7 @@
 			return(property)
 		}
 	}
-}
-## end function prop.validity()
+} ## end function prop.validity()
 
 ## function check.type()
 check.type <- function(value, type, var.name, warn.only=TRUE){
@@ -282,8 +282,7 @@
 			stop(simpleError(msg.text))
 		}
 	}
-}
-## end function check.type()
+} ## end function check.type()
 
 ## function clean.name()
 clean.name <- function(name, message=TRUE){
@@ -295,5 +294,69 @@
 		} else {}
 	} else {}
 	return(name)
-}
-## end function clean.name()
+} ## end function clean.name()
+
+## function paste.JS.ite()
+paste.JS.ite <- function(object, level=1, indent.by="\t", recurse=FALSE){
+	stopifnot(inherits(object, "rk.JS.ite"))
+	# check indentation
+	main.indent <- indent(level, by=indent.by)
+	scnd.indent <- indent(level+1, by=indent.by)
+
+	# if this is not a single "if" but an "else if", do not indent
+	if(isTRUE(recurse)){
+		ifJS <- paste("if(", object at ifJS, ") {\n", sep="")
+	} else {
+		ifJS <- paste(main.indent, "if(", object at ifJS, ") {\n", sep="")
+	}
+	thenJS <- paste(scnd.indent, object at thenJS, "\n", main.indent, "}", sep="")
+	if(nchar(object at elseJS) > 0) {
+		elseJS <- paste(" else {\n", scnd.indent, object at elseJS, "\n", main.indent, "}", sep="")
+	} else {
+		# if there is another rk.JS.ite object, call with recursion
+		if(length(object at elifJS) == 1){
+			if(inherits(object at elifJS[[1]], "rk.JS.ite")){
+				elseJS <- paste(" else ", paste.JS.ite(object at elifJS[[1]], level=level, indent.by=indent.by, recurse=TRUE), sep="")
+			} else {
+				elseJS <- " else {}"
+			}
+		} else {
+			# close for sure with an empty "else"
+			elseJS <- " else {}"
+		}
+	}
+	result <- paste(ifJS, thenJS, elseJS, collapse="", sep="")
+
+	return(result)
+} ## end function paste.JS.ite()
+
+## function paste.JS.array()
+paste.JS.array <- function(object, level=2, indent.by="\t", funct=NULL){
+	stopifnot(inherits(object, "rk.JS.arr"))
+	# check indentation
+	main.indent <- indent(level, by=indent.by)
+	scnd.indent <- indent(level+1, by=indent.by)
+
+	arr.name  <- object at arr.name
+	opt.name  <- object at opt.name
+	variables <- object at variables
+	option    <- object at option
+	if(is.null(funct)){
+		funct <- object at funct
+	} else {}
+
+	JS.array <- paste(
+		main.indent, "var ", arr.name, " = new Array();\n",
+		main.indent, arr.name, ".push(",
+		paste(variables, collapse=", "), ");\n",
+		main.indent, arr.name, " = ", arr.name, ".filter(String);\n",
+		main.indent, "if(", arr.name, ".length > 0) {\n",
+		scnd.indent, "var ", opt.name, " = \", ", option,"=",
+		funct, "(\" + ", arr.name, ".join(\", \") + \")\";\n",
+		main.indent, "} else {\n",
+		scnd.indent, "var ", opt.name, " = \"\";\n",
+		main.indent, "}\n",
+		sep="")
+
+	return(JS.array)
+} ## end function paste.JS.array()

Added: trunk/rkward/packages/rkwarddev/R/rk.JS.arr-class.R
===================================================================
--- trunk/rkward/packages/rkwarddev/R/rk.JS.arr-class.R	                        (rev 0)
+++ trunk/rkward/packages/rkwarddev/R/rk.JS.arr-class.R	2011-10-03 19:31:00 UTC (rev 3877)
@@ -0,0 +1,23 @@
+#' @export
+
+# this simple class is for JavaScript generation,
+# produced by rk.JS.array()
+
+setClass("rk.JS.arr",
+	representation=representation(
+		arr.name="character",
+		opt.name="character",
+		IDs="vector",
+		variables="vector",
+		funct="character",
+		option="character"
+	),
+	prototype(
+		arr.name=character(),
+		opt.name=character(),
+		IDs=c(),
+		variables=c(),
+		funct="c",
+		option=character()
+	)
+)

Modified: trunk/rkward/packages/rkwarddev/R/rk.JS.array.R
===================================================================
--- trunk/rkward/packages/rkwarddev/R/rk.JS.array.R	2011-10-03 16:47:37 UTC (rev 3876)
+++ trunk/rkward/packages/rkwarddev/R/rk.JS.array.R	2011-10-03 19:31:00 UTC (rev 3877)
@@ -4,54 +4,43 @@
 #' this function can help with that task. All relevant variables will become part of an array and
 #' then joined into the desired argument type.
 #'
-#' @param option A character string, naming the option of, e.g., an R function which should be
+#' @param option A character string, naming, e.g., an option of an R function which should be
 #'		constructed from several variables.
-#' @param variables A character vector, the names of the variables to combine to a vector or list.
-#' @param list Logical, if \code{TRUE} the option will be constructed by \code{list()},
-#'		otherwise by \code{c()}.
-#' @param def.vars Logical, if \code{TRUE} the provided variables will also be defined.
-#' @param var.prefix A character string. If \code{def.vars=TRUE}, this string will be used as a prefix
-#'		for the JS variable names.
-#' @param indent.by A character string defining how indentation should be done.
-#' @return A character string.
+#' @param variables A list with either character strings (the names of the variables to combine to a vector or list),
+#'		of objects of class \code{XiMpLe.node} with plugin XML nodes (whose ID will be extracted and used).
+#' @param funct Character string, name of the R function to be called to combine the options, e.g. "list" for \code{list()},
+#'		or "c" for \code{c()}.
+#' @param var.prefix A character string. sets a global string to be used as a prefix for the JS variable names.
+#' @return An object of class \code{rk.JS.arr}.
 #' @export
+#' @seealso \code{\link[rkwarddev:rk.paste.JS]{rk.paste.JS}},
+#'		\code{\link[rkwarddev:rk.JS.vars]{rk.JS.vars}},
+#'		\code{\link[rkwarddev:echo]{echo}},
+#'		\code{\link[rkwarddev:id]{id}}
 #' @examples
-#' cat(rk.JS.array("my.option", variables=c("frst.var", "scnd.var")))
+#' # create three checkboxes for independent options
+#' checkA <- rk.XML.cbox(label="Run Test A", value="A")
+#' checkB <- rk.XML.cbox(label="Run Test B", value="B")
+#' checkC <- rk.XML.cbox(label="Run Test C", value="C")
+#' # combine them into one list of options via JavaScript
+#' rk.JS.array("run.tests", variables=list(checkA, checkB, checkC), funct="list")
 
-rk.JS.array <- function(option, variables=NULL, list=FALSE, def.vars=FALSE, var.prefix=NULL, indent.by="\t"){
+rk.JS.array <- function(option, variables=list(), funct="c", var.prefix=NULL){
 	arr.name <- camelCode(c("arr", option))
 	opt.name <- camelCode(c("opt", option))
 
-	if(isTRUE(def.vars)){
-		JS.vars <- paste(unlist(sapply(child.list(variables), function(this.var){get.JS.vars(
+	JS.array <- new("rk.JS.arr",
+		arr.name=arr.name,
+		opt.name=opt.name,
+		IDs=check.ID(variables),
+		variables=unlist(sapply(child.list(variables), function(this.var){get.JS.vars(
 							JS.var=this.var,
-							XML.var=this.var,
 							JS.prefix=var.prefix,
-							indent.by=indent.by)
-					})), collapse="")
-	} else {
-		JS.vars <- ""
-	}
-
-	JS.array <- paste(
-		indent(2, by=indent.by), "var ", arr.name, " = new Array();\n",
-		indent(2, by=indent.by), arr.name, ".push(",
-		paste(unlist(sapply(child.list(variables), function(this.var){get.JS.vars(
-							JS.var=this.var,
-							JS.prefix=var.prefix,
 							names.only=TRUE)
-					})), collapse=", "), ");\n",
-		indent(2, by=indent.by), arr.name, " = ", arr.name, ".filter(String);\n",
-		indent(2, by=indent.by), "if(", arr.name, ".length > 0) {\n",
-		indent(3, by=indent.by), "var ", opt.name, " = \", ", option,"=",
-			ifelse(isTRUE(list), "list(", "c("),
-			"\" + ", arr.name, ".join(\", \") + \")\";\n",
-		indent(2, by=indent.by), "} else {\n",
-		indent(3, by=indent.by), "var ", opt.name, " = \"\";\n",
-		indent(2, by=indent.by), "}\n",
-		sep="")
+					})),
+		funct=funct,
+		option=option
+	)
 
-	results <- paste(JS.vars, JS.array, sep="\n")
-
-	return(results)
+	return(JS.array)
 }

Modified: trunk/rkward/packages/rkwarddev/R/rk.JS.doc.R
===================================================================
--- trunk/rkward/packages/rkwarddev/R/rk.JS.doc.R	2011-10-03 16:47:37 UTC (rev 3876)
+++ trunk/rkward/packages/rkwarddev/R/rk.JS.doc.R	2011-10-03 19:31:00 UTC (rev 3877)
@@ -14,6 +14,12 @@
 #'		pasted as-is, after \code{results.header} has been evaluated.
 #' @param indent.by A character string defining how indentation should be done.
 #' @return A character string.
+#' @seealso \code{\link[rkwarddev:rk.paste.JS]{rk.paste.JS}},
+#'		\code{\link[rkwarddev:rk.JS.vars]{rk.JS.vars}},
+#'		\code{\link[rkwarddev:rk.JS.array]{rk.JS.array}},
+#'		\code{\link[rkwarddev:ite]{ite}},
+#'		\code{\link[rkwarddev:echo]{echo}},
+#'		\code{\link[rkwarddev:id]{id}}
 #' @export
 
 rk.JS.doc <- function(require=c(), variables=NULL, results.header=NULL,

Modified: trunk/rkward/packages/rkwarddev/R/rk.JS.ite-class.R
===================================================================
--- trunk/rkward/packages/rkwarddev/R/rk.JS.ite-class.R	2011-10-03 16:47:37 UTC (rev 3876)
+++ trunk/rkward/packages/rkwarddev/R/rk.JS.ite-class.R	2011-10-03 19:31:00 UTC (rev 3877)
@@ -7,11 +7,13 @@
 	representation=representation(
 		ifJS="character",
 		thenJS="character",
-		elseJS="character"
+		elseJS="character",
+		elifJS="list"
 	),
 	prototype(
 		ifJS=character(),
 		thenJS=character(),
-		elseJS=character()
+		elseJS=character(),
+		elifJS=list()
 	)
 )

Added: trunk/rkward/packages/rkwarddev/R/rk.JS.vars.R
===================================================================
--- trunk/rkward/packages/rkwarddev/R/rk.JS.vars.R	                        (rev 0)
+++ trunk/rkward/packages/rkwarddev/R/rk.JS.vars.R	2011-10-03 19:31:00 UTC (rev 3877)
@@ -0,0 +1,33 @@
+#' Define variables in JavaScript code
+#' 
+#' @param variables A list with either character strings (the names of the variables to define),
+#'		of objects of class \code{XiMpLe.node} with plugin XML nodes (whose ID will be extracted and used).
+#' @param var.prefix A character string. If \code{def.vars=TRUE}, this string will be used as a prefix
+#'		for the JS variable names.
+#' @param level Integer, which indentation level to use, minimum is 1.
+#' @param indent.by A character string defining how indentation should be done.
+#' @return A character string.
+#' @export
+#' @seealso \code{\link[rkwarddev:rk.JS.array]{rk.JS.array}},
+#'		\code{\link[rkwarddev:echo]{echo}},
+#'		\code{\link[rkwarddev:id]{id}}
+#' @examples
+#' # create three checkboxes
+#' checkA <- rk.XML.cbox(label="Run Test A", value="A")
+#' checkB <- rk.XML.cbox(label="Run Test B", value="B")
+#' checkC <- rk.XML.cbox(label="Run Test C", value="C")
+#' # define them by their ID in JavaScript
+#' cat(rk.JS.vars(list(checkA, checkB, checkC)))
+
+rk.JS.vars <- function(variables, var.prefix=NULL, level=2, indent.by="\t"){
+	indent.by <- indent(level, by=indent.by)
+
+	JS.vars <- paste(unlist(sapply(child.list(variables), function(this.var){get.JS.vars(
+						JS.var=this.var,
+						XML.var=this.var,
+						JS.prefix=var.prefix,
+						indent.by=indent.by)
+				})), collapse="")
+
+	return(JS.vars)
+}

Modified: trunk/rkward/packages/rkwarddev/R/rk.paste.JS.R
===================================================================
--- trunk/rkward/packages/rkwarddev/R/rk.paste.JS.R	2011-10-03 16:47:37 UTC (rev 3876)
+++ trunk/rkward/packages/rkwarddev/R/rk.paste.JS.R	2011-10-03 19:31:00 UTC (rev 3877)
@@ -1,27 +1,27 @@
 #' Paste objects of class rk.JS.ite
 #'
-#' @param object An object of class \code{rk.JS.ite}
+#' @param object An object of class \code{rk.JS.ite} or \code{rk.JS.arr}
 #' @param level Integer, which indentation level to use, minimum is 1.
 #' @param indent.by A character string defining the indentation string to use.
+#' @param funct For \code{rk.JS.arr} objects only: Character string, name of the R function
+#' 	to be called to combine the options, e.g. "list" for \code{list()}, or "c" for \code{c()}.
 #' @return A character string.
 #' @include rk.JS.ite-class.R
+#' @include rk.JS.arr-class.R
+#' @seealso
+#'		\code{\link[rkwarddev:rk.JS.array]{rk.JS.array}},
+#'		\code{\link[rkwarddev:ite]{ite}}
 #' @export
 
-rk.paste.JS <- function(object, level=1, indent.by="\t"){
+rk.paste.JS <- function(object, level=1, indent.by="\t", funct=NULL){
 	stopifnot(level > 0)
-	# check indentation
-	main.indent <- indent(level, by=indent.by)
-	scnd.indent <- indent(level+1, by=indent.by)
 
 	if(inherits(object, "rk.JS.ite")){
-		ifJS <- paste(main.indent, "if(", object at ifJS, ") {\n", sep="")
-		thenJS <- paste(scnd.indent, object at thenJS, "\n", main.indent, "}", sep="")
-		if(!is.null(object at elseJS)) {
-			elseJS <- paste(" else {\n", scnd.indent, object at elseJS, "\n", main.indent, "}", sep="")
-		} else {
-			elseJS <- NULL
-		}
-		result <- paste(ifJS, thenJS, elseJS, collapse="", sep="")
+		# done by an internal function, to ease handling of recursions
+		result <- paste.JS.ite(object, level=level, indent.by=indent.by)
+	} else if(inherits(object, "rk.JS.arr")){
+		# done by an internal function, to ease handling of recursions
+		result <- paste.JS.array(object, level=level, indent.by=indent.by, funct=funct)
 	} else {
 		result <- paste(object)
 	}

Added: trunk/rkward/packages/rkwarddev/R/show-methods.R
===================================================================
--- trunk/rkward/packages/rkwarddev/R/show-methods.R	                        (rev 0)
+++ trunk/rkward/packages/rkwarddev/R/show-methods.R	2011-10-03 19:31:00 UTC (rev 3877)
@@ -0,0 +1,21 @@
+#' Show method for S4 objects of class \code{rk.JS.ite}
+#'
+#' @title Show method for objects of class rk.JS.ite
+#' @param object An object of class \code{rk.JS.ite}
+#' @aliases show,-methods show,rk.JS.ite-method
+#' @keywords methods
+#' @import methods
+#' @include rk.JS.ite-class.R
+#' @exportMethod show
+#' @rdname show-methods
+setGeneric("show")
+
+#' @rdname show-methods
+setMethod("show", signature(object="rk.JS.ite"), function(object){
+	cat(rk.paste.JS(object))
+})
+
+#' @rdname show-methods
+setMethod("show", signature(object="rk.JS.arr"), function(object){
+	cat(rk.paste.JS(object))
+})

Deleted: trunk/rkward/packages/rkwarddev/R/show.rk.JS.ite.R
===================================================================
--- trunk/rkward/packages/rkwarddev/R/show.rk.JS.ite.R	2011-10-03 16:47:37 UTC (rev 3876)
+++ trunk/rkward/packages/rkwarddev/R/show.rk.JS.ite.R	2011-10-03 19:31:00 UTC (rev 3877)
@@ -1,16 +0,0 @@
-#' Show method for S4 objects of class \code{rk.JS.ite}
-#'
-#' @title Show method for objects of class rk.JS.ite
-#' @param object An object of class \code{rk.JS.ite}
-#' @aliases show,-methods show,rk.JS.ite-method
-#' @keywords methods
-#' @import methods
-#' @include rk.JS.ite-class.R
-#' @exportMethod show
-#' @rdname show-methods
-setGeneric("show")
-
-#' @rdname show-methods
-setMethod("show", signature(object="rk.JS.ite"), function(object){
-	cat(rk.paste.JS(object))
-})

Modified: trunk/rkward/packages/rkwarddev/man/echo.Rd
===================================================================
--- trunk/rkward/packages/rkwarddev/man/echo.Rd	2011-10-03 16:47:37 UTC (rev 3876)
+++ trunk/rkward/packages/rkwarddev/man/echo.Rd	2011-10-03 19:31:00 UTC (rev 3877)
@@ -22,4 +22,14 @@
   generate a ready-to-run JavaScript \code{echo();} call
   from it.
 }
+\examples{
+cbox1 <- rk.XML.cbox(label="foo", value="foo1", id.name="CheckboxFoo.ID")
+echo("bar <- \\"", cbox1, "\\"")
+}
+\seealso{
+  \code{\link[rkwarddev:rk.JS.vars]{rk.JS.vars}},
+  \code{\link[rkwarddev:rk.JS.array]{rk.JS.array}},
+  \code{\link[rkwarddev:ite]{ite}},
+  \code{\link[rkwarddev:id]{id}}
+}
 

Modified: trunk/rkward/packages/rkwarddev/man/id.Rd
===================================================================
--- trunk/rkward/packages/rkwarddev/man/id.Rd	2011-10-03 16:47:37 UTC (rev 3876)
+++ trunk/rkward/packages/rkwarddev/man/id.Rd	2011-10-03 19:31:00 UTC (rev 3877)
@@ -27,4 +27,14 @@
   \code{id} value, and combine these replacements with
   character strings.
 }
+\examples{
+# an example checkbox XML node
+cbox1 <- rk.XML.cbox(label="foo", value="foo1", id.name="CheckboxFoo.ID")
+id("The ID is: ", cbox1, "!", quote=TRUE, collapse=" + ")
+}
+\seealso{
+  \code{\link[rkwarddev:rk.JS.vars]{rk.JS.vars}},
+  \code{\link[rkwarddev:rk.JS.array]{rk.JS.array}},
+  \code{\link[rkwarddev:echo]{echo}},
+}
 

Modified: trunk/rkward/packages/rkwarddev/man/ite.Rd
===================================================================
--- trunk/rkward/packages/rkwarddev/man/ite.Rd	2011-10-03 16:47:37 UTC (rev 3876)
+++ trunk/rkward/packages/rkwarddev/man/ite.Rd	2011-10-03 19:31:00 UTC (rev 3877)
@@ -20,4 +20,17 @@
 \description{
   Generate JavaScript if/then/else constructs
 }
+\examples{
+# first create an example checkbox XML node
+cbox1 <- rk.XML.cbox(label="foo", value="foo1", id.name="CheckboxFoo.ID")
+# now some JavaScript generation
+ite(id(cbox1), echo("bar <- \\"", cbox1, "\\""), echo("bar <- NULL"))
+}
+\seealso{
+  \code{\link[rkwarddev:rk.paste.JS]{rk.paste.JS}},
+  \code{\link[rkwarddev:rk.JS.vars]{rk.JS.vars}},
+  \code{\link[rkwarddev:rk.JS.array]{rk.JS.array}},
+  \code{\link[rkwarddev:echo]{echo}},
+  \code{\link[rkwarddev:id]{id}}
+}
 

Modified: trunk/rkward/packages/rkwarddev/man/rk.JS.array.Rd
===================================================================
--- trunk/rkward/packages/rkwarddev/man/rk.JS.array.Rd	2011-10-03 16:47:37 UTC (rev 3876)
+++ trunk/rkward/packages/rkwarddev/man/rk.JS.array.Rd	2011-10-03 19:31:00 UTC (rev 3877)
@@ -2,32 +2,28 @@
 \alias{rk.JS.array}
 \title{Create a simple JavaScript array}
 \usage{
-  rk.JS.array(option, variables = NULL, list = FALSE,
-  def.vars = TRUE, var.prefix = "chc", indent.by = "\t")
+  rk.JS.array(option, variables = list(), funct = "c",
+  var.prefix = NULL)
 }
 \arguments{
-  \item{option}{A character string, naming the option of,
-  e.g., an R function which should be constructed from
-  several variables.}
+  \item{option}{A character string, naming, e.g., an option
+  of an R function which should be constructed from several
+  variables.}
 
-  \item{variables}{A character vector, the names of the
-  variables to combine to a vector or list.}
+  \item{variables}{A list with either character strings
+  (the names of the variables to combine to a vector or
+  list), of objects of class \code{XiMpLe.node} with plugin
+  XML nodes (whose ID will be extracted and used).}
 
-  \item{list}{Logical, if \code{TRUE} the option will be
-  constructed by \code{list()}, otherwise by \code{c()}.}
+  \item{funct}{Character string, name of the R function to
+  be called to combine the options, e.g. "list" for
+  \code{list()}, or "c" for \code{c()}.}
 
-  \item{def.vars}{Logical, if \code{TRUE} the provided
-  variables will also be defined.}
-
-  \item{var.prefix}{A character string. If
-  \code{def.vars=TRUE}, this string will be used as a
-  prefix for the JS variable names.}
-
-  \item{indent.by}{A character string defining how
-  indentation should be done.}
+  \item{var.prefix}{A character string. sets a global
+  string to be used as a prefix for the JS variable names.}
 }
 \value{
-  A character string.
+  An object of class \code{rk.JS.arr}.
 }
 \description{
   If you need to combine multiple options (like values of
@@ -37,6 +33,17 @@
   desired argument type.
 }
 \examples{
-cat(rk.JS.array("my.option", variables=c("frst.var", "scnd.var")))
+# create three checkboxes for independent options
+checkA <- rk.XML.cbox(label="Run Test A", value="A")
+checkB <- rk.XML.cbox(label="Run Test B", value="B")
+checkC <- rk.XML.cbox(label="Run Test C", value="C")
+# combine them into one list of options via JavaScript
+rk.JS.array("run.tests", variables=list(checkA, checkB, checkC), funct="list")
 }
+\seealso{
+  \code{\link[rkwarddev:rk.paste.JS]{rk.paste.JS}},
+  \code{\link[rkwarddev:rk.JS.vars]{rk.JS.vars}},
+  \code{\link[rkwarddev:echo]{echo}},
+  \code{\link[rkwarddev:id]{id}}
+}
 

Modified: trunk/rkward/packages/rkwarddev/man/rk.JS.doc.Rd
===================================================================
--- trunk/rkward/packages/rkwarddev/man/rk.JS.doc.Rd	2011-10-03 16:47:37 UTC (rev 3876)
+++ trunk/rkward/packages/rkwarddev/man/rk.JS.doc.Rd	2011-10-03 19:31:00 UTC (rev 3877)
@@ -42,4 +42,12 @@
 \note{
   The JavaScript
 }
+\seealso{
+  \code{\link[rkwarddev:rk.paste.JS]{rk.paste.JS}},
+  \code{\link[rkwarddev:rk.JS.vars]{rk.JS.vars}},
+  \code{\link[rkwarddev:rk.JS.array]{rk.JS.array}},
+  \code{\link[rkwarddev:ite]{ite}},
+  \code{\link[rkwarddev:echo]{echo}},
+  \code{\link[rkwarddev:id]{id}}
+}
 

Added: trunk/rkward/packages/rkwarddev/man/rk.JS.vars.Rd
===================================================================
--- trunk/rkward/packages/rkwarddev/man/rk.JS.vars.Rd	                        (rev 0)
+++ trunk/rkward/packages/rkwarddev/man/rk.JS.vars.Rd	2011-10-03 19:31:00 UTC (rev 3877)
@@ -0,0 +1,43 @@
+\name{rk.JS.vars}
+\alias{rk.JS.vars}
+\title{Define variables in JavaScript code}
+\usage{
+  rk.JS.vars(variables, var.prefix = NULL, level = 2,
+  indent.by = "\t")
+}
+\arguments{
+  \item{variables}{A list with either character strings
+  (the names of the variables to define), of objects of
+  class \code{XiMpLe.node} with plugin XML nodes (whose ID
+  will be extracted and used).}
+
+  \item{var.prefix}{A character string. If
+  \code{def.vars=TRUE}, this string will be used as a
+  prefix for the JS variable names.}
+
+  \item{level}{Integer, which indentation level to use,
+  minimum is 1.}
+
+  \item{indent.by}{A character string defining how
+  indentation should be done.}
+}
+\value{
+  A character string.
+}
+\description{
+  Define variables in JavaScript code
+}
+\examples{
+# create three checkboxes
+checkA <- rk.XML.cbox(label="Run Test A", value="A")
+checkB <- rk.XML.cbox(label="Run Test B", value="B")
+checkC <- rk.XML.cbox(label="Run Test C", value="C")
+# define them by their ID in JavaScript
+cat(rk.JS.vars(list(checkA, checkB, checkC)))
+}
+\seealso{
+  \code{\link[rkwarddev:rk.JS.array]{rk.JS.array}},
+  \code{\link[rkwarddev:echo]{echo}},
+  \code{\link[rkwarddev:id]{id}}
+}
+

Modified: trunk/rkward/packages/rkwarddev/man/rk.paste.JS.Rd
===================================================================
--- trunk/rkward/packages/rkwarddev/man/rk.paste.JS.Rd	2011-10-03 16:47:37 UTC (rev 3876)
+++ trunk/rkward/packages/rkwarddev/man/rk.paste.JS.Rd	2011-10-03 19:31:00 UTC (rev 3877)
@@ -2,16 +2,23 @@
 \alias{rk.paste.JS}
 \title{Paste objects of class rk.JS.ite}
 \usage{
-  rk.paste.JS(object, level = 1, indent.by = "\t")
+  rk.paste.JS(object, level = 1, indent.by = "\t", funct =
+  NULL)
 }
 \arguments{
-  \item{object}{An object of class \code{rk.JS.ite}}
+  \item{object}{An object of class \code{rk.JS.ite} or
+  \code{rk.JS.arr}}
 
   \item{level}{Integer, which indentation level to use,
   minimum is 1.}
 
   \item{indent.by}{A character string defining the
   indentation string to use.}
+
+  \item{funct}{For \code{rk.JS.arr} objects only: Character
+  string, name of the R function to be called to combine
+  the options, e.g. "list" for \code{list()}, or "c" for
+  \code{c()}.}
 }
 \value{
   A character string.
@@ -19,4 +26,8 @@
 \description{
   Paste objects of class rk.JS.ite
 }
+\seealso{
+  \code{\link[rkwarddev:rk.JS.array]{rk.JS.array}},
+  \code{\link[rkwarddev:ite]{ite}}
+}
 

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.





More information about the rkward-tracker mailing list