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

solved the scope issue of js()

  - added a new function rk.local() to replace local(), hope this is a clean enough solution
parent 44c1ba32
ChangeLog for package rkwarddev
changes in version 0.07-4 (2015-11-23)
changes in version 0.08-1 (2015-11-28)
unreleased:
- this version is under development
fixed:
......@@ -27,8 +27,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() and ".ite" in rk.JS.options() 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
......@@ -45,6 +45,8 @@ added:
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
- new function rk.local() to be used as an alternative to local() with a
predefined local environment to solve scope issues with js()
changed:
- improved error handling in rk.JS.header(), error messages are more
informative now
......
......@@ -31,6 +31,9 @@
#'
#' These are currently unsupported and still need to be quoted: \%, ++, --, =, +=, -=, *=, /=, \%=, ===, !== and !
#'
#' @note You should nest your plugin script inside \code{\link[rkwarddev:rk.local]{rk.local}} if you're
#' making use of js(), to be sure it can find all defined objects.
#'
#' @param ... One or several character strings and/or \code{XiMpLe.node} objects with plugin nodes,
#' 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.
......@@ -43,7 +46,8 @@
#' 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}},
#' @seealso \code{\link[rkwarddev:rk.local]{rk.local}},
#' \code{\link[rkwarddev:rk.JS.vars]{rk.JS.vars}},
#' \code{\link[rkwarddev:rk.JS.array]{rk.JS.array}},
#' \code{\link[rkwarddev:rk.JS.options]{rk.JS.options}},
#' \code{\link[rkwarddev:echo]{echo}},
......@@ -89,8 +93,8 @@ js <- function(..., level=2, indent.by=rk.get.indent(), linebreaks=TRUE, empty.e
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))
if(as.character(this.part[[1]]) %in% c("rk.comment", "tf", "rk.JS.optionset")){
return(rk.paste.JS(eval(this.part, envir=.rk.local.env), level=level, indent.by=indent.by, empty.e=empty.e))
} else {}
# replace JS operators
return(do.call("replaceJSOperators", args=list(this.part)))
......
......@@ -21,6 +21,8 @@
# set up an internal environment, e.g. for prompter settings or indentation
.rkdev.env <- new.env()
# another environment for use with rk.local()
.rk.local.env <- new.env()
# internal functions for the rk.* functions
......
# 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/>.
#' Evaluate code in a local environment
#'
#' Can be used like \code{\link[base:local]{local}}, but evaluation is being done in a speacial
#' local environment of the rkwarddev package. This can be neccessary if you want to call functions
#' nested insinde \code{\link[rkwarddev:js]{js}}, because it might not find all objects if they were
#' only defined in a standard local environment.
#'
#' @param ... The code to be evaluated.
#' @return The result of evaluating the object(s).
#' @export
rk.local <- function(...){
rm(list=ls(), envir=.rk.local.env)
local(..., envir=.rk.local.env)
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/rk.local.R
\name{rk.local}
\alias{rk.local}
\title{Evaluate code in a local environment}
\usage{
rk.local(...)
}
\arguments{
\item{...}{The code to be evaluated.}
}
\value{
The result of evaluating the object(s).
}
\description{
Can be used like \code{\link[base:local]{local}}, but evaluation is being done in a speacial
local environment of the rkwarddev package. This can be neccessary if you want to call functions
nested insinde \code{\link[rkwarddev:js]{js}}, because it might not find all objects if they were
only defined in a standard local environment.
}
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