[rkward-cvs] [rkward] packages/rkwarddev: some changes to make it possible to have default modifiers without changing the JS varaible name. phew...
m.eik michalke
meik.michalke at uni-duesseldorf.de
Wed Dec 3 15:31:54 UTC 2014
Git commit 838aa48dc7ba06469d8b806f64c47925c8b99536 by m.eik michalke.
Committed on 03/12/2014 at 15:31.
Pushed by meikm into branch 'master'.
some changes to make it possible to have default modifiers without changing the JS varaible name. phew...
M +4 -3 packages/rkwarddev/ChangeLog
M +4 -1 packages/rkwarddev/DESCRIPTION
M +2 -0 packages/rkwarddev/R/00_class_02_rk.JS.var.R
A +63 -0 packages/rkwarddev/R/60_JS.getters.default.R
M +56 -69 packages/rkwarddev/R/rk-internal.R
M +33 -0 packages/rkwarddev/R/rk.JS.scan.R
M +1 -1 packages/rkwarddev/R/rkwarddev-package.R
M +2 -2 packages/rkwarddev/man/R.comment.Rd
M +1 -1 packages/rkwarddev/man/rkwarddev-package.Rd
http://commits.kde.org/rkward/838aa48dc7ba06469d8b806f64c47925c8b99536
diff --git a/packages/rkwarddev/ChangeLog b/packages/rkwarddev/ChangeLog
index 8cddce9..dfd74bf 100644
--- a/packages/rkwarddev/ChangeLog
+++ b/packages/rkwarddev/ChangeLog
@@ -1,6 +1,6 @@
ChangeLog for package rkwarddev
-changes in version 0.06-6 (2014-12-02)
+changes in version 0.06-6 (2014-12-03)
fixed:
- rk.XML.optionset() does now allow to re-use objects defined in the same
function call (i.e., refer to optioncolumns in the logic section)
@@ -11,6 +11,7 @@ fixed:
- rk.plugin.skeleton() still allowed invalid IDs, fixed the regexp
- rk.XML.snippets() now also accepts <include> as child node
- rk.XML.tabbook() returns <insert> nodes as-is, not nested in <tab></tab>
+ - rk.JS.scan() now sets "state" as default modifier for checkboxes if guess.getter is TRUE
added:
- all "help" values can now be a list of character strings or XiMpLe nodes,
to have more control over the markup
@@ -28,8 +29,8 @@ changed:
- comment nodes (<!-- foo -->) are now globally allowed as child nodes in XML; important for
i18n comments
- modifier checks now point to rkwarddev:::all.valid.modifiers directly in case of errors
- - internally, moved the definitions of valid child nodes and modifiers to separate files, so they're
- more obvious to find and check
+ - internally, moved the definitions of valid child nodes and modifiers as well as default getter
+ functions and modifiers to separate files, so they're more obvious to find and check
removed:
- the functions rk.set.language() rk.get.language() were no longer useful and therefore removed
- also removed the option "lang" from rk.rkh.doc(), rk.XML.plugin(), rk.XML.pluginmap()
diff --git a/packages/rkwarddev/DESCRIPTION b/packages/rkwarddev/DESCRIPTION
index 2bd1a58..90ae0ef 100644
--- a/packages/rkwarddev/DESCRIPTION
+++ b/packages/rkwarddev/DESCRIPTION
@@ -15,7 +15,7 @@ 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.06-6
-Date: 2014-12-01
+Date: 2014-12-03
Collate:
'00_class_01_rk.JS.arr.R'
'00_class_02_rk.JS.var.R'
@@ -26,6 +26,9 @@ Collate:
'rk.XML.plugin.R'
'rk.JS.doc.R'
'00_class_06_rk.plug.comp.R'
+ '50_all.valid.children.R'
+ '50_all.valid.modifiers.R'
+ '60_JS.getters.default.R'
'R.comment.R'
'echo.R'
'i18n.R'
diff --git a/packages/rkwarddev/R/00_class_02_rk.JS.var.R b/packages/rkwarddev/R/00_class_02_rk.JS.var.R
index e39646c..6fcf8ac 100644
--- a/packages/rkwarddev/R/00_class_02_rk.JS.var.R
+++ b/packages/rkwarddev/R/00_class_02_rk.JS.var.R
@@ -28,6 +28,7 @@ setClass("rk.JS.var",
prefix="character",
modifiers="list",
default="logical",
+ append.modifier="logical",
join="character",
vars="list",
getter="character"
@@ -38,6 +39,7 @@ setClass("rk.JS.var",
prefix=character(),
modifiers=list(),
default=FALSE,
+ append.modifier=TRUE,
join="",
vars=list(),
getter="getValue" # for compatibility with earlier releases
diff --git a/packages/rkwarddev/R/60_JS.getters.default.R b/packages/rkwarddev/R/60_JS.getters.default.R
new file mode 100644
index 0000000..98f37ba
--- /dev/null
+++ b/packages/rkwarddev/R/60_JS.getters.default.R
@@ -0,0 +1,63 @@
+## default getters for JavaScript variables
+# try to set useful default getter functions to query the values from XML nodes
+# will only be used if "guess.getter" is true
+JS.getters.default <- list(
+ "browser"="getString",
+ "checkbox"="getBoolean",
+ "dropdown"="getString",
+ "frame"="getBoolean",
+ "input"="getString",
+ "matrix"="getList",
+ "optioncolumn"="getList",
+ "radio"="getString",
+ "saveobject"="getString",
+ "select"="getString",
+ "spinbox"="getString",
+ "valueslot"="getString",
+ "varslot"="getString"
+)
+
+# we can also guess some fitting getter functions by the modifier set
+JS.getters.modif.default <- list(
+# "active",
+# "available",
+# "calculate",
+ "checked"="getBoolean",
+ "checked.not"="getBoolean",
+ "checked.numeric"="getBoolean",
+ "dependent"="getString",
+ "enabled"="getBoolean",
+ "enabled.not"="getBoolean",
+ "enabled.numeric"="getBoolean",
+# "false",
+ "fixed_factors"="getString",
+# "int",
+ "label"="getString",
+ "labels"="getString",
+ "model"="getString",
+# "not",
+# "number",
+# "numeric",
+ "objectname"="getString",
+ "parent"="getString",
+ "preprocess"="getString",
+ "preview"="getBoolean",
+ "printout"="getString",
+# "real",
+ "required"="getBoolean",
+# "root",
+# "selected",
+# "selection",
+ "shortname"="getString",
+ "source"="getString",
+ "state"="getBoolean",
+ "state.not"="getBoolean",
+ "state.numeric"="getBoolean",
+ "string"="getString",
+# "table",
+ "text"="getString",
+# "true",
+ "visible"="getBoolean",
+ "visible.not"="getBoolean",
+ "visible.numeric"="getBoolean"
+)
diff --git a/packages/rkwarddev/R/rk-internal.R b/packages/rkwarddev/R/rk-internal.R
index e899d95..5350428 100644
--- a/packages/rkwarddev/R/rk-internal.R
+++ b/packages/rkwarddev/R/rk-internal.R
@@ -277,75 +277,13 @@ camelCode <- function(words){
} ## end function camelCode()
-## default getters for JavaScript variables
-# try to set useful default getter functions to query the values from XML nodes
-# will only be used if "guess.getter" is true
-JS.getters.default <- list(
- "browser"="getString",
- "checkbox"="getBoolean",
- "dropdown"="getString",
- "frame"="getBoolean",
- "input"="getString",
- "matrix"="getList",
- "optioncolumn"="getList",
- "radio"="getString",
- "saveobject"="getString",
- "select"="getString",
- "spinbox"="getString",
- "valueslot"="getString",
- "varslot"="getString"
-)
-# we can also guess some fitting getter functions by the modifier set
-JS.getters.modif.default <- list(
-# "active",
-# "available",
-# "calculate",
- "checked"="getBoolean",
- "checked.not"="getBoolean",
- "checked.numeric"="getBoolean",
- "dependent"="getString",
- "enabled"="getBoolean",
- "enabled.not"="getBoolean",
- "enabled.numeric"="getBoolean",
-# "false",
- "fixed_factors"="getString",
-# "int",
- "label"="getString",
- "labels"="getString",
- "model"="getString",
-# "not",
-# "number",
-# "numeric",
- "objectname"="getString",
- "parent"="getString",
- "preprocess"="getString",
- "preview"="getBoolean",
- "printout"="getString",
-# "real",
- "required"="getBoolean",
-# "root",
-# "selected",
-# "selection",
- "shortname"="getString",
- "source"="getString",
- "state"="getBoolean",
- "state.not"="getBoolean",
- "state.numeric"="getBoolean",
- "string"="getString",
-# "table",
- "text"="getString",
-# "true",
- "visible"="getBoolean",
- "visible.not"="getBoolean",
- "visible.numeric"="getBoolean"
-)
-
## function get.JS.vars()
+# see 60_JS.getters.default.R for definition of JS.getters.default and JS.getters.modif.default
# <tag id="my.id" ...>
# in XML will become
# var my.id = getValue("my.id");
get.JS.vars <- function(JS.var, XML.var=NULL, tag.name=NULL, JS.prefix="", names.only=FALSE, modifiers=NULL, default=FALSE, join="",
- getter="getValue", guess.getter=FALSE, check.modifiers=TRUE, search.environment=FALSE){
+ getter="getValue", guess.getter=FALSE, check.modifiers=TRUE, search.environment=FALSE, append.modifier=TRUE){
# check for XiMpLe nodes
JS.var <- check.ID(JS.var)
have.XiMpLe.var <- FALSE
@@ -382,6 +320,7 @@ get.JS.vars <- function(JS.var, XML.var=NULL, tag.name=NULL, JS.prefix="", names
# check for getter guessing
if(isTRUE(guess.getter)){
+ # see 60_JS.getters.default.R for definition of JS.getters.default
if(tag.name %in% names(JS.getters.default)){
# special case: is a <checkbox> has a value other than
# "true" or "false", it's probably supposed to be fetched
@@ -395,6 +334,7 @@ get.JS.vars <- function(JS.var, XML.var=NULL, tag.name=NULL, JS.prefix="", names
## TODO: currently this only works for one modifier of if all
## modifiers are fine with the same getter; maybe "getter"
## should become a vector like "modifiers"
+ # see 60_JS.getters.default.R for definition of JS.getters.modif.default
if(!is.null(modifiers) && any(modifiers %in% names(JS.getters.modif.default))){
# find all matching modifiers
getter.modifs <- modifiers[modifiers %in% names(JS.getters.modif.default)]
@@ -447,6 +387,7 @@ get.JS.vars <- function(JS.var, XML.var=NULL, tag.name=NULL, JS.prefix="", names
prefix=JS.prefix,
modifiers=as.list(modifiers),
default=default,
+ append.modifier=append.modifier,
join=join,
getter=getter)
}
@@ -1003,8 +944,11 @@ paste.JS.options <- function(object, level=2, indent.by="\t", array=NULL, funct=
## function paste.JS.var()
-paste.JS.var <- function(object, level=2, indent.by="\t", JS.prefix=NULL, modifiers=NULL, default=NULL, join=NULL,
- getter=NULL, names.only=FALSE, check.modifiers=FALSE){
+# append.modifier: if a modifier is given, should that become part of the variable name? this is mostly
+# important for "checkbox", which has "state" as default modifier, but using the checkbox object will not
+# notice this. works only for the first modifier given.
+paste.JS.var <- function(object, level=2, indent.by="\t", JS.prefix=NULL, modifiers=NULL, default=NULL, append.modifier=NULL,
+ join=NULL, getter=NULL, names.only=FALSE, check.modifiers=FALSE){
# paste several objects
results <- unlist(sapply(slot(object, "vars"), function(this.obj){
paste.JS.var(this.obj,
@@ -1013,6 +957,7 @@ paste.JS.var <- function(object, level=2, indent.by="\t", JS.prefix=NULL, modifi
JS.prefix=JS.prefix,
modifiers=modifiers,
default=default,
+ append.modifier=append.modifier,
join=join,
getter=getter,
names.only=names.only)}))
@@ -1038,6 +983,9 @@ paste.JS.var <- function(object, level=2, indent.by="\t", JS.prefix=NULL, modifi
if(is.null(default)){
default <- slot(object, "default")
} else {}
+ if(is.null(append.modifier)){
+ append.modifier <- slot(object, "append.modifier")
+ } else {}
if(is.null(join)){
join <- slot(object, "join")
} else {}
@@ -1065,11 +1013,17 @@ paste.JS.var <- function(object, level=2, indent.by="\t", JS.prefix=NULL, modifi
# check modifiers
modifiers <- modifiers[modif.validity(source="all", modifier=modifiers, ignore.empty=TRUE, warn.only=TRUE, bool=TRUE)]
} else {}
- modif.results <- sapply(modifiers, function(this.modif){
+ modif.results <- sapply(1:length(modifiers), function(this.modif.num){
+ this.modif <- modifiers[[this.modif.num]]
+ if(isTRUE(append.modifier) || this.modif.num > 1){
+ this.name <- camelCode(c(JS.prefix, JS.var, this.modif))
+ } else {
+ this.name <- camelCode(c(JS.prefix, JS.var))
+ }
if(isTRUE(names.only)){
- return(camelCode(c(JS.prefix, JS.var, this.modif)))
+ return(this.name)
} else {
- return(paste0(main.indent, "var ", camelCode(c(JS.prefix, JS.var, this.modif)),
+ return(paste0(main.indent, "var ", this.name,
" = ", getter, "(\"", XML.var, ".", this.modif, "\")", join.code, ";"))
}
})
@@ -1360,3 +1314,36 @@ force.i18n <- function(obj){
return(result)
} ## end function force.i18n
+
+## function check.JS.lines()
+# called by rk.JS.scan()
+check.JS.lines <- function(relevant.tags, single.tags, add.abbrev, js, indent.by, guess.getter,
+ tag.names=TRUE, modifiers=NULL, only.checkable=FALSE, append.modifier=TRUE, result=NULL){
+
+ JS.id <- get.IDs(single.tags=single.tags, relevant.tags=relevant.tags, add.abbrev=add.abbrev,
+ tag.names=tag.names, only.checkable=only.checkable)
+
+ if("id" %in% colnames(JS.id)){
+ if(isTRUE(js)){
+ # now
+ # <tag id="my.id" ...>
+ # will become
+ # var my.id = getValue("my.id");
+ result <- paste(result, paste(unlist(sapply(1:nrow(JS.id), function(this.id){
+ return(rk.paste.JS(get.JS.vars(
+ JS.var=JS.id[this.id,"abbrev"],
+ XML.var=JS.id[this.id,"id"],
+ tag.name=JS.id[this.id,"tag"],
+ modifiers=modifiers,
+ append.modifier=append.modifier,
+ guess.getter=guess.getter),
+ level=2, indent.by=indent.by))
+ }, USE.NAMES=FALSE)), collapse="\n"),
+ sep="\n", collapse="\n")
+ } else {
+ result <- c(result, JS.id[,"id"])
+ names(result) <- NULL
+ }
+ } else {}
+ return(result)
+} ## end function check.JS.lines()
diff --git a/packages/rkwarddev/R/rk.JS.scan.R b/packages/rkwarddev/R/rk.JS.scan.R
index 3a381a5..8c31987 100644
--- a/packages/rkwarddev/R/rk.JS.scan.R
+++ b/packages/rkwarddev/R/rk.JS.scan.R
@@ -34,6 +34,39 @@
rk.JS.scan <- function(pXML, js=TRUE, add.abbrev=FALSE, guess.getter=FALSE, indent.by="\t"){
+ # these are tags to scan normally, no special treatment
+ JS.relevant.tags.default <- c("browser", "dropdown", "input", "matrix", "optioncolumn",
+ "radio", "saveobject", "select", "spinbox", "valueslot", "varslot")
+ # these tags should get a default modifier if guess.getter=TRUE
+ if(isTRUE(guess.getter)){
+ JS.relevant.tags.state <- c("checkbox")
+ } else {
+ JS.relevant.tags.state <- c()
+ JS.relevant.tags.default <- c(JS.relevant.tags.default, "checkbox")
+ }
+ # special tags: must be checkable and get "checked" property
+ JS.relevant.tags.checked <- c("frame")
+
+
+ # getting the relevant IDs out of optionsets is a little tricky
+ # this function will probe for sets and return single tags
+ single.tags <- check.optionset.tags(XML.obj=pXML, drop=c("comments","cdata", "declarations", "doctype"))
+
+ # now go through the various cases of XML nodes, appending the results
+ result <- check.JS.lines(relevant.tags=JS.relevant.tags.default, single.tags=single.tags,
+ add.abbrev=add.abbrev, js=js, indent.by=indent.by, guess.getter=guess.getter)
+ result <- check.JS.lines(relevant.tags=JS.relevant.tags.state, single.tags=single.tags,
+ add.abbrev=add.abbrev, js=js, indent.by=indent.by, guess.getter=guess.getter,
+ modifiers="state", append.modifier=FALSE, result=result)
+ result <- check.JS.lines(relevant.tags=JS.relevant.tags.checked, single.tags=single.tags,
+ add.abbrev=add.abbrev, js=js, indent.by=indent.by, guess.getter=guess.getter,
+ modifiers="checked", only.checkable=TRUE, result=result)
+
+ return(result)
+}
+
+rk.JS.scan.old <- function(pXML, js=TRUE, add.abbrev=FALSE, guess.getter=FALSE, indent.by="\t"){
+
JS.relevant.tags <- c("browser", "checkbox", "dropdown", "input", "matrix", "optioncolumn",
"radio", "saveobject", "select", "spinbox", "valueslot", "varslot")
diff --git a/packages/rkwarddev/R/rkwarddev-package.R b/packages/rkwarddev/R/rkwarddev-package.R
index afc4a14..5cb140c 100644
--- a/packages/rkwarddev/R/rkwarddev-package.R
+++ b/packages/rkwarddev/R/rkwarddev-package.R
@@ -4,7 +4,7 @@
#' Package: \tab rkwarddev\cr
#' Type: \tab Package\cr
#' Version: \tab 0.06-6\cr
-#' Date: \tab 2014-12-01\cr
+#' Date: \tab 2014-12-03\cr
#' Depends: \tab R (>= 2.9.0),methods,XiMpLe (>= 0.03-21),rkward (>= 0.5.7)\cr
#' Enhances: \tab rkward\cr
#' Encoding: \tab UTF-8\cr
diff --git a/packages/rkwarddev/man/R.comment.Rd b/packages/rkwarddev/man/R.comment.Rd
index f618751..dd21683 100644
--- a/packages/rkwarddev/man/R.comment.Rd
+++ b/packages/rkwarddev/man/R.comment.Rd
@@ -3,10 +3,10 @@
\alias{R.comment}
\title{Create R comment with JavaScript in RKWard plugin code}
\usage{
-R.comment(message, indent.by = "\\\\t", level = 2, newline = "")
+R.comment(..., indent.by = "\\\\t", level = 2, newline = "")
}
\arguments{
-\item{message}{}
+\item{...}{Character strings to form a comment.}
\item{indent.by}{A character string defining the indentation string to use. Note that
backslashes need to be escaped (e.g. \code{"\\t"} to produce \code{"\t"}).}
diff --git a/packages/rkwarddev/man/rkwarddev-package.Rd b/packages/rkwarddev/man/rkwarddev-package.Rd
index e68a34f..264d756 100644
--- a/packages/rkwarddev/man/rkwarddev-package.Rd
+++ b/packages/rkwarddev/man/rkwarddev-package.Rd
@@ -11,7 +11,7 @@ A collection of tools for RKWard plugin development.
Package: \tab rkwarddev\cr
Type: \tab Package\cr
Version: \tab 0.06-6\cr
-Date: \tab 2014-12-01\cr
+Date: \tab 2014-12-03\cr
Depends: \tab R (>= 2.9.0),methods,XiMpLe (>= 0.03-21),rkward (>= 0.5.7)\cr
Enhances: \tab rkward\cr
Encoding: \tab UTF-8\cr
More information about the rkward-tracker
mailing list