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

m-eik at users.sourceforge.net m-eik at users.sourceforge.net
Sun Oct 2 22:11:14 UTC 2011


Revision: 3875
          http://rkward.svn.sourceforge.net/rkward/?rev=3875&view=rev
Author:   m-eik
Date:     2011-10-02 22:11:13 +0000 (Sun, 02 Oct 2011)
Log Message:
-----------
rkwarddev: added some early, experimental JS generating functions and classes

Modified Paths:
--------------
    trunk/rkward/packages/rkwarddev/ChangeLog
    trunk/rkward/packages/rkwarddev/DESCRIPTION
    trunk/rkward/packages/rkwarddev/NAMESPACE
    trunk/rkward/packages/rkwarddev/R/rkwarddev-package.R
    trunk/rkward/packages/rkwarddev/inst/CITATION
    trunk/rkward/packages/rkwarddev/man/rkwarddev-package.Rd

Added Paths:
-----------
    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.JS.ite-class.R
    trunk/rkward/packages/rkwarddev/R/rk.paste.JS.R
    trunk/rkward/packages/rkwarddev/R/show.rk.JS.ite.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.paste.JS.Rd
    trunk/rkward/packages/rkwarddev/man/show-methods.Rd

Modified: trunk/rkward/packages/rkwarddev/ChangeLog
===================================================================
--- trunk/rkward/packages/rkwarddev/ChangeLog	2011-10-02 17:05:43 UTC (rev 3874)
+++ trunk/rkward/packages/rkwarddev/ChangeLog	2011-10-02 22:11:13 UTC (rev 3875)
@@ -1,5 +1,10 @@
 ChangeLog for package rkwarddev
 
+## 0.02-4 (2011-10-02)
+  - 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
+
 ## 0.02-3 (2011-09-30)
   - added functions rk.XML.attribute(), rk.XML.component(), rk.XML.components(), rk.XML.context(),
     rk.XML.entry(), rk.XML.hierarchy(), rk.XML.menu() and rk.XML.require()

Modified: trunk/rkward/packages/rkwarddev/DESCRIPTION
===================================================================
--- trunk/rkward/packages/rkwarddev/DESCRIPTION	2011-10-02 17:05:43 UTC (rev 3874)
+++ trunk/rkward/packages/rkwarddev/DESCRIPTION	2011-10-02 22:11:13 UTC (rev 3875)
@@ -14,14 +14,19 @@
 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-3
-Date: 2011-09-30
+Version: 0.02-4
+Date: 2011-10-03
 Collate:
+    'echo.R'
+    'id.R'
+    'rk.JS.ite-class.R'
+    'ite.R'
     'rk.build.plugin.R'
     'rk-internal.R'
     'rk.JS.array.R'
     'rk.JS.doc.R'
     'rk.JS.scan.R'
+    'rk.paste.JS.R'
     'rk.plugin.skeleton.R'
     'rk.rkh.doc.R'
     'rk.rkh.scan.R'
@@ -71,3 +76,4 @@
     'rk.XML.varslot.R'
     'rk.XML.vars.R'
     'rk.XML.wizard.R'
+    'show.rk.JS.ite.R'

Modified: trunk/rkward/packages/rkwarddev/NAMESPACE
===================================================================
--- trunk/rkward/packages/rkwarddev/NAMESPACE	2011-10-02 17:05:43 UTC (rev 3874)
+++ trunk/rkward/packages/rkwarddev/NAMESPACE	2011-10-02 22:11:13 UTC (rev 3875)
@@ -1,3 +1,8 @@
+exportClasses(rk.JS.ite)
+export(echo)
+export(id)
+export(ite)
+exportMethods(show)
 export(rk.build.plugin)
 export(rk.JS.array)
 export(rk.JS.doc)
@@ -2,2 +7,3 @@
 export(rk.JS.scan)
+export(rk.paste.JS)
 export(rk.plugin.skeleton)
@@ -49,3 +55,4 @@
 export(rk.XML.varselector)
 export(rk.XML.varslot)
 export(rk.XML.wizard)
+import(methods)

