Skip to content

Commit

Permalink
Add font_family sprinkle
Browse files Browse the repository at this point in the history
  • Loading branch information
nutterb committed Nov 11, 2015
1 parent c490ce0 commit ed15390
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 6 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: pixiedust
Date: 2015-11-05
Date: 2015-11-10
Title: Tables so Beautifully Fine-Tuned You Will Believe It's Magic
Version: 0.5.3
Version: 0.5.4
Authors@R: person("Benjamin", "Nutter", email = "nutter@battelle.org", role = c("aut", "cre"))
Description: The introduction of the broom package has made converting model objects into data
frames as simple as a single function. While the broom package focuses on providing tidy
Expand Down
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#### 0.5.4 (10 November 2015)
* Added the `font_family` sprinkle for HTML output

#### 0.5.3 (5 November 2015)
* Due to a great deal of difficulty getting the last couple of
features to play nicely, I decided to take a different
Expand Down
1 change: 1 addition & 0 deletions R/dust.R
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ cell_attributes_frame <- function(nrow, ncol)
halign = "",
valign = "",
bg = "",
font_family = "",
font_color = "",
font_size = "",
font_size_units = "",
Expand Down
7 changes: 6 additions & 1 deletion R/print_dust_html.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ part_prep_html <- function(part, head=FALSE)
part$bg[logic] <-
with(part, paste0("background-color:", bg[logic], ";"))

#* Font Family
logic <- part$font_family != ""
part$font_family[logic] <-
with(part, paste0("font-family:", font_family[logic], ";"))

#* Font Color
logic <- part$font_color != ""
part$font_color[logic] <-
Expand Down Expand Up @@ -169,7 +174,7 @@ part_prep_html <- function(part, head=FALSE)
" colspan = '", colspan, "'; ",
"rowspan = '", rowspan, "'; ",
"style='",
bold, italic, halign, valign, bg, font_color,
bold, italic, halign, valign, bg, font_family, font_color,
font_size, height, width,
top_border, bottom_border, left_border, right_border,
rotate_degree, pad,
Expand Down
11 changes: 10 additions & 1 deletion R/sprinkle.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@
#' \item{\code{fn} }{A function to apply to values in cells. The function
#' should be an expression that acts on the variable \code{value}. For
#' example, \code{quote(round(value, 3))}.}
#' \item{\code{font_family} }{A character string denoting the font family
#' for the text. This option is only recognized in HTML output.
#' A short list of web safe fonts is available at
#' http://www.w3schools.com/cssref/css_websafe_fonts.asp}
#' \item{\code{font_color} }{A character string denoting the color of the
#' font. See "Colors".}
#' \item{\code{font_size} }{A numeric value denoting the size of the font.}
Expand Down Expand Up @@ -446,6 +450,11 @@ sprinkle <- function(x, rows=NULL, cols=NULL, ...,
msg = "The 'border_collapse' argument must be logical.",
argcheck = Check)

if ("font_family" %in% names(sprinkles) & !is.character(sprinkles$font_family))
ArgumentCheck::addError(
msg = "The 'font_family' argument must be a character string",
argcheck = Check)

if ("font_color" %in% names(sprinkles) & !is.character(sprinkles$font_color))
ArgumentCheck::addError(
msg = "The 'font_color' argument must be a character string.",
Expand Down Expand Up @@ -718,7 +727,7 @@ sprinkle_names <- function()
"bold", "border", "border_thickness",
"border_units", "border_style", "border_color",
"border_collapse",
"fn", "font_color", "font_size", "font_size_units", "halign",
"fn", "font_family", "font_color", "font_size", "font_size_units", "halign",
"height", "height_units", "italic", "longtable",
"merge", "merge_rowval", "merge_colval", "na_string", "pad",
"replace", "rotate_degree",
Expand Down
4 changes: 4 additions & 0 deletions man/sprinkle.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ list of which sprinkles are recognized by each output type, see
\item{\code{fn} }{A function to apply to values in cells. The function
should be an expression that acts on the variable \code{value}. For
example, \code{quote(round(value, 3))}.}
\item{\code{font_family} }{A character string denoting the font family
for the text. This option is only recognized in HTML output.
A short list of web safe fonts is available at
http://www.w3schools.com/cssref/css_websafe_fonts.asp}
\item{\code{font_color} }{A character string denoting the color of the
font. See "Colors".}
\item{\code{font_size} }{A numeric value denoting the size of the font.}
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-dust.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ test_that("dust object body component has correct dimensions",
dim(x$foot))

expect_equal(Dims,
list(c(5, 30),
c(30, 30),
list(c(5, 31),
c(30, 31),
NULL,
NULL))
})
Expand Down

0 comments on commit ed15390

Please sign in to comment.