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

m-eik at users.sourceforge.net m-eik at users.sourceforge.net
Tue Oct 4 20:27:50 UTC 2011


Revision: 3884
          http://rkward.svn.sourceforge.net/rkward/?rev=3884&view=rev
Author:   m-eik
Date:     2011-10-04 20:27:49 +0000 (Tue, 04 Oct 2011)
Log Message:
-----------
rkwarddev: rk.JS.vars() can now also write code to query properties

Modified Paths:
--------------
    trunk/rkward/packages/rkwarddev/ChangeLog
    trunk/rkward/packages/rkwarddev/DESCRIPTION
    trunk/rkward/packages/rkwarddev/R/rk-internal.R
    trunk/rkward/packages/rkwarddev/R/rk.JS.vars.R
    trunk/rkward/packages/rkwarddev/R/rkwarddev-package.R
    trunk/rkward/packages/rkwarddev/inst/CITATION
    trunk/rkward/packages/rkwarddev/man/rk.JS.vars.Rd
    trunk/rkward/packages/rkwarddev/man/rkwarddev-package.Rd

Modified: trunk/rkward/packages/rkwarddev/ChangeLog
===================================================================
--- trunk/rkward/packages/rkwarddev/ChangeLog	2011-10-04 17:20:21 UTC (rev 3883)
+++ trunk/rkward/packages/rkwarddev/ChangeLog	2011-10-04 20:27:49 UTC (rev 3884)
@@ -1,5 +1,8 @@
 ChangeLog for package rkwarddev
 
+## 0.02-5 (2011-10-04)
+  - added support for properties to rk.JS.vars() 
+
 ## 0.02-4 (2011-10-03)
   - some experimental JavaScript generator tools added, might very well be changed soon again:
     - added functions rk.JS.vars(), echo(), id(), ite() and rk.paste.JS() to help generate JavaScript code

Modified: trunk/rkward/packages/rkwarddev/DESCRIPTION
===================================================================
--- trunk/rkward/packages/rkwarddev/DESCRIPTION	2011-10-04 17:20:21 UTC (rev 3883)
+++ trunk/rkward/packages/rkwarddev/DESCRIPTION	2011-10-04 20:27:49 UTC (rev 3884)
@@ -14,8 +14,8 @@
 URL: http://rkward.sourceforge.net
 Authors at R: c(person(given="Meik", family="Michalke",
     email="meik.michalke at hhu.de", role=c("aut", "cre")))
-Version: 0.02-4
-Date: 2011-10-03
+Version: 0.02-5
+Date: 2011-10-04
 Collate:
     'echo.R'
     'id.R'

Modified: trunk/rkward/packages/rkwarddev/R/rk-internal.R
===================================================================
--- trunk/rkward/packages/rkwarddev/R/rk-internal.R	2011-10-04 17:20:21 UTC (rev 3883)
+++ trunk/rkward/packages/rkwarddev/R/rk-internal.R	2011-10-04 20:27:49 UTC (rev 3884)
@@ -118,7 +118,7 @@
 		word.vector[1] <- toupper(word.vector[1])
 		word.new <- paste(word.vector, collapse="")
 		return(word.new)
-		})
+	})
 
 	results <- paste(words[1], paste(new.words, collapse=""), sep="")
 
@@ -129,17 +129,55 @@
 #   <tag id="my.id" ...>
 # in XML will become
 #   var my.id = getValue("my.id");