Added: trunk/rkward/packages/rkwarddev/R/echo.R
===================================================================
--- trunk/rkward/packages/rkwarddev/R/echo.R	                        (rev 0)
+++ trunk/rkward/packages/rkwarddev/R/echo.R	2011-10-02 22:11:13 UTC (rev 3875)
@@ -0,0 +1,17 @@
+#' Generate JavaScript echo command call
+#' 
+#' This function will take several elements, either character strings or objects of class \code{XiMpLe.node}
+#' which hold an XML node of some plugin GUI definition, and generate a ready-to-run JavaScript \code{echo();}
+#' call from it.
+#' 
+#' @param ... One or several character strings and/or \code{XiMpLe.node} objects with plugin nodes,
+#'		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.
+#' @export
+
+echo <- function(..., newline=""){
+	ID.content <- id(..., quote=TRUE,  collapse=" + ")
+	result <- paste("echo(", ID.content, ");", newline, sep="")
+	return(result)
+}

Added: trunk/rkward/packages/rkwarddev/R/id.R
===================================================================
--- trunk/rkward/packages/rkwarddev/R/id.R	                        (rev 0)
+++ trunk/rkward/packages/rkwarddev/R/id.R	2011-10-02 22:11:13 UTC (rev 3875)
@@ -0,0 +1,33 @@
+#' Replace XiMpLe.node objects with their ID value
+#' 
+#' This function is intended to be used for generating JavaScript code for
+#' RKWard plugins. Its sole purpose is to replace objects of class \code{XiMpLe.node}
+#' which hold an XML node of some plugin GUI definition with their \code{id} value, and
+#' combine these replacements with character strings.
+#' 
+#' @param ... One or several character strings and/or \code{XiMpLe.node} objects with plugin nodes,
+#'		simply separated by comma.
+#' @param quote Logical, it the character strings sould be deparsed, so they come out "as-is" when
+#'		written to files, e.g. by \code{cat}.
+#' @param collapse Character string, defining if and how the individual elements should be glued together.
+#' @return A character string.
+#' @export
+
+id <- function(..., quote=FALSE, collapse=""){
+	full.content <- list(...)
+	ID.content <- sapply(full.content, function(this.part){
+			if(inherits(this.part, "XiMpLe.node")){
+				node.id <- this.part at attributes$id
+				return(node.id)
+			} else {
+				if(isTRUE(quote)){
+					text.part <- deparse(this.part)
+				} else {
+					text.part <- this.part
+				}
+				return(text.part)
+			}
+		})
+	result <- paste(ID.content, collapse=collapse)
+	return(result)
+}

Added: trunk/rkward/packages/rkwarddev/R/ite.R
===================================================================
--- trunk/rkward/packages/rkwarddev/R/ite.R	                        (rev 0)
+++ trunk/rkward/packages/rkwarddev/R/ite.R	2011-10-02 22:11:13 UTC (rev 3875)
@@ -0,0 +1,17 @@
+#' Generate JavaScript if/then/else constructs
+#' 
+#' @param ifjs A character string, to be placed in the brackets if an \code{if()} statement.
+#' @param thenjs A character string, the code to be executed in case the \code{if()} statement is true.
+#' @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
+#' @export
+
+ite <- function(ifjs, thenjs, elsejs=NULL){
+	result <- new("rk.JS.ite",
+		ifJS=ifjs,
+		thenJS=thenjs,
+		elseJS=elsejs
+	)
+	return(result)
+}

Added: trunk/rkward/packages/rkwarddev/R/rk.JS.ite-class.R
===================================================================
--- trunk/rkward/packages/rkwarddev/R/rk.JS.ite-class.R	                        (rev 0)
+++ trunk/rkward/packages/rkwarddev/R/rk.JS.ite-class.R	2011-10-02 22:11:13 UTC (rev 3875)
@@ -0,0 +1,17 @@
+#' @export
+
+# this simple class is for JavaScript generation,
+# produced by ite()
+
+setClass("rk.JS.ite",
+	representation=representation(
+		ifJS="character",
+		thenJS="character",
+		elseJS="character"
+	),
+	prototype(
+		ifJS=character(),
+		thenJS=character(),
+		elseJS=character()
+	)
+)

Added: trunk/rkward/packages/rkwarddev/R/rk.paste.JS.R
===================================================================
--- trunk/rkward/packages/rkwarddev/R/rk.paste.JS.R	                        (rev 0)
+++ trunk/rkward/packages/rkwarddev/R/rk.paste.JS.R	2011-10-02 22:11:13 UTC (rev 3875)
@@ -0,0 +1,30 @@
+#' Paste objects of class rk.JS.ite
+#'
+#' @param object An object of class \code{rk.JS.ite}
+#' @param level Integer, which indentation level to use, minimum is 1.
+#' @param indent.by A character string defining the indentation string to use.
+#' @return A character string.
+#' @include rk.JS.ite-class.R
+#' @export
+
+rk.paste.JS <- function(object, level=1, indent.by="\t"){
+	stopifnot(level > 0)
+	# check indentation
+	main.indent <- paste(rep(indent.by, level-1), collapse="")
+	scnd.indent <- paste(rep(indent.by, level), collapse="")
+
+	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="")
+	} else {
+		result <- paste(object)
+	}
+
+	return(result)
+}

Modified: trunk/rkward/packages/rkwarddev/R/rkwarddev-package.R
===================================================================
--- trunk/rkward/packages/rkwarddev/R/rkwarddev-package.R	2011-10-02 17:05:43 UTC (rev 3874)
+++ trunk/rkward/packages/rkwarddev/R/rkwarddev-package.R	2011-10-02 22:11:13 UTC (rev 3875)
@@ -3,8 +3,8 @@
 #' \tabular{ll}{
 #' Package: \tab rkwarddev\cr
 #' Type: \tab Package\cr
-#' Version: \tab 0.02-3\cr
-#' Date: \tab 2011-09-30\cr
+#' Version: \tab 0.02-4\cr
+#' Date: \tab 2011-10-03\cr
 #' Depends: \tab R (>= 2.9.0),XiMpLe,rkward (>= 0.5.6)\cr
 #' Enhances: \tab rkward\cr
 #' Encoding: \tab UTF-8\cr

Added: trunk/rkward/packages/rkwarddev/R/show.rk.JS.ite.R
===================================================================
--- trunk/rkward/packages/rkwarddev/R/show.rk.JS.ite.R	                        (rev 0)
+++ trunk/rkward/packages/rkwarddev/R/show.rk.JS.ite.R	2011-10-02 22:11:13 UTC (rev 3875)
@@ -0,0 +1,16 @@
+#' 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/inst/CITATION
===================================================================
--- trunk/rkward/packages/rkwarddev/inst/CITATION	2011-10-02 17:05:43 UTC (rev 3874)
+++ trunk/rkward/packages/rkwarddev/inst/CITATION	2011-10-02 22:11:13 UTC (rev 3875)
@@ -2,12 +2,12 @@
 		title="rkwarddev: A collection of tools for RKWard plugin development",
 		author="Meik Michalke",
 		year="2011",
-		note="(Version 0.02-3)",
+		note="(Version 0.02-4)",
 		url="http://rkward.sourceforge.net",
 
 		textVersion =
 		paste("Michalke, M. (2011). ",
-				"rkwarddev: A collection of tools for RKWard plugin development (Version 0.02-3). ",
+				"rkwarddev: A collection of tools for RKWard plugin development (Version 0.02-4). ",
 				"Available from http://rkward.sourceforge.net",
 				sep=""),
 

Added: trunk/rkward/packages/rkwarddev/man/echo.Rd
===================================================================
--- trunk/rkward/packages/rkwarddev/man/echo.Rd	                        (rev 0)
+++ trunk/rkward/packages/rkwarddev/man/echo.Rd	2011-10-02 22:11:13 UTC (rev 3875)
@@ -0,0 +1,25 @@
+\name{echo}
+\alias{echo}
+\title{Generate JavaScript echo command call}
+\usage{
+  echo(..., newline = "")
+}
+\arguments{
+  \item{...}{One or several character strings and/or
+  \code{XiMpLe.node} objects with plugin nodes, simply
+  separated by comma.}
+
+  \item{newline}{Character string, can be set to e.g.
+  \code{"\n"} to force a newline after the call.}
+}
+\value{
+  A character string.
+}
+\description{
+  This function will take several elements, either
+  character strings or objects of class \code{XiMpLe.node}
+  which hold an XML node of some plugin GUI definition, and
+  generate a ready-to-run JavaScript \code{echo();} call
+  from it.
+}
+

