[rkward] packages/rkwarddev: rewrote idq() to also work in XML context

m.eik michalke meik.michalke at uni-duesseldorf.de
Wed Nov 11 14:38:28 UTC 2015


Git commit bd9c8afd4c8eb3027e9e6f363c635b6d7310d1e2 by m.eik michalke.
Committed on 11/11/2015 at 14:39.
Pushed by meikm into branch 'master'.

rewrote idq() to also work in XML context

  - i figured it's much cheaper to leave it to id()

M  +6    -5    packages/rkwarddev/ChangeLog
M  +1    -1    packages/rkwarddev/DESCRIPTION
M  +12   -12   packages/rkwarddev/R/idq.R
M  +1    -0    packages/rkwarddev/R/rk-internal.R
M  +1    -1    packages/rkwarddev/R/rk.JS.header.R
M  +1    -1    packages/rkwarddev/R/rkwarddev-package.R
M  +6    -5    packages/rkwarddev/inst/NEWS.Rd
M  +13   -2    packages/rkwarddev/man/idq.Rd
M  +1    -1    packages/rkwarddev/man/rkwarddev-package.Rd

http://commits.kde.org/rkward/bd9c8afd4c8eb3027e9e6f363c635b6d7310d1e2

diff --git a/packages/rkwarddev/ChangeLog b/packages/rkwarddev/ChangeLog
index be53fe4..304ebb6 100644
--- a/packages/rkwarddev/ChangeLog
+++ b/packages/rkwarddev/ChangeLog
@@ -1,6 +1,6 @@
 ChangeLog for package rkwarddev
 
-changes in version 0.07-4 (2015-11-10)
+changes in version 0.07-4 (2015-11-11)
 unreleased:
   - this version is under development
 fixed:
@@ -31,8 +31,8 @@ added:
     sections
   - new function modifiers() to make checking for valid mdifiers of a given
     node easier
-  - new functions rk.get.indent() and rk.set.indent() to globally set indentation
-    string
+  - new functions rk.get.indent() and rk.set.indent() to globally set
+    indentation string
 changed:
   - improved error handling in rk.JS.header(), error messages are more
     informative now
@@ -40,8 +40,9 @@ changed:
   - updated the vignette with information on js() and how to add help pages
   - internal function modif.validity() now calls modifiers() to give more
     useful feedback
-  - all functions offering "intent.by" as an option now fetch the default value
-    by calling rk.get.indent()
+  - all functions offering "intent.by" as an option now fetch the default
+    value by calling rk.get.indent()
+  - removed trailing newline in rk.JS.header() output
 
 changes in version 0.07-3 (2015-06-29)
 fixed:
diff --git a/packages/rkwarddev/DESCRIPTION b/packages/rkwarddev/DESCRIPTION
index ba3fef1..d127189 100644
--- a/packages/rkwarddev/DESCRIPTION
+++ b/packages/rkwarddev/DESCRIPTION
@@ -17,7 +17,7 @@ URL: https://rkward.kde.org
 Authors at R: c(person(given="m.eik", family="michalke",
         email="meik.michalke at hhu.de", role=c("aut", "cre")))
 Version: 0.07-4
-Date: 2015-11-10
+Date: 2015-11-11
 RoxygenNote: 5.0.0
 Collate:
     '00_class_01_rk.JS.arr.R'
diff --git a/packages/rkwarddev/R/idq.R b/packages/rkwarddev/R/idq.R
index 4736e6b..8d007a4 100644
--- a/packages/rkwarddev/R/idq.R
+++ b/packages/rkwarddev/R/idq.R
@@ -17,7 +17,7 @@
 
 #' Get a quoted element ID
 #' 
-#' This is actually a convenience wrapper for \code{\link[rkwarddev:rk.JS.vars]{rk.JS.vars}}
+#' This is actually a convenience wrapper for \code{\link[rkwarddev:id]{id}}
 #' and returns the XML ID of XiMpLe nodes in quoted format, optionally with an attached modifier.
 #' 
 #' You can use this function to write almost literal JavaScript code, but still be able to extract IDs from
