[rkward] packages/rkwarddev: enable linebreaks in js()
m.eik michalke
meik.michalke at uni-duesseldorf.de
Sun Nov 8 17:33:43 UTC 2015
Git commit 804de7120205aad5c0787868a10e6d6f5b8e01ce by m.eik michalke.
Committed on 08/11/2015 at 17:31.
Pushed by meikm into branch 'master'.
enable linebreaks in js()
- this still messes up the output a bit, there's a tab too many before additional "if" clauses, not so easy to fix
M +10 -2 packages/rkwarddev/R/js.R
M +3 -1 packages/rkwarddev/man/js.Rd
http://commits.kde.org/rkward/804de7120205aad5c0787868a10e6d6f5b8e01ce
diff --git a/packages/rkwarddev/R/js.R b/packages/rkwarddev/R/js.R
index 684836f..777abba 100644
--- a/packages/rkwarddev/R/js.R
+++ b/packages/rkwarddev/R/js.R
@@ -35,6 +35,7 @@
#' and/or objects of classes \code{rk.JS.arr} or \code{rk.JS.opt}, simply separated by comma.
#' JavaScript operators and \code{if} conditions will be kept as-is.
#' @param level Integer value, first indetation level.
+#' @param linebreaks Logical, should there be line breaks between the elements in this call?
#' @return A character string.
#' @export
#' @seealso \code{\link[rkwarddev:rk.JS.vars]{rk.JS.vars}},
@@ -54,8 +55,15 @@
#' }
#' )))
-js <- function(..., level=2){
+js <- function(..., level=2, linebreaks=FALSE){
full.content <- eval(substitute(alist(...)))
+
+ if(isTRUE(linebreaks)){
+ collapse <- paste0("\n", paste0(rep("\t", max(0, level-1)), collapse=""))
+ } else {
+ collapse <- ""
+ }
+
ID.content <- lapply(
full.content,
function(this.part){
@@ -80,5 +88,5 @@ js <- function(..., level=2){
}
}
)
- return(id(js=TRUE, .objects=ID.content))
+ return(id(js=TRUE, collapse=collapse, .objects=ID.content))
}
diff --git a/packages/rkwarddev/man/js.Rd b/packages/rkwarddev/man/js.Rd
index 9208915..0ae37be 100644
--- a/packages/rkwarddev/man/js.Rd
+++ b/packages/rkwarddev/man/js.Rd
@@ -4,7 +4,7 @@
\alias{js}
\title{R to JavaScript translation}
\usage{
-js(..., level = 2)
+js(..., level = 2, linebreaks = FALSE)
}
\arguments{
\item{...}{One or several character strings and/or \code{XiMpLe.node} objects with plugin nodes,
@@ -12,6 +12,8 @@ and/or objects of classes \code{rk.JS.arr} or \code{rk.JS.opt}, simply separated
JavaScript operators and \code{if} conditions will be kept as-is.}
\item{level}{Integer value, first indetation level.}
+
+\item{linebreaks}{Logical, should there be line breaks between the elements in this call?}
}
\value{
A character string.
More information about the rkward-tracker
mailing list