Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

{{mustache}} for R

NotificationsYou must be signed in to change notification settings

edwindj/whisker

Repository files navigation

versiondownloadsR build statusBuild statusstatus

Whisker

Whisker is a{{Mustache}} implementation inR confirming to the Mustache specification.Mustache is a logicless templating language, meaning that no programming sourcecode can be used in your templates. This may seem very limited, but Mustache isnonetheless powerful and has the advantage of being able to be used unaltered inmany programming languages. It makes it very easy to write a web application in Rusing Mustache templates which could also be re-used for client-side rendering with"Mustache.js".

Mustache (and therefore whisker) takes a simple, but different, approach totemplating compared to most templating engines. Most templating libraries,such asSweave,knitr andbrew, allow the user to mix programming code and textthroughout the template. This is powerful, but ties your template directlyto a programming language and makes it difficult to seperate programming code fromtemplating code.

Whisker, on the other hand, takes a Mustache template and uses the variables of thecurrentenvironment (or the suppliedlist) to fill in the variables.

Mustache syntax

The syntax of Mustache templates is described inhttps://mustache.github.io/mustache.5.htmlHow the mustache template are used with whisker can be found in the whisker documentation, and below.

Mustache specification

Whisker conforms to theMustache 1.1 specificaton except for delimiter switching andlambdas. We expect that these will be implented shortly.

Installation

To install whisker use the following statement in your R console

install.packages("whisker")

The latest whisker version is not yet available on CRAN, but can be installed from github:

library(devtools)# dev_mode()install_github("whisker","edwindj")

Usage

whisker.render accepts acharacter template and a list or environment containing data to render:

library(whisker)template <-'Hello {{name}}You have just won ${{value}}!{{#in_ca}}Well, ${{taxed_value}}, after taxes.{{/in_ca}}'data <- list( name ="Chris", value =10000, taxed_value =10000- (10000*0.4), in_ca = TRUE            )text <- whisker.render(template, data)cat(text)
## Hello Chris## You have just won $10000!## Well, $6000, after taxes.

Or using a text file

library(whisker)template <- readLines("./template.html")data <- list( name ="Chris", value =10000, taxed_value =10000- (10000*0.4), in_ca = TRUE            )writeLines(whisker.render(template, data),"./output.html")

Note

By defaultwhisker applieshtml escaping on the generated text.To prevent this use{{{variable}}} (triple) in stead of{{variable}}.

template <-"I'm escaped: {{name}}And I'm not: {{{name}}}"data <- list( name ='<My Name="Nescio">')whisker.render(template, data)

Generates:

I'm escaped: &lt;My Name=&quot;Nescio&quot;&gt;And I'm not: <My Name="Nescio">

About

{{mustache}} for R

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors5

Languages


[8]ページ先頭

©2009-2025 Movatter.jp