@@ -30,23 +30,23 @@
 #' @param modifiers A character vector with modifiers you'd like to apply to the XML node property.
 #' @param check.modifiers Logical, if \code{TRUE} the given modifiers will be checked for validity. Should only be
 #'    turned off if you know what you're doing.
+#' @param js Logical, if \code{TRUE} returns JavaScript varaible names for \code{XiMpLe.node} objects.
+#'    Otherwise their actual ID is returned.
+#' @param quote Character string to be used for quoting.
 #' @return A character string.
 #' @export
-#' @expamples
+#' @examples
 #' myCheckbox <- rk.XML.cbox("Check for action")
 #' rk.paste.JS(id("var x = getBoolean(", idq(myCheckbox, modifiers="state"), ");"))
 
-idq <- function(obj, modifiers=NULL, check.modifiers=TRUE, quote="\""){
-  # first give the object to rk.JS.vars(), as this already does all the modifier checking magic etc.
-  # rk.JS.vars() should return the variable object in the vars slot as a one item list
-  varObj <- slot(rk.JS.vars(obj, modifiers=modifiers, check.modifiers=check.modifiers), "vars")[[1]]
-  obj.XML.var <- slot(varObj, "XML.var")
-  obj.modifiers <- slot(varObj, "modifiers")
-  
-  result <- paste0(quote, slot(varObj, "XML.var"))
+idq <- function(obj, modifiers=NULL, check.modifiers=TRUE, js=TRUE, quote="\""){
+  result <- paste0(quote, id(obj, js=js))
 
-  if(length(obj.modifiers) > 0){
-    result <- paste0(result, ".", paste0(unlist(obj.modifiers), collapse="."), quote)
+  if(length(modifiers) > 0){
+    if(isTRUE(check.modifiers)){
+      modifiers <- modif.validity(source=obj, modifier=modifiers, bool=FALSE)
+    } else {}
+    result <- paste0(result, ".", paste0(unlist(modifiers), collapse="."), quote)
   } else {
     result <- paste0(result, quote)
   }
diff --git a/packages/rkwarddev/R/rk-internal.R b/packages/rkwarddev/R/rk-internal.R
index 5e16126..d8fc433 100644
--- a/packages/rkwarddev/R/rk-internal.R
+++ b/packages/rkwarddev/R/rk-internal.R
@@ -641,6 +641,7 @@ check.ID <- function(node, search.environment=FALSE, env.get="XML"){
 ## function modif.validity()
 # checks if a modifier is valid for an XML node, if source is XiMpLe.node
 # if bool=FALSE, returns the modifier or ""
+# modifier can take multiple modifiers at once
 modif.validity <- function(source, modifier, ignore.empty=TRUE, warn.only=TRUE, bool=TRUE){
   if(identical(modifier, "") & isTRUE(ignore.empty)){
     if(isTRUE(bool)){
diff --git a/packages/rkwarddev/R/rk.JS.header.R b/packages/rkwarddev/R/rk.JS.header.R
index 112ddd0..1481c5f 100644
--- a/packages/rkwarddev/R/rk.JS.header.R
+++ b/packages/rkwarddev/R/rk.JS.header.R
@@ -85,7 +85,7 @@ rk.JS.header <- function(title, ..., level=NULL, guess.getter=FALSE, .add=list()
     },
     ")",
     addToHeaderChar,
-    ".print();\n"
+    ".print();"
   )
 
   return(result)
diff --git a/packages/rkwarddev/R/rkwarddev-package.R b/packages/rkwarddev/R/rkwarddev-package.R
index e0f6d8d..fc0e2b2 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.07-4\cr
-#' Date: \tab 2015-11-10\cr
+#' Date: \tab 2015-11-11\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/inst/NEWS.Rd b/packages/rkwarddev/inst/NEWS.Rd
index 68abe89..9b8b1ef 100644
--- a/packages/rkwarddev/inst/NEWS.Rd
+++ b/packages/rkwarddev/inst/NEWS.Rd
@@ -1,7 +1,7 @@
 \name{NEWS}
 \title{News for Package 'rkwarddev'}
 \encoding{UTF-8}
-\section{Changes in rkwarddev version 0.07-4 (2015-11-10)}{
+\section{Changes in rkwarddev version 0.07-4 (2015-11-11)}{
   \subsection{unreleased}{
     \itemize{
       \item this version is under development
@@ -39,8 +39,8 @@
         sections
       \item new function \code{modifiers()} to make checking for valid mdifiers of a given
         node easier
-      \item new functions \code{rk.get.indent()} and \code{rk.set.indent()} to globally set indentation
-        string
+      \item new functions \code{rk.get.indent()} and \code{rk.set.indent()} to globally set
+        indentation string
     }
   }
   \subsection{changed}{
@@ -51,8 +51,9 @@
       \item updated the vignette with information on \code{js()} and how to add help pages
       \item internal function \code{modif.validity()} now calls \code{modifiers()} to give more
         useful feedback
-      \item all functions offering \code{"intent.by"} as an option now fetch the default value
-        by calling \code{rk.get.indent()}
+      \item all functions offering \code{"intent.by"} as an option now fetch the default
+        value by calling \code{rk.get.indent()}
+      \item removed trailing newline in \code{rk.JS.header()} output
     }
   }
 }
diff --git a/packages/rkwarddev/man/idq.Rd b/packages/rkwarddev/man/idq.Rd
index 65bd781..7805abe 100644
--- a/packages/rkwarddev/man/idq.Rd
+++ b/packages/rkwarddev/man/idq.Rd
@@ -4,7 +4,8 @@
 \alias{idq}
 \title{Get a quoted element ID}
 \usage{
-idq(obj, modifiers = NULL, check.modifiers = TRUE, quote = "\\"")
+idq(obj, modifiers = NULL, check.modifiers = TRUE, js = TRUE,
+  quote = "\\"")
 }
 \arguments{
 \item{obj}{An object of class \code{XiMpLe.node} containig an ID to extract.}
@@ -14,12 +15,18 @@ idq(obj, modifiers = NULL, check.modifiers = TRUE, quote = "\\"")
 \item{check.modifiers}{Logical,
       if \code{TRUE} the given modifiers will be checked for validity. Should only be
 turned off if you know what you're doing.}
+
+\item{js}{Logical,
+      if \code{TRUE} returns JavaScript varaible names for \code{XiMpLe.node} objects.
+Otherwise their actual ID is returned.}
+
+\item{quote}{Character string to be used for quoting.}
 }
 \value{
 A character string.
 }
 \description{
-This is actually a convenience wrapper for \code{\link[rkwarddev:rk.JS.vars]{rk.JS.vars}}
+This is actually a convenience wrapper for \code{\link[rkwarddev:id]{id}}
 and returns the XML ID of XiMpLe nodes in quoted format,
       optionally with an attached modifier.
 }
@@ -32,4 +39,8 @@ generated R objects.
 You should always nest this function inside an \code{\link[rkwarddev:id]{id}} call (or a similar wrapper)
   to prevent \code{rk.paste.JS} from appending newline characters -- see the example section.
 }
+\examples{
+myCheckbox <- rk.XML.cbox("Check for action")
+rk.paste.JS(id("var x = getBoolean(", idq(myCheckbox, modifiers="state"), ");"))
+}
 
diff --git a/packages/rkwarddev/man/rkwarddev-package.Rd b/packages/rkwarddev/man/rkwarddev-package.Rd
index 2d49f41..91e4747 100644
--- a/packages/rkwarddev/man/rkwarddev-package.Rd
+++ b/packages/rkwarddev/man/rkwarddev-package.Rd
@@ -12,7 +12,7 @@ A Collection of Tools for RKWard Plugin Development.
 Package: \tab rkwarddev\cr
 Type: \tab Package\cr
 Version: \tab 0.07-4\cr
-Date: \tab 2015-11-10\cr
+Date: \tab 2015-11-11\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