Added: trunk/rkward/packages/rkwarddev/man/id.Rd
===================================================================
--- trunk/rkward/packages/rkwarddev/man/id.Rd	                        (rev 0)
+++ trunk/rkward/packages/rkwarddev/man/id.Rd	2011-10-02 22:11:13 UTC (rev 3875)
@@ -0,0 +1,30 @@
+\name{id}
+\alias{id}
+\title{Replace XiMpLe.node objects with their ID value}
+\usage{
+  id(..., quote = FALSE, collapse = "")
+}
+\arguments{
+  \item{...}{One or several character strings and/or
+  \code{XiMpLe.node} objects with plugin nodes, simply
+  separated by comma.}
+
+  \item{quote}{Logical, it the character strings sould be
+  deparsed, so they come out "as-is" when written to files,
+  e.g. by \code{cat}.}
+
+  \item{collapse}{Character string, defining if and how the
+  individual elements should be glued together.}
+}
+\value{
+  A character string.
+}
+\description{
+  This function is intended to be used for generating
+  JavaScript code for RKWard plugins. Its sole purpose is
+  to replace objects of class \code{XiMpLe.node} which hold
+  an XML node of some plugin GUI definition with their
+  \code{id} value, and combine these replacements with
+  character strings.
+}
+

Added: trunk/rkward/packages/rkwarddev/man/ite.Rd
===================================================================
--- trunk/rkward/packages/rkwarddev/man/ite.Rd	                        (rev 0)
+++ trunk/rkward/packages/rkwarddev/man/ite.Rd	2011-10-02 22:11:13 UTC (rev 3875)
@@ -0,0 +1,23 @@
+\name{ite}
+\alias{ite}
+\title{Generate JavaScript if/then/else constructs}
+\usage{
+  ite(ifjs, thenjs, elsejs = NULL)
+}
+\arguments{
+  \item{ifjs}{A character string, to be placed in the
+  brackets if an \code{if()} statement.}
+
+  \item{thenjs}{A character string, the code to be executed
+  in case the \code{if()} statement is true.}
+
+  \item{elsejs}{A character string, the code to be executed
+  in case the \code{if()} statement is not true.}
+}
+\value{
+  An object of class \code{rk.JS.ite}
+}
+\description{
+  Generate JavaScript if/then/else constructs
+}
+

Added: trunk/rkward/packages/rkwarddev/man/rk.paste.JS.Rd
===================================================================
--- trunk/rkward/packages/rkwarddev/man/rk.paste.JS.Rd	                        (rev 0)
+++ trunk/rkward/packages/rkwarddev/man/rk.paste.JS.Rd	2011-10-02 22:11:13 UTC (rev 3875)
@@ -0,0 +1,22 @@
+\name{rk.paste.JS}
+\alias{rk.paste.JS}
+\title{Paste objects of class rk.JS.ite}
+\usage{
+  rk.paste.JS(object, level = 1, indent.by = "\t")
+}
+\arguments{
+  \item{object}{An object of class \code{rk.JS.ite}}
+
+  \item{level}{Integer, which indentation level to use,
+  minimum is 1.}
+
+  \item{indent.by}{A character string defining the
+  indentation string to use.}
+}
+\value{
+  A character string.
+}
+\description{
+  Paste objects of class rk.JS.ite
+}
+

Modified: trunk/rkward/packages/rkwarddev/man/rkwarddev-package.Rd
===================================================================
--- trunk/rkward/packages/rkwarddev/man/rkwarddev-package.Rd	2011-10-02 17:05:43 UTC (rev 3874)
+++ trunk/rkward/packages/rkwarddev/man/rkwarddev-package.Rd	2011-10-02 22:11:13 UTC (rev 3875)
@@ -8,8 +8,8 @@
 }
 \details{
   \tabular{ll}{ Package: \tab rkwarddev\cr Type: \tab
-  Package\cr Version: \tab 0.02-3\cr Date: \tab
-  2011-09-30\cr Depends: \tab R (>= 2.9.0),XiMpLe,rkward
+  Package\cr Version: \tab 0.02-4\cr Date: \tab
+  2011-10-03\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 }

Added: trunk/rkward/packages/rkwarddev/man/show-methods.Rd
===================================================================
--- trunk/rkward/packages/rkwarddev/man/show-methods.Rd	                        (rev 0)
+++ trunk/rkward/packages/rkwarddev/man/show-methods.Rd	2011-10-02 22:11:13 UTC (rev 3875)
@@ -0,0 +1,13 @@
+\name{show}
+\alias{show}
+\alias{show,-methods}
+\alias{show,rk.JS.ite-method}
+\title{Show method for objects of class rk.JS.ite}
+\arguments{
+  \item{object}{An object of class \code{rk.JS.ite}}
+}
+\description{
+  Show method for S4 objects of class \code{rk.JS.ite}
+}
+\keyword{methods}
+

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