-get.JS.vars <- function(JS.var, XML.var=NULL, JS.prefix="", indent.by="", names.only=FALSE){
+get.JS.vars <- function(JS.var, XML.var=NULL, JS.prefix="", indent.by="", names.only=FALSE, properties=NULL, default=FALSE){
 	# check for XiMpLe nodes
 	JS.var <- check.ID(JS.var)
 	if(!is.null(XML.var)){
+		# check validity of properties value
+		if(!is.null(properties)){
+			if(identical(properties, "all")){
+					if(inherits(XML.var, "XiMpLe.node")){
+						tag.name <- XML.var at name
+					} else {
+						tag.name <- XML.var
+					}
+				if(tag.name %in% names(all.valid.props)){
+					properties <- all.valid.props[[tag.name]]
+				} else {
+					properties <- NULL
+				}
+			} else {
+				properties <- sapply(child.list(properties), function(this.prop){
+					prop.validity(XML.var, property=this.prop, warn.only=TRUE, bool=FALSE)
+				})
+				properties <- properties[!"" %in% properties]
+			}
+		} else {}
 		XML.var <- check.ID(XML.var)
 	} else {}
-	if(isTRUE(names.only)){
-		results <- camelCode(c(JS.prefix, JS.var))
-	} else {
-		results <- paste(indent.by, "var ", camelCode(c(JS.prefix, JS.var)), " = getValue(\"", XML.var, "\");\n", sep="")
+
+	results <- c()
+	if(is.null(properties) | isTRUE(default)){
+		if(isTRUE(names.only)){
+			results <- camelCode(c(JS.prefix, JS.var))
+		} else {
+			results <- paste(indent.by, "var ", camelCode(c(JS.prefix, JS.var)), " = getValue(\"", XML.var, "\");\n", sep="")
+		}
+	} else {}
+	if(!is.null(properties)){
+		if(isTRUE(names.only)){
+			results <- c(results,
+				sapply(properties, function(this.prop){camelCode(c(JS.prefix, JS.var, this.prop))})
+			)
+		} else {
+			results <- c(results,
+				sapply(properties, function(this.prop){
+					paste(indent.by, "var ", camelCode(c(JS.prefix, JS.var, this.prop)), " = getValue(\"", XML.var, ".", this.prop, "\");\n", sep="")
+				})
+			)
+		}
 	}
+
 	return(results)
 } ## end function get.JS.vars()
 
@@ -200,6 +238,26 @@
 	return(node.ID)
 } ## end function check.ID()
 
+## list with valid properties
+all.valid.props <- list(
+	all=c("visible", "enabled", "required"),
+	text=c("text"),
+	varselector=c("selected", "root"),
+	varslot=c("available", "selected", "source"),
+	radio=c("string", "number"),
+	dropdown=c("string", "number"),
+	# option=c(),
+	checkbox=c("state"),
+	frame=c("checked"),
+	input=c("text"),
+	browser=c("selection"),
+	saveobject=c("selection", "parent", "objectname", "active"),
+	spinbox=c("int", "real"),
+	formula=c("model", "table", "labels", "fixed_factors", "dependent"),
+	embed=c("code"),
+	preview=c("state")
+) ## end list with valid properties
+
 ## function prop.validity()
 # checks if a property is valid for an XML node, if source is XiMpLe.node
 # if bool=FALSE, returns the property or ""
@@ -222,25 +280,6 @@
 		}
 	}
 
-	all.valid.props <- list(
-			all=c("visible", "enabled", "required"),
-			text=c("text"),
-			varselector=c("selected", "root"),
-			varslot=c("available", "selected", "source"),
-			radio=c("string", "number"),
-			dropdown=c("string", "number"),
-			# option=c(),
-			checkbox=c("state"),
-			frame=c("checked"),
-			input=c("text"),
-			browser=c("selection"),
-			saveobject=c("selection", "parent", "objectname", "active"),
-			spinbox=c("int", "real"),
-			formula=c("model", "table", "labels", "fixed_factors", "dependent"),
-			embed=c("code"),
-			preview=c("state")
-		)
-
 	if(tag.name %in% names(all.valid.props)){
 		valid.props <- c(all.valid.props[["all"]], all.valid.props[[tag.name]])
 	} else {
@@ -251,7 +290,7 @@
 	if(any(invalid.prop)){
 		if(isTRUE(warn.only)){
 			warning(paste("Some property you provided is invalid for '",tag.name,"' and was ignored: ",
-				paste(property[invalid.prop], collapse=", "), sep=""))
+				paste(property[invalid.prop], collapse=", "), sep=""), call.=FALSE)
 			if(isTRUE(bool)){
 				return(FALSE)
 			} else {

Modified: trunk/rkward/packages/rkwarddev/R/rk.JS.vars.R
===================================================================
--- trunk/rkward/packages/rkwarddev/R/rk.JS.vars.R	2011-10-04 17:20:21 UTC (rev 3883)
+++ trunk/rkward/packages/rkwarddev/R/rk.JS.vars.R	2011-10-04 20:27:49 UTC (rev 3884)
@@ -4,6 +4,9 @@
 #'		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 properties A character vector with properties you'd like to get of the XML node.
+#' @param default Logical, if \code{TRUE} the default value (no special property) of the node will
+#'		also be defined. Does nothing if \code{properties=NULL}.
 #' @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.
@@ -19,14 +22,16 @@
 #' # 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"){
+rk.JS.vars <- function(variables, var.prefix=NULL, properties=NULL, default=FALSE, 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)
+						indent.by=indent.by,
+						properties=properties,
+						default=default)
 				})), collapse="")
 
 	return(JS.vars)

Modified: trunk/rkward/packages/rkwarddev/R/rkwarddev-package.R
===================================================================
--- trunk/rkward/packages/rkwarddev/R/rkwarddev-package.R	2011-10-04 17:20:21 UTC (rev 3883)
+++ trunk/rkward/packages/rkwarddev/R/rkwarddev-package.R	2011-10-04 20:27:49 UTC (rev 3884)
@@ -3,8 +3,8 @@
 #' \tabular{ll}{
 #' Package: \tab rkwarddev\cr
 #' Type: \tab Package\cr
-#' Version: \tab 0.02-4\cr
-#' Date: \tab 2011-10-03\cr
+#' Version: \tab 0.02-5\cr
+#' Date: \tab 2011-10-04\cr
 #' Depends: \tab R (>= 2.9.0),XiMpLe,rkward (>= 0.5.6)\cr
 #' Enhances: \tab rkward\cr
 #' Encoding: \tab UTF-8\cr

Modified: trunk/rkward/packages/rkwarddev/inst/CITATION
===================================================================
--- trunk/rkward/packages/rkwarddev/inst/CITATION	2011-10-04 17:20:21 UTC (rev 3883)
+++ trunk/rkward/packages/rkwarddev/inst/CITATION	2011-10-04 20:27:49 UTC (rev 3884)
@@ -2,12 +2,12 @@
 		title="rkwarddev: A collection of tools for RKWard plugin development",
 		author="Meik Michalke",
 		year="2011",
-		note="(Version 0.02-4)",
+		note="(Version 0.02-5)",
 		url="http://rkward.sourceforge.net",
 
 		textVersion =
 		paste("Michalke, M. (2011). ",
-				"rkwarddev: A collection of tools for RKWard plugin development (Version 0.02-4). ",
+				"rkwarddev: A collection of tools for RKWard plugin development (Version 0.02-5). ",
 				"Available from http://rkward.sourceforge.net",
 				sep=""),
 

Modified: trunk/rkward/packages/rkwarddev/man/rk.JS.vars.Rd
===================================================================
--- trunk/rkward/packages/rkwarddev/man/rk.JS.vars.Rd	2011-10-04 17:20:21 UTC (rev 3883)
+++ trunk/rkward/packages/rkwarddev/man/rk.JS.vars.Rd	2011-10-04 20:27:49 UTC (rev 3884)
@@ -2,8 +2,8 @@
 \alias{rk.JS.vars}
 \title{Define variables in JavaScript code}
 \usage{
-  rk.JS.vars(variables, var.prefix = NULL, level = 2,
-  indent.by = "\t")
+  rk.JS.vars(variables, var.prefix = NULL, properties =
+  NULL, default = FALSE, level = 2, indent.by = "\t")
 }
 \arguments{
   \item{variables}{A list with either character strings
@@ -15,6 +15,13 @@
   \code{def.vars=TRUE}, this string will be used as a
   prefix for the JS variable names.}
 
+  \item{properties}{A character vector with properties
+  you'd like to get of the XML node.}
+
+  \item{default}{Logical, if \code{TRUE} the default value
+  (no special property) of the node will also be defined.
+  Does nothing if \code{properties=NULL}.}
+
   \item{level}{Integer, which indentation level to use,
   minimum is 1.}
 

Modified: trunk/rkward/packages/rkwarddev/man/rkwarddev-package.Rd
===================================================================
--- trunk/rkward/packages/rkwarddev/man/rkwarddev-package.Rd	2011-10-04 17:20:21 UTC (rev 3883)
+++ trunk/rkward/packages/rkwarddev/man/rkwarddev-package.Rd	2011-10-04 20:27:49 UTC (rev 3884)
@@ -8,8 +8,8 @@
 }
 \details{
   \tabular{ll}{ Package: \tab rkwarddev\cr Type: \tab
-  Package\cr Version: \tab 0.02-4\cr Date: \tab
-  2011-10-03\cr Depends: \tab R (>= 2.9.0),XiMpLe,rkward
+  Package\cr Version: \tab 0.02-5\cr Date: \tab
+  2011-10-04\cr Depends: \tab R (>= 2.9.0),XiMpLe,rkward
   (>= 0.5.6)\cr Enhances: \tab rkward\cr Encoding: \tab
   UTF-8\cr License: \tab GPL (>= 3)\cr LazyLoad: \tab
   yes\cr URL: \tab http://rkward.sourceforge.net\cr }

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