Skip to content

Commit

Permalink
Fixed for issue #15 thanks to @danhalligan
Browse files Browse the repository at this point in the history
  • Loading branch information
edwindj committed Jun 10, 2014
1 parent 39ef6fa commit f0a8b05
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 6 additions & 1 deletion R/parseTemplate.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ keytypes <- c("", "{}", "&", "#", "^", "/", ">")
# current parsing code is not a clean parsing state machine!
# This is partly due to that this would be clumsy in R,
# It's on my list to do the parsing in C (would be significantly faster)
parseTemplate <- function(template, partials=new.env(), debug=FALSE, strict=TRUE){
parseTemplate <- function(template, partials=new.env(), debug=FALSE, strict=TRUE, checkvars=FALSE){
#TODO add delimiter switching

delim <- tag2delim()
Expand Down Expand Up @@ -95,6 +95,11 @@ parseTemplate <- function(template, partials=new.env(), debug=FALSE, strict=TRUE

compiled <- function(data=list(), context=list(data)){
values <- lapply(keys, resolve, context=context, strict=strict)
if (isTRUE(checkvars)){
for (v in which(sapply(values, is.null))){
warning("Missing '", keys[v],"'")
}
}
keyinfo <- key
renderTemplate( values=values
, context=context
Expand Down
6 changes: 5 additions & 1 deletion R/whisker.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
#' @param data named \code{list} or \code{environment} with variables that will be used during rendering
#' @param partials named \code{list} with partial templates, will be used during template construction
#' @param debug Used for debugging purposes, likely to disappear
#' @param strict \code{logical} if \code{TRUE} the seperation symbol is a "." otherwise a "$"
#' @param strict \code{logical} if \code{TRUE} the separation symbol is a "." otherwise a "$"
#' @param checkvars \code{logical} if \code{TRUE} \code{whisker.render} will
#' generate warnings when values are not present in \code{data}.
#' @return \code{character} with rendered template
#' @rdname whisker.render
#' @example examples/whisker_render.R
Expand All @@ -14,6 +16,7 @@ whisker.render <- function( template
, partials = list()
, debug = FALSE
, strict = TRUE
, checkvars = FALSE
){
if (is.null(template) || paste(template, collapse="") == ""){
return("")
Expand All @@ -23,6 +26,7 @@ whisker.render <- function( template
, partials=as.environment(partials)
, debug=debug
, strict=strict
, checkvars = checkvars
)

return(tmpl(data))
Expand Down

0 comments on commit f0a8b05

Please sign in to comment.