[rkward] packages/rkwarddev: enabled rk.JS.options() to work with js()

m.eik michalke meik.michalke at uni-duesseldorf.de
Mon Nov 23 21:46:21 UTC 2015


Git commit c5b863e83cfa021cf014f4399912bf2736a730a6 by m.eik michalke.
Committed on 23/11/2015 at 21:43.
Pushed by meikm into branch 'master'.

enabled rk.JS.options() to work with js()

  - js() can now return rk.JS.ite objects in a list
  - rk.JS.options() can now take such a list for input

M  +7    -5    packages/rkwarddev/ChangeLog
M  +4    -5    packages/rkwarddev/DESCRIPTION
M  +20   -9    packages/rkwarddev/R/js.R
M  +3    -4    packages/rkwarddev/R/rk.JS.options.R
M  +1    -1    packages/rkwarddev/R/rkwarddev-package.R
M  +21   -6    packages/rkwarddev/demo/skeleton_dialog.R
M  +5    -4    packages/rkwarddev/inst/NEWS.Rd
M  +7    -2    packages/rkwarddev/man/js.Rd
M  +3    -1    packages/rkwarddev/man/rk.JS.options.Rd
M  +3    -1    packages/rkwarddev/man/rk.plugin.skeleton.Rd
M  +1    -1    packages/rkwarddev/man/rkwarddev-package.Rd

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

diff --git a/packages/rkwarddev/ChangeLog b/packages/rkwarddev/ChangeLog
index 9d6a122..e1594c3 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-19)
+changes in version 0.07-4 (2015-11-23)
 unreleased:
   - this version is under development
 fixed:
@@ -14,7 +14,8 @@ fixed:
   - some fixes to the skeleton GUI and demo script
   - prevent internal function indent() from losing it over negative values
   - indentation of rk.paste.JS.graph() was incorrect
-  - pasting comments via rk.paste.JS() gained an extra space for subsequent lines
+  - pasting comments via rk.paste.JS() gained an extra space for subsequent
+    lines
 added:
   - new methods plugin2script() to try to translate raw plugin XML into
     working rkwarddev script calls
@@ -25,7 +26,8 @@ added:
     will be translated to JavaScript equivalents without the need for quoting.
     however, the "for" loop code is not publicly documented and remains a
     proof of concept kind of thing for now
-  - new option ".objects" in id() to provide objects as a list
+  - new option ".objects" in id() and ".ite" in rk.JS.options() to provide objects
+    as a list
   - new option "rk.JS.vars" to make JS variables match the name of the
     original R object
   - new function idq() to print quoted IDs of XML nodes for use in JavaScript
@@ -40,8 +42,8 @@ added:
     "noquote" to have it nested in the JS noquote() function
   - new wrapper function rk.updatePluginMessages() for
     update_plugin_messages.py, the package now comes with its own copy of this core i18n script
-  - the generator info gained support for hinting at the very rkwarddev script file
-    that was used to generate a particular plugin file
+  - the generator info gained support for hinting at the very rkwarddev
+    script file that was used to generate a particular plugin file
 changed:
   - improved error handling in rk.JS.header(), error messages are more
     informative now
diff --git a/packages/rkwarddev/DESCRIPTION b/packages/rkwarddev/DESCRIPTION
index d4cc342..47dc91d 100644
--- a/packages/rkwarddev/DESCRIPTION
+++ b/packages/rkwarddev/DESCRIPTION
@@ -8,16 +8,15 @@ Depends:
 Suggests:
     testthat
 Enhances: rkward
-Description: Provides functions to create plugin skeletons and XML
-    structures for RKWard.
+Description: Provides functions to create plugin skeletons and XML structures
+    for RKWard.
 License: GPL (>= 3)
 Encoding: UTF-8
 LazyLoad: yes
 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", "cph")))
+Authors at R: c(person(given="m.eik", family="michalke", email="meik.michalke at hhu.de", role=c("aut", "cre", "cph")))
 Version: 0.07-4
-Date: 2015-11-19
+Date: 2015-11-23
 RoxygenNote: 5.0.1
 Collate:
     '00_class_01_rk.JS.arr.R'
diff --git a/packages/rkwarddev/R/js.R b/packages/rkwarddev/R/js.R
index 5caed7b..4f88d19 100644
--- a/packages/rkwarddev/R/js.R
+++ b/packages/rkwarddev/R/js.R
@@ -39,7 +39,9 @@
 #' @param linebreaks Logical, should there be line breaks between the elements in this call?
 #' @param empty.e For \code{if} conditions only: Logical, if \code{TRUE} will force to add empty \code{else \{\}} brackets when
 #'    there is no \code{else} statement defined, which is considered to enhance code readability by some.
-#' @return A character string.
+#' @param keep.ite Logical, if \code{TRUE} returns \code{if/else} conditions in a list of objects of class \code{rk.JS.ite} instead
+#'    of a pasted character string. Comes in handy if used inside \code{\link[rkwarddev:rk.JS.options]{rk.JS.options}}.
+#' @return A character string (or \code{rk.JS.ite}, if \code{keep.ite=TRUE} and input is an \code{if/else} condition).
 #' @export
 #' @seealso \code{\link[rkwarddev:rk.JS.vars]{rk.JS.vars}},
 #'    \code{\link[rkwarddev:rk.JS.array]{rk.JS.array}},
@@ -58,7 +60,7 @@
 #'   }
 #' )))
 
-js <- function(..., level=2, indent.by=rk.get.indent(), linebreaks=TRUE, empty.e=rk.get.empty.e()){
+js <- function(..., level=2, indent.by=rk.get.indent(), linebreaks=TRUE, empty.e=rk.get.empty.e(), keep.ite=FALSE){
   full.content <- eval(substitute(alist(...)))
 
   if(isTRUE(linebreaks)){
@@ -79,16 +81,20 @@ js <- function(..., level=2, indent.by=rk.get.indent(), linebreaks=TRUE, empty.e
       if(is.call(this.part)){
         # recursively check for if conditions
         if(inherits(this.part, "if")){
-          this.part <- replaceJSIf(this.part, level=level, indent.by=indent.by, empty.e=empty.e)
+          this.part <- replaceJSIf(this.part, level=level, paste=!keep.ite, indent.by=indent.by, empty.e=empty.e)
         } else {}
         if(inherits(this.part, "for")){
           this.part <- replaceJSFor(this.part, level=level, indent.by=indent.by)
         } else {}
-        if(identical(this.part[[1]], "rk.comment")){
-          return(rk.paste.JS(eval(this.part), level=level, indent.by=indent.by, empty.e=empty.e))
-        } else {}
-        # replace JS operators
-        return(do.call("replaceJSOperators", args=list(this.part)))
+        if(isTRUE(keep.ite)){
+          return(this.part)
+        } else {
+          if(identical(this.part[[1]], "rk.comment")){
+            return(rk.paste.JS(eval(this.part), level=level, indent.by=indent.by, empty.e=empty.e))
+          } else {}
+          # replace JS operators
+          return(do.call("replaceJSOperators", args=list(this.part)))
+        }
       } else if(is.XiMpLe.node(this.part)){
         if(XMLName(this.part) == "!--"){
           return(rk.paste.JS(this.part, level=level, indent.by=indent.by, empty.e=empty.e))
@@ -100,5 +106,10 @@ js <- function(..., level=2, indent.by=rk.get.indent(), linebreaks=TRUE, empty.e
       }
     }
   )
-  return(id(js=TRUE, collapse=collapse, .objects=ID.content))
+  
+  if(isTRUE(keep.ite)){
+    return(ID.content)
+  } else {
+    return(id(js=TRUE, collapse=collapse, .objects=ID.content))
+  }
 }
diff --git a/packages/rkwarddev/R/rk.JS.options.R b/packages/rkwarddev/R/rk.JS.options.R
index 33c2c7d..b741640 100644
--- a/packages/rkwarddev/R/rk.JS.options.R
+++ b/packages/rkwarddev/R/rk.JS.options.R
@@ -33,6 +33,7 @@
 #' @param array Logical, if \code{TRUE} will generate the options as an array, otherwise in one
 #'    concatenated character string (probably only useful for mandatory options).
 #' @param opt.sep Character string, will be printed in the resulting R code before the option name.
+#' @param .ite Like \code{...}, if you have all objects in a list already.
 #' @return An object of class \code{rk.JS.opt}, use \code{\link[rkwarddev:rk.paste.JS]{rk.paste.JS}}
 #'    on that.
 #' @seealso
@@ -49,9 +50,7 @@
 #'   ite(checkB, "fast=TRUE")
 #' )
 
-rk.JS.options <- function(var, ..., collapse=", ", option=NULL, funct=NULL, array=TRUE, opt.sep=", "){
-  all.opts <- list(...)
-
+rk.JS.options <- function(var, ..., collapse=", ", option=NULL, funct=NULL, array=TRUE, opt.sep=", ", .ite=list(...)){
   if(is.null(option)){
     option <- ""
   } else {}
@@ -63,7 +62,7 @@ rk.JS.options <- function(var, ..., collapse=", ", option=NULL, funct=NULL, arra
     var.name=var,
     opt.name=option,
     collapse=collapse,
-    ifs=all.opts,
+    ifs=.ite,
     array=array,
     funct=funct,
     opt.sep=opt.sep
diff --git a/packages/rkwarddev/R/rkwarddev-package.R b/packages/rkwarddev/R/rkwarddev-package.R
index 0f08724..8e877b4 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-19\cr
+#' Date: \tab 2015-11-23\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/demo/skeleton_dialog.R b/packages/rkwarddev/demo/skeleton_dialog.R
index d1bc5e7..7ba5093 100644
--- a/packages/rkwarddev/demo/skeleton_dialog.R
+++ b/packages/rkwarddev/demo/skeleton_dialog.R
@@ -267,12 +267,27 @@ logic.section <- rk.XML.logic(
 ## JS code generation
 # about section
 js.opt.about.about <- rk.JS.options("optAbout",
-  ite(pluginDescription, qp("desc=\"",pluginDescription,"\"")),
-  ite(pluginVersion, qp("version=\"",pluginVersion,"\"")),
-  ite(pluginDate, qp("date=\"",pluginDate,"\"")),
-  ite(pluginHomepage, qp("url=\"",pluginHomepage,"\"")),
-  ite(pluginLicense, qp("license=\"",pluginLicense,"\"")),
-  ite(pluginCategory, qp("category=\"",pluginCategory,"\"")),
+  .ite=js(
+    if(pluginDescription){
+      qp("desc=\"",pluginDescription,"\"")
+    } else {},
+    if(pluginVersion){
+      qp("version=\"",pluginVersion,"\"")
+    } else {},
+    if(pluginDate){
+      qp("date=\"",pluginDate,"\"")
+    } else {},
+    if(pluginHomepage){
+      qp("url=\"",pluginHomepage,"\"")
+    } else {},
+    if(pluginLicense){
+      qp("license=\"",pluginLicense,"\"")
+    } else {},
+    if(pluginCategory){
+      qp("category=\"",pluginCategory,"\"")
+    } else {},
+    keep.ite=TRUE
+  ),
   funct="list", option="about", collapse=",\\n\\t")
 # dependencies section
 js.frm.dependencyFrame <- rk.JS.vars(dependencyFrame, modifiers="checked") # see to it frame is checked
diff --git a/packages/rkwarddev/inst/NEWS.Rd b/packages/rkwarddev/inst/NEWS.Rd
index 47eb8dc..16ee376 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-19)}{
+\section{Changes in rkwarddev version 0.07-4 (2015-11-23)}{
   \subsection{unreleased}{
     \itemize{
       \item this version is under development
@@ -19,7 +19,8 @@
       \item some fixes to the skeleton GUI and demo script
       \item prevent internal function \code{indent()} from losing it over negative values
       \item indentation of \code{rk.paste.JS.graph()} was incorrect
-      \item pasting comments via \code{rk.paste.JS()} gained an extra space for subsequent lines
+      \item pasting comments via \code{rk.paste.JS()} gained an extra space for subsequent
+        lines
     }
   }
   \subsection{added}{
@@ -48,8 +49,8 @@
         \code{"noquote"} to have it nested in the JS \code{noquote()} function
       \item new wrapper function \code{rk.updatePluginMessages()} for
         update_plugin_messages.py, the package now comes with its own copy of this core i18n script
-      \item the generator info gained support for hinting at the very rkwarddev script file
-        that was used to generate a particular plugin file
+      \item the generator info gained support for hinting at the very rkwarddev
+        script file that was used to generate a particular plugin file
     }
   }
   \subsection{changed}{
diff --git a/packages/rkwarddev/man/js.Rd b/packages/rkwarddev/man/js.Rd
index 3b38132..e718ca9 100644
--- a/packages/rkwarddev/man/js.Rd
+++ b/packages/rkwarddev/man/js.Rd
@@ -5,7 +5,7 @@
 \title{R to JavaScript translation}
 \usage{
 js(..., level = 2, indent.by = rk.get.indent(), linebreaks = TRUE,
-  empty.e = rk.get.empty.e())
+  empty.e = rk.get.empty.e(), keep.ite = FALSE)
 }
 \arguments{
 \item{...}{One or several character strings and/or \code{XiMpLe.node} objects with plugin nodes,
@@ -22,9 +22,14 @@ JavaScript operators and \code{if} conditions will be kept as-is.}
       if \code{TRUE} will force to add empty \code{else \{\}} brackets when
 there is no \code{else} statement defined,
       which is considered to enhance code readability by some.}
+
+\item{keep.ite}{Logical,
+      if \code{TRUE} returns \code{if/else} conditions in a list of objects of class \code{rk.JS.ite} instead
+of a pasted character string. Comes in handy if used inside \code{\link[rkwarddev:rk.JS.options]{rk.JS.options}}.}
 }
 \value{
-A character string.
+A character string (or \code{rk.JS.ite},
+      if \code{keep.ite=TRUE} and input is an \code{if/else} condition).
 }
 \description{
 This function is a wrapper for \code{\link[rkwarddev:id]{id}} similar to \code{\link[rkwarddev:qp]{qp}}
diff --git a/packages/rkwarddev/man/rk.JS.options.Rd b/packages/rkwarddev/man/rk.JS.options.Rd
index ec38736..49f4896 100644
--- a/packages/rkwarddev/man/rk.JS.options.Rd
+++ b/packages/rkwarddev/man/rk.JS.options.Rd
@@ -5,7 +5,7 @@
 \title{Combine several options in one JavaScript variable}
 \usage{
 rk.JS.options(var, ..., collapse = ", ", option = NULL, funct = NULL,
-  array = TRUE, opt.sep = ", ")
+  array = TRUE, opt.sep = ", ", .ite = list(...))
 }
 \arguments{
 \item{var}{Character string, name of the JavaScript variable to use in the script code.}
@@ -34,6 +34,8 @@ concatenated character string (probably only useful for mandatory options).}
 
 \item{opt.sep}{Character string,
       will be printed in the resulting R code before the option name.}
+
+\item{.ite}{Like \code{...}, if you have all objects in a list already.}
 }
 \value{
 An object of class \code{rk.JS.opt}, use \code{\link[rkwarddev:rk.paste.JS]{rk.paste.JS}}
diff --git a/packages/rkwarddev/man/rk.plugin.skeleton.Rd b/packages/rkwarddev/man/rk.plugin.skeleton.Rd
index b22f23d..a404e14 100644
--- a/packages/rkwarddev/man/rk.plugin.skeleton.Rd
+++ b/packages/rkwarddev/man/rk.plugin.skeleton.Rd
@@ -126,7 +126,9 @@ it was loaded (i.e.,
 
 \item{gen.info}{Logical,
       if \code{TRUE} comment notes will be written into the genrated documents,
-that they were generated by \code{rkwarddev} and changes should be done to the script.}
+that they were generated by \code{rkwarddev} and changes should be done to the script.
+You can also provide a character string naming the very rkwarddev script file that generates this plugin and its main component,
+which will then also be added to the comment.}
 
 \item{hints}{Logical,
       if \code{TRUE} and you leave out optional entries (like \code{dependencies=NULL}), dummy sections will be added as comments.}
diff --git a/packages/rkwarddev/man/rkwarddev-package.Rd b/packages/rkwarddev/man/rkwarddev-package.Rd
index 49f3945..2dd2eba 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-19\cr
+Date: \tab 2015-11-23\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