[rkward] packages/rkwarddev: globally define empte.e and corrected spacing in JS code
m.eik michalke
meik.michalke at uni-duesseldorf.de
Sat Nov 14 23:43:05 UTC 2015
Git commit 9971dccdefd448c8790be6649a6378c9e49ffae0 by m.eik michalke.
Committed on 14/11/2015 at 23:41.
Pushed by meikm into branch 'master'.
globally define empte.e and corrected spacing in JS code
- new functions rk.set.empty.e() and rk.get.empty.e() to define "empte.e" parameter globally
- made all functions that offer "empte.e" compatible to the global setting
- small thing: removed some superfluous newlines in rk.JS.doc() generated code
M +4 -0 packages/rkwarddev/ChangeLog
M +2 -0 packages/rkwarddev/DESCRIPTION
M +2 -0 packages/rkwarddev/NAMESPACE
M +1 -1 packages/rkwarddev/R/js.R
M +11 -2 packages/rkwarddev/R/rk-internal.R
M +4 -4 packages/rkwarddev/R/rk.JS.doc.R
C +3 -16 packages/rkwarddev/R/rk.get.empty.e.R [from: packages/rkwarddev/R/rk.set.indent.R - 050% similarity]
M +1 -1 packages/rkwarddev/R/rk.paste.JS.R
M +1 -1 packages/rkwarddev/R/rk.paste.JS.graph.R
C +10 -12 packages/rkwarddev/R/rk.set.empty.e.R [from: packages/rkwarddev/R/rk.set.indent.R - 052% similarity]
M +1 -3 packages/rkwarddev/R/rk.set.indent.R
M +4 -0 packages/rkwarddev/inst/NEWS.Rd
M +1 -1 packages/rkwarddev/man/js.Rd
M +1 -1 packages/rkwarddev/man/rk.paste.JS.Rd
M +1 -1 packages/rkwarddev/man/rk.paste.JS.graph.Rd
A +27 -0 packages/rkwarddev/man/rk.set.empty.e.Rd
http://commits.kde.org/rkward/9971dccdefd448c8790be6649a6378c9e49ffae0
diff --git a/packages/rkwarddev/ChangeLog b/packages/rkwarddev/ChangeLog
index 825ca4f..54461bd 100644
--- a/packages/rkwarddev/ChangeLog
+++ b/packages/rkwarddev/ChangeLog
@@ -33,6 +33,8 @@ added:
node easier
- new functions rk.get.indent() and rk.set.indent() to globally set
indentation string
+ - new functions rk.get.empty.e() and rk.set.empty.e() to globally define
+ the handling of empty "else" clauses in JavaScript
- in rk.JS.header(), the second value provided by "add" can now be named
"noquote" to have it nested in the JS noquote() function
changed:
@@ -44,6 +46,8 @@ changed:
useful feedback
- all functions offering "intent.by" as an option now fetch the default
value by calling rk.get.indent()
+ - all functions offering "empty.e" as an option now fetch the default
+ value by calling rk.get.empty.e()
- removed trailing newline in rk.JS.header() output
changes in version 0.07-3 (2015-06-29)
diff --git a/packages/rkwarddev/DESCRIPTION b/packages/rkwarddev/DESCRIPTION
index 21b3ea9..053bcea 100644
--- a/packages/rkwarddev/DESCRIPTION
+++ b/packages/rkwarddev/DESCRIPTION
@@ -110,6 +110,7 @@ Collate:
'rk.XML.wizard.R'
'rk.build.plugin.R'
'rk.get.comp.R'
+ 'rk.get.empty.e.R'
'rk.get.indent.R'
'rk.get.rkh.prompter.R'
'rk.i18n.comment.R'
@@ -131,6 +132,7 @@ Collate:
'rk.rkh.title.R'
'rk.rkh.usage.R'
'rk.set.comp.R'
+ 'rk.set.empty.e.R'
'rk.set.indent.R'
'rk.set.rkh.prompter.R'
'rk.testsuite.doc.R'
diff --git a/packages/rkwarddev/NAMESPACE b/packages/rkwarddev/NAMESPACE
index 9bc0d25..df509ce 100644
--- a/packages/rkwarddev/NAMESPACE
+++ b/packages/rkwarddev/NAMESPACE
@@ -81,6 +81,7 @@ export(rk.XML.wizard)
export(rk.build.plugin)
export(rk.comment)
export(rk.get.comp)
+export(rk.get.empty.e)
export(rk.get.indent)
export(rk.get.rkh.prompter)
export(rk.i18n.comment)
@@ -103,6 +104,7 @@ export(rk.rkh.technical)
export(rk.rkh.title)
export(rk.rkh.usage)
export(rk.set.comp)
+export(rk.set.empty.e)
export(rk.set.indent)
export(rk.set.rkh.prompter)
export(rk.testsuite.doc)
diff --git a/packages/rkwarddev/R/js.R b/packages/rkwarddev/R/js.R
index 741a07b..5caed7b 100644
--- a/packages/rkwarddev/R/js.R
+++ b/packages/rkwarddev/R/js.R
@@ -58,7 +58,7 @@
#' }
#' )))
-js <- function(..., level=2, indent.by=rk.get.indent(), linebreaks=TRUE, empty.e=FALSE){
+js <- function(..., level=2, indent.by=rk.get.indent(), linebreaks=TRUE, empty.e=rk.get.empty.e()){
full.content <- eval(substitute(alist(...)))
if(isTRUE(linebreaks)){
diff --git a/packages/rkwarddev/R/rk-internal.R b/packages/rkwarddev/R/rk-internal.R
index 37c4e13..4d440ad 100644
--- a/packages/rkwarddev/R/rk-internal.R
+++ b/packages/rkwarddev/R/rk-internal.R
@@ -104,6 +104,15 @@ trim <- function(char){
} ## end function trim()
+## function trim.n()
+# cuts off newline at start and end of a character string
+trim.n <- function(char){
+ char <- gsub("^([\n]*)", "", char)
+ char <- gsub("([\n]*)$", "", char)
+ return(char)
+} ## end function trim.n()
+
+
## function indent()
# will create tabs to format the output
indent <- function(level, by=rk.get.indent()){
@@ -815,7 +824,7 @@ clean.name <- function(name, message=TRUE){
## function paste.JS.ite()
-paste.JS.ite <- function(object, level=1, indent.by=rk.get.indent(), recurse=FALSE, empty.e=FALSE){
+paste.JS.ite <- function(object, level=1, indent.by=rk.get.indent(), recurse=FALSE, empty.e=rk.get.empty.e()){
stopifnot(inherits(object, "rk.JS.ite"))
# check indentation
main.indent <- indent(level, by=indent.by)
@@ -1548,7 +1557,7 @@ uncurl <- function(cond, level=1, indent.by=rk.get.indent()){
## function replaceJSIf
-replaceJSIf <- function(cond, level=1, paste=TRUE, indent.by=rk.get.indent(), empty.e=FALSE){
+replaceJSIf <- function(cond, level=1, paste=TRUE, indent.by=rk.get.indent(), empty.e=rk.get.empty.e()){
if(inherits(cond, "if")){
# if condition -- should be save to give to js()
cond.if <- do.call(
diff --git a/packages/rkwarddev/R/rk.JS.doc.R b/packages/rkwarddev/R/rk.JS.doc.R
index 3141d4a..50285dc 100644
--- a/packages/rkwarddev/R/rk.JS.doc.R
+++ b/packages/rkwarddev/R/rk.JS.doc.R
@@ -90,7 +90,7 @@ rk.JS.doc <- function(require=c(), variables=NULL, globals=NULL, results.header=
if(!is.null(globals)){
js.globals <- paste0(
"// define variables globally\n",
- paste0(globals, collapse=""))
+ trim.n(paste0(globals, collapse="")))
if(!is.null(variables)){
# remove globals from variables, if duplicate
# we'll split them by semicolon
@@ -124,7 +124,7 @@ rk.JS.doc <- function(require=c(), variables=NULL, globals=NULL, results.header=
js.preprocess <- paste0("function preprocess(){\n",
ifelse(isTRUE(addSetGlobalVars), paste0(indent(2, by=indent.by), "setGlobalVars();\n"), ""),
indent(2, by=indent.by), "// add requirements etc. here\n",
- paste(js.require, collapse=""),
+ trim.n(paste(js.require, collapse="")),
"\n",
ifelse(is.null(preprocess), "", paste0("\n", preprocess, "\n")),
"}")
@@ -134,7 +134,7 @@ rk.JS.doc <- function(require=c(), variables=NULL, globals=NULL, results.header=
if(is.null(doPrintout) | !is.null(calculate)){paste0(
ifelse(is.null(variables), "", paste0(
indent(2, by=indent.by), "// read in variables from dialog\n",
- paste(variables, collapse=""), "\n\n")),
+ trim.n(paste(variables, collapse="")), "\n\n")),
ifelse(is.null(calculate),
paste0(indent(2, by=indent.by), "// generate the R code to be evaluated here\n"),
paste0(indent(2, by=indent.by), "// the R code to be evaluated\n",calculate, "\n")))
@@ -172,7 +172,7 @@ rk.JS.doc <- function(require=c(), variables=NULL, globals=NULL, results.header=
"function doPrintout(full){\n",
ifelse(is.null(variables), "", paste0(
indent(2, by=indent.by), "// read in variables from dialog\n",
- paste(variables, collapse=""), "\n\n")),
+ trim.n(paste(variables, collapse="")), "\n\n")),
indent(2, by=indent.by), "// create the plot\n",
if(is.character(results.header) && !identical(results.header, "")){
rk.paste.JS(ite("full", rk.JS.header(results.header, guess.getter=guess.getter, .add=header.add)))
diff --git a/packages/rkwarddev/R/rk.set.indent.R b/packages/rkwarddev/R/rk.get.empty.e.R
similarity index 50%
copy from packages/rkwarddev/R/rk.set.indent.R
copy to packages/rkwarddev/R/rk.get.empty.e.R
index e5843d4..ec8aec7 100644
--- a/packages/rkwarddev/R/rk.set.indent.R
+++ b/packages/rkwarddev/R/rk.get.empty.e.R
@@ -15,22 +15,9 @@
# You should have received a copy of the GNU General Public License
# along with rkwarddev. If not, see <http://www.gnu.org/licenses/>.
-#' Globally define the indentation string
-#'
-#' Many functions allow to manually set the indentation string that should be used
-#' for code formatting. The default string used can be globally defined with \code{rk.set.indent},
-#' so you don't have to specify it in each function call.
-#'
-#' \code{rk.get.indent} returns the set value, which defaults to a tab character by default.
-#'
-#' @param by Character string, indentation string to be defined globally.
-#' @return \code{rk.set.indent} returns invisible(NULL), \code{rk.get.indent} a character string.
-#' @rdname rk.set.indent
+#' @rdname rk.set.empty.e
#' @export
-rk.set.indent <- function(by="\t"){
- indent.by <- rk.get.indent()
- indent.by <- by
- set.rk.env("indent.by", value=indent.by)
- return(invisible(NULL))
+rk.get.empty.e <- function(){
+ return(get.rk.env("empty.e", value=FALSE))
}
diff --git a/packages/rkwarddev/R/rk.paste.JS.R b/packages/rkwarddev/R/rk.paste.JS.R
index 616c9ee..6308312 100644
--- a/packages/rkwarddev/R/rk.paste.JS.R
+++ b/packages/rkwarddev/R/rk.paste.JS.R
@@ -65,7 +65,7 @@
#' @export
rk.paste.JS <- function(..., level=2, indent.by=rk.get.indent(), funct=NULL, array=NULL,
- var.prefix=NULL, modifiers=NULL, default=NULL, join=NULL, getter=NULL, var=TRUE, empty.e=FALSE,
+ var.prefix=NULL, modifiers=NULL, default=NULL, join=NULL, getter=NULL, var=TRUE, empty.e=rk.get.empty.e(),
opt.sep=NULL){
stopifnot(level > 0)
all.objects <- list(...)
diff --git a/packages/rkwarddev/R/rk.paste.JS.graph.R b/packages/rkwarddev/R/rk.paste.JS.graph.R
index 48a4d78..58d54cc 100644
--- a/packages/rkwarddev/R/rk.paste.JS.graph.R
+++ b/packages/rkwarddev/R/rk.paste.JS.graph.R
@@ -55,7 +55,7 @@
#' plotOpts=tmp.plot.options)
#'
#' cat(js.prnt)
-rk.paste.JS.graph <- function(..., plotOpts=NULL, printoutObj=NULL, level=2, indent.by=rk.get.indent(), empty.e=FALSE){
+rk.paste.JS.graph <- function(..., plotOpts=NULL, printoutObj=NULL, level=2, indent.by=rk.get.indent(), empty.e=rk.get.empty.e()){
plotOptsIndent <- paste(rep(rk.get.indent(escape=TRUE), level), collapse="")
diff --git a/packages/rkwarddev/R/rk.set.indent.R b/packages/rkwarddev/R/rk.set.empty.e.R
similarity index 52%
copy from packages/rkwarddev/R/rk.set.indent.R
copy to packages/rkwarddev/R/rk.set.empty.e.R
index e5843d4..eeab198 100644
--- a/packages/rkwarddev/R/rk.set.indent.R
+++ b/packages/rkwarddev/R/rk.set.empty.e.R
@@ -15,22 +15,20 @@
# You should have received a copy of the GNU General Public License
# along with rkwarddev. If not, see <http://www.gnu.org/licenses/>.
-#' Globally define the indentation string
+#' Globally define handling of empty else conditions in JS
#'
-#' Many functions allow to manually set the indentation string that should be used
-#' for code formatting. The default string used can be globally defined with \code{rk.set.indent},
-#' so you don't have to specify it in each function call.
+#' Some JS functions allow to decide whether empty \code{else} statements should be omitted or printed
+#' nonetheless (which some consider more reader friendly). The default can be globally defined with
+#' \code{rk.set.empty.e}, so you don't have to specify it in each function call.
#'
-#' \code{rk.get.indent} returns the set value, which defaults to a tab character by default.
+#' \code{rk.get.empty.e} returns the set value, which defaults to \code{FALSE} by default.
#'
-#' @param by Character string, indentation string to be defined globally.
-#' @return \code{rk.set.indent} returns invisible(NULL), \code{rk.get.indent} a character string.
-#' @rdname rk.set.indent
+#' @param empty Logical, whether .
+#' @return \code{rk.set.empty.e} returns invisible(NULL), \code{rk.get.empty.e} either \code{TRUE} or \code{FALSE}.
+#' @rdname rk.set.empty.e
#' @export
-rk.set.indent <- function(by="\t"){
- indent.by <- rk.get.indent()
- indent.by <- by
- set.rk.env("indent.by", value=indent.by)
+rk.set.empty.e <- function(empty=FALSE){
+ set.rk.env("empty.e", value=empty)
return(invisible(NULL))
}
diff --git a/packages/rkwarddev/R/rk.set.indent.R b/packages/rkwarddev/R/rk.set.indent.R
index e5843d4..f8cddc4 100644
--- a/packages/rkwarddev/R/rk.set.indent.R
+++ b/packages/rkwarddev/R/rk.set.indent.R
@@ -29,8 +29,6 @@
#' @export
rk.set.indent <- function(by="\t"){
- indent.by <- rk.get.indent()
- indent.by <- by
- set.rk.env("indent.by", value=indent.by)
+ set.rk.env("indent.by", value=by)
return(invisible(NULL))
}
diff --git a/packages/rkwarddev/inst/NEWS.Rd b/packages/rkwarddev/inst/NEWS.Rd
index 363b4f0..6e34a67 100644
--- a/packages/rkwarddev/inst/NEWS.Rd
+++ b/packages/rkwarddev/inst/NEWS.Rd
@@ -41,6 +41,8 @@
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.empty.e()} and \code{rk.set.empty.e()} to globally define
+ the handling of empty \code{"else"} clauses in JavaScript
\item in \code{rk.JS.header()}, the second value provided by \code{"add"} can now be named
\code{"noquote"} to have it nested in the JS \code{noquote()} function
}
@@ -55,6 +57,8 @@
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{"empty.e"} as an option now fetch the default
+ value by calling \code{rk.get.empty.e()}
\item removed trailing newline in \code{rk.JS.header()} output
}
}
diff --git a/packages/rkwarddev/man/js.Rd b/packages/rkwarddev/man/js.Rd
index 99f9453..3b38132 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 = FALSE)
+ empty.e = rk.get.empty.e())
}
\arguments{
\item{...}{One or several character strings and/or \code{XiMpLe.node} objects with plugin nodes,
diff --git a/packages/rkwarddev/man/rk.paste.JS.Rd b/packages/rkwarddev/man/rk.paste.JS.Rd
index 63c1a8b..bd3cf81 100644
--- a/packages/rkwarddev/man/rk.paste.JS.Rd
+++ b/packages/rkwarddev/man/rk.paste.JS.Rd
@@ -6,7 +6,7 @@
\usage{
rk.paste.JS(..., level = 2, indent.by = rk.get.indent(), funct = NULL,
array = NULL, var.prefix = NULL, modifiers = NULL, default = NULL,
- join = NULL, getter = NULL, var = TRUE, empty.e = FALSE,
+ join = NULL, getter = NULL, var = TRUE, empty.e = rk.get.empty.e(),
opt.sep = NULL)
}
\arguments{
diff --git a/packages/rkwarddev/man/rk.paste.JS.graph.Rd b/packages/rkwarddev/man/rk.paste.JS.graph.Rd
index 5265532..ee3eb20 100644
--- a/packages/rkwarddev/man/rk.paste.JS.graph.Rd
+++ b/packages/rkwarddev/man/rk.paste.JS.graph.Rd
@@ -5,7 +5,7 @@
\title{Paste simple JavaScript plot code}
\usage{
rk.paste.JS.graph(..., plotOpts = NULL, printoutObj = NULL, level = 2,
- indent.by = rk.get.indent(), empty.e = FALSE)
+ indent.by = rk.get.indent(), empty.e = rk.get.empty.e())
}
\arguments{
\item{...}{The actual plot code, passed through to \code{rk.paste.JS}.}
diff --git a/packages/rkwarddev/man/rk.set.empty.e.Rd b/packages/rkwarddev/man/rk.set.empty.e.Rd
new file mode 100644
index 0000000..bb61360
--- /dev/null
+++ b/packages/rkwarddev/man/rk.set.empty.e.Rd
@@ -0,0 +1,27 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/rk.get.empty.e.R, R/rk.set.empty.e.R
+\name{rk.get.empty.e}
+\alias{rk.get.empty.e}
+\alias{rk.set.empty.e}
+\title{Globally define handling of empty else conditions in JS}
+\usage{
+rk.get.empty.e()
+
+rk.set.empty.e(empty = FALSE)
+}
+\arguments{
+\item{empty}{Logical, whether .}
+}
+\value{
+\code{rk.set.empty.e} returns invisible(NULL),
+ \code{rk.get.empty.e} either \code{TRUE} or \code{FALSE}.
+}
+\description{
+Some JS functions allow to decide whether empty \code{else} statements should be omitted or printed
+nonetheless (which some consider more reader friendly). The default can be globally defined with
+\code{rk.set.empty.e}, so you don't have to specify it in each function call.
+}
+\details{
+\code{rk.get.empty.e} returns the set value, which defaults to \code{FALSE} by default.
+}
+
More information about the rkward-tracker
mailing list