Commit fc163a30 authored by m.eik michalke's avatar m.eik michalke
Browse files

added new functions rk.set.indent()/rk.get.indent()

  - these new functions control what indentation string should be used in the generated code
  - all functions offering "indent.by" have been updated accordingly
parent ff375cb1
......@@ -31,6 +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
changed:
- improved error handling in rk.JS.header(), error messages are more
informative now
......@@ -38,6 +40,8 @@ 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()
changes in version 0.07-3 (2015-06-29)
fixed:
......
......@@ -111,6 +111,7 @@ Collate:
'rk.XML.wizard.R'
'rk.build.plugin.R'
'rk.get.comp.R'
'rk.get.indent.R'
'rk.get.rkh.prompter.R'
'rk.i18n.comment.R'
'rk.paste.JS.R'
......@@ -131,6 +132,7 @@ Collate:
'rk.rkh.title.R'
'rk.rkh.usage.R'
'rk.set.comp.R'
'rk.set.indent.R'
'rk.set.rkh.prompter.R'
'rk.testsuite.doc.R'
'rk.uniqueIDs.R'
......
......@@ -81,6 +81,7 @@ export(rk.XML.wizard)
export(rk.build.plugin)
export(rk.comment)
export(rk.get.comp)
export(rk.get.indent)
export(rk.get.rkh.prompter)
export(rk.i18n.comment)
export(rk.paste.JS)
......@@ -102,6 +103,7 @@ export(rk.rkh.technical)
export(rk.rkh.title)
export(rk.rkh.usage)
export(rk.set.comp)
export(rk.set.indent)
export(rk.set.rkh.prompter)
export(rk.testsuite.doc)
export(rkwarddev.required)
......
......@@ -27,7 +27,7 @@
#' @examples
#' cat(R.comment("This will become an R comment"))
R.comment <- function(..., indent.by="\\t", level=2, newline=""){
R.comment <- function(..., indent.by=rk.get.indent(escape=TRUE), level=2, newline=""){
message <- paste0(list(...), collapse=" ")
if(level > 1){
indentation <- paste0(", \"", rep(indent.by, level-1), "\"")
......
......@@ -58,7 +58,7 @@
#' }
#' )))
js <- function(..., level=2, indent.by="\t", linebreaks=FALSE, empty.e=FALSE){
js <- function(..., level=2, indent.by=rk.get.indent(), linebreaks=FALSE, empty.e=FALSE){
full.content <- eval(substitute(alist(...)))
if(isTRUE(linebreaks)){
......
......@@ -19,7 +19,7 @@
#' @include rk.comment.R
#' @import XiMpLe rkward
# set up an internal environment, e.g. for prompter settings
# set up an internal environment, e.g. for prompter settings or indentation
.rkdev.env <- new.env()
# internal functions for the rk.* functions
......@@ -106,7 +106,7 @@ trim <- function(char){
## function indent()
# will create tabs to format the output
indent <- function(level, by="\t"){
indent <- function(level, by=rk.get.indent()){
paste(rep(by, max(0, level-1)), collapse="")
} ## end function indent()
......@@ -679,7 +679,7 @@ modif.validity <- function(source, modifier, ignore.empty=TRUE, warn.only=TRUE,
if(isTRUE(warn.only)){
warning(paste0("Some modifier you provided is invalid for '", tag.name, "' and was ignored: \"",
paste(modifier[invalid.modif], collapse="\", \""), "\"\n\n",
"Known modifiers for '", tag.name, "' nodes are:\n\t\"", paste0(unlist(modifiers(obj=tag.name)[[tag.name]]), collapse="\", \""), "\"\n\n",
"Known modifiers for '", tag.name, "' nodes are:\n \"", paste0(unlist(modifiers(obj=tag.name)[[tag.name]]), collapse="\", \""), "\"\n\n",
"For a list of all valid modifiers call modifiers(\"", tag.name, "\")"), call.=FALSE)
if(isTRUE(bool)){
return(!invalid.modif)
......@@ -814,7 +814,7 @@ clean.name <- function(name, message=TRUE){
## function paste.JS.ite()
paste.JS.ite <- function(object, level=1, indent.by="\t", recurse=FALSE, empty.e=FALSE){
paste.JS.ite <- function(object, level=1, indent.by=rk.get.indent(), recurse=FALSE, empty.e=FALSE){
stopifnot(inherits(object, "rk.JS.ite"))
# check indentation
main.indent <- indent(level, by=indent.by)
......@@ -864,7 +864,7 @@ paste.JS.ite <- function(object, level=1, indent.by="\t", recurse=FALSE, empty.e
## function paste.JS.array()
# opt.sep: the separator that comes *before* the option that is set, in the resulting code
paste.JS.array <- function(object, level=2, indent.by="\t", funct=NULL, opt.sep=NULL){
paste.JS.array <- function(object, level=2, indent.by=rk.get.indent(), funct=NULL, opt.sep=NULL){
stopifnot(inherits(object, "rk.JS.arr"))
# check indentation
main.indent <- indent(level, by=indent.by)
......@@ -919,7 +919,7 @@ paste.JS.array <- function(object, level=2, indent.by="\t", funct=NULL, opt.sep=
## function paste.JS.options()
# opt.sep: the separator that comes *before* the option that is set, in the resulting code
paste.JS.options <- function(object, level=2, indent.by="\t", array=NULL, funct=NULL, opt.sep=NULL){
paste.JS.options <- function(object, level=2, indent.by=rk.get.indent(), array=NULL, funct=NULL, opt.sep=NULL){
stopifnot(inherits(object, "rk.JS.opt"))
# check indentation
main.indent <- indent(level, by=indent.by)
......@@ -1018,7 +1018,7 @@ paste.JS.options <- function(object, level=2, indent.by="\t", array=NULL, funct=
# 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.
# var: if FALSE, the variable is assumed to be already defined (globally?) and "var " will be omitted
paste.JS.var <- function(object, level=2, indent.by="\t", JS.prefix=NULL, modifiers=NULL, default=NULL, append.modifier=NULL,
paste.JS.var <- function(object, level=2, indent.by=rk.get.indent(), JS.prefix=NULL, modifiers=NULL, default=NULL, append.modifier=NULL,
join=NULL, getter=NULL, names.only=FALSE, check.modifiers=FALSE, var=TRUE){
# paste several objects
results <- unlist(sapply(slot(object, "vars"), function(this.obj){
......@@ -1119,7 +1119,7 @@ paste.JS.var <- function(object, level=2, indent.by="\t", JS.prefix=NULL, modifi
## function paste.JS.optionsset()
paste.JS.optionsset <- function(object, level=2, indent.by="\t"){
paste.JS.optionsset <- function(object, level=2, indent.by=rk.get.indent()){
stopifnot(inherits(object, "rk.JS.oset"))
# check indentation
main.indent <- indent(level, by=indent.by)
......@@ -1509,7 +1509,7 @@ replaceJSOperators <- function(..., call="id"){
## function uncurl()
# used by js() to fetch calls from then/else segments of if conditions,
# omitting curly brackets that would get in the way with ite()
uncurl <- function(cond, level=1, indent.by="\t"){
uncurl <- function(cond, level=1, indent.by=rk.get.indent()){
if(!is.null(cond)){
cond.list <- as.list(cond)
# first check for the bracket
......@@ -1537,7 +1537,7 @@ uncurl <- function(cond, level=1, indent.by="\t"){
## function replaceJSIf
replaceJSIf <- function(cond, level=1, paste=TRUE, indent.by="\t", empty.e=FALSE){
replaceJSIf <- function(cond, level=1, paste=TRUE, indent.by=rk.get.indent(), empty.e=FALSE){
if(inherits(cond, "if")){
# if condition -- should be save to give to js()
cond.if <- do.call(
......@@ -1625,7 +1625,7 @@ replaceJSIf <- function(cond, level=1, paste=TRUE, indent.by="\t", empty.e=FALSE
# }
# )))
#</documentation>
replaceJSFor <- function(loop, level=1, indent.by="\t"){
replaceJSFor <- function(loop, level=1, indent.by=rk.get.indent()){
if(inherits(loop, "for")){
# for loops must be handled differently, we need to create an array
# first and then interate through the array to imitate ho R does this
......
......@@ -59,7 +59,7 @@
#' @export
rk.JS.doc <- function(require=c(), variables=NULL, globals=NULL, results.header=NULL, header.add=list(),
preprocess=NULL, calculate=NULL, printout=NULL, doPrintout=NULL, load.silencer=NULL, gen.info=TRUE, indent.by="\t",
preprocess=NULL, calculate=NULL, printout=NULL, doPrintout=NULL, load.silencer=NULL, gen.info=TRUE, indent.by=rk.get.indent(),
guess.getter=FALSE){
# variable to determine whether to add setGlobalVars() to preprocess() later
addSetGlobalVars <- FALSE
......
# Copyright 2010-2014 Meik Michalke <meik.michalke@hhu.de>
# Copyright 2010-2015 Meik Michalke <meik.michalke@hhu.de>
#
# This file is part of the R package rkwarddev.
#
......@@ -31,7 +31,7 @@
#' @seealso \href{help:rkwardplugins}{Introduction to Writing Plugins for RKWard}
#' @export
rk.JS.saveobj <- function(pXML, R.objects="initial", vars=TRUE, add.abbrev=FALSE, indent.by="\t"){
rk.JS.saveobj <- function(pXML, R.objects="initial", vars=TRUE, add.abbrev=FALSE, indent.by=rk.get.indent()){
single.tags <- get.single.tags(XML.obj=pXML, drop=c("comments","cdata", "declarations", "doctype"))
......
......@@ -32,7 +32,7 @@
#' @seealso \href{help:rkwardplugins}{Introduction to Writing Plugins for RKWard}
#' @export
rk.JS.scan <- function(pXML, js=TRUE, add.abbrev=FALSE, guess.getter=FALSE, indent.by="\t"){
rk.JS.scan <- function(pXML, js=TRUE, add.abbrev=FALSE, guess.getter=FALSE, indent.by=rk.get.indent()){
# these are tags to scan normally, no special treatment
JS.relevant.tags.default <- c("browser", "dropdown", "input", "matrix", "optioncolumn",
......
# Copyright 2015 Meik Michalke <meik.michalke@hhu.de>
#
# This file is part of the R package rkwarddev.
#
# rkwarddev is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# rkwarddev is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with rkwarddev. If not, see <http://www.gnu.org/licenses/>.
#' @rdname rk.set.indent
#' @param escape Logical, if set to \code{TRUE} each occurring "\t" will be escaped by an additional "\".
#' @export
rk.get.indent <- function(escape=FALSE){
indent.by <- get.rk.env("indent.by", value="\t")
if(isTRUE(escape)){
indent.by <- gsub("\t", "\\\\t", indent.by)
} else {}
return(indent.by)
}
......@@ -64,7 +64,7 @@
#' and the \href{help:rkwardplugins}{Introduction to Writing Plugins for RKWard}
#' @export
rk.paste.JS <- function(..., level=2, indent.by="\t", funct=NULL, array=NULL,
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,
opt.sep=NULL){
stopifnot(level > 0)
......
......@@ -55,9 +55,9 @@
#' plotOpts=tmp.plot.options)
#'
#' cat(js.prnt)
rk.paste.JS.graph <- function(..., plotOpts=NULL, printoutObj=NULL, level=2, indent.by="\t", empty.e=FALSE){
rk.paste.JS.graph <- function(..., plotOpts=NULL, printoutObj=NULL, level=2, indent.by=rk.get.indent(), empty.e=FALSE){
plotOptsIndent <- paste(rep("\\t", level), collapse="")
plotOptsIndent <- paste(rep(rk.get.indent(escape=TRUE), level), collapse="")
# define variables
js.prnt <- rk.paste.JS(
......@@ -90,7 +90,7 @@ rk.paste.JS.graph <- function(..., plotOpts=NULL, printoutObj=NULL, level=2, ind
# graph.on() & begin try()
js.prnt <- paste(js.prnt, rk.paste.JS(
ite("full", echo("rk.graph.on()\n")),
echo("\ttry({\n"),
echo(paste0(indent(level=level, by=indent.by), "try({\n")),
level=level, indent.by=indent.by, empty.e=empty.e
), sep="\n\n")
......@@ -133,7 +133,7 @@ rk.paste.JS.graph <- function(..., plotOpts=NULL, printoutObj=NULL, level=2, ind
# end try() & graph.off()
js.prnt <- paste(js.prnt, rk.paste.JS(
echo("\n\t})\n"),
echo(paste0("\n",indent(level=level, by=indent.by),"})\n")),
ite("full", echo("rk.graph.off()\n")),
level=level, indent.by=indent.by, empty.e=empty.e
), sep="\n\n")
......
# Copyright 2010-2014 Meik Michalke <meik.michalke@hhu.de>
# Copyright 2010-2015 Meik Michalke <meik.michalke@hhu.de>
#
# This file is part of the R package rkwarddev.
#
......
# Copyright 2010-2014 Meik Michalke <meik.michalke@hhu.de>
# Copyright 2010-2015 Meik Michalke <meik.michalke@hhu.de>
#
# This file is part of the R package rkwarddev.
#
......@@ -92,7 +92,7 @@
rk.plugin.component <- function(about, xml=list(), js=list(), rkh=list(),
provides=c("logic", "dialog"), scan=c("var", "saveobj", "settings"), guess.getter=FALSE,
hierarchy="test", include=NULL, create=c("xml", "js", "rkh"), dependencies=NULL,
hints=TRUE, gen.info=TRUE, indent.by="\t"){
hints=TRUE, gen.info=TRUE, indent.by=rk.get.indent()){
if(is.XiMpLe.node(about)){
# check about and dependencies
......
# Copyright 2010-2014 Meik Michalke <meik.michalke@hhu.de>
# Copyright 2010-2015 Meik Michalke <meik.michalke@hhu.de>
#
# This file is part of the R package rkwarddev.
#
......@@ -166,7 +166,7 @@ rk.plugin.skeleton <- function(about, path=tempdir(),
overwrite=FALSE, tests=TRUE, lazyLoad=TRUE,
create=c("pmap", "xml", "js", "rkh", "desc", "clog"), suggest.required=TRUE,
components=list(), dependencies=NULL, edit=FALSE, load=FALSE, show=FALSE, gen.info=TRUE,
hints=TRUE, indent.by="\t", internal=FALSE){
hints=TRUE, indent.by=rk.get.indent(), internal=FALSE){
if(is.XiMpLe.node(about)){
# check about and dependencies
......
# Copyright 2015 Meik Michalke <meik.michalke@hhu.de>
#
# This file is part of the R package rkwarddev.
#
# rkwarddev is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# rkwarddev is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# 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
#' @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))
}
......@@ -53,7 +53,7 @@
#' cbox1 <- rk.XML.cbox(label="foo", value="foo1", id.name="foo_option")
#' tf(cbox1)
tf <- function(cbox, true=TRUE, not=FALSE, ifelse=FALSE, false=FALSE, opt=NULL, prefix=",\n", level=3, indent.by="\t"){
tf <- function(cbox, true=TRUE, not=FALSE, ifelse=FALSE, false=FALSE, opt=NULL, prefix=",\n", level=3, indent.by=rk.get.indent()){
# check if we're given a checkbox, alright...
valid.parent(parent="checkbox", node=cbox, warn=FALSE, see="rk.XML.cbox", arg.name="cbox")
......
......@@ -39,6 +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
}
}
\subsection{changed}{
......@@ -49,6 +51,8 @@
\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()}
}
}
}
......
......@@ -4,7 +4,8 @@
\alias{R.comment}
\title{Create R comment with JavaScript in RKWard plugin code}
\usage{
R.comment(..., indent.by = "\\\\t", level = 2, newline = "")
R.comment(..., indent.by = rk.get.indent(escape = TRUE), level = 2,
newline = "")
}
\arguments{
\item{...}{Character strings to form a comment.}
......
......@@ -4,7 +4,7 @@
\alias{js}
\title{R to JavaScript translation}
\usage{
js(..., level = 2, indent.by = "\\t", linebreaks = FALSE,
js(..., level = 2, indent.by = rk.get.indent(), linebreaks = FALSE,
empty.e = FALSE)
}
\arguments{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment