| 1 |
library(testit) |
| 2 |
|
| 3 |
# getting and setting themes |
| 4 |
|
| 5 |
formats = c("markdown", "latex") |
| 6 |
for (frm in formats) { |
| 7 |
opts_knit$set(out.format = frm) |
| 8 |
thm = knit_theme$get('acid') |
| 9 |
knit_theme$set(thm) |
| 10 |
assert('knit_theme$get returns theme(s)', { |
| 11 |
(identical(length(knit_theme$get()), |
| 12 |
length(dir(system.file("themes", package = "knitr"))))) |
| 13 |
(!is.null(thm)) |
| 14 |
}) |
| 15 |
|
| 16 |
assert('knit_theme$set updates highlight and background', { |
| 17 |
(thm$highlight %==% as.character(opts_knit$get('header')[1])) |
| 18 |
(thm$background %==% opts_chunk$get('background')) |
| 19 |
}) |
| 20 |
opts_knit$restore() |
| 21 |
opts_chunk$restore() |
| 22 |
} |
| 23 |
|
| 24 |
# style -> theme |
| 25 |
|
| 26 |
tl = theme2list('acid.style') |
| 27 |
assert('theme2list parsing from .style to CSS', { |
| 28 |
(tl$Description %==% "Acid") |
| 29 |
(tl$Canvas$Colour %==% "#eeeeee") |
| 30 |
(isTRUE(tl$Number$Bold)) |
| 31 |
(is.null(tl$Keywords)) |
| 32 |
}) |
| 33 |
|
| 34 |
# theme -> css |
| 35 |
|
| 36 |
css = list2css(tl) |
| 37 |
assert('css is generated for a theme', { |
| 38 |
(grepl(tl$Canvas$Colour, css[1])) |
| 39 |
(grepl("font-weight: bold;", css[2])) |
| 40 |
(grepl(tl$String$Colour, css[3])) |
| 41 |
}) |
| 42 |
|
| 43 |
fdir = file.path(tempdir(), "themes") |
| 44 |
dir.create(fdir) |
| 45 |
res = lapply(1:2, function(i) { |
| 46 |
fn = paste0(fdir, "/acid", i, '.theme', collapse = "") |
| 47 |
writeLines(readLines('acid.style'), con = fn) |
| 48 |
return() |
| 49 |
}) |
| 50 |
|
| 51 |
cssdir = file.path(tempdir(), "css") |
| 52 |
dir.create(cssdir) |
| 53 |
suppressMessages(themes2css(fdir, cssdir)) |
| 54 |
assert('themes2css creates two css files from test data', { |
| 55 |
(length(dir(cssdir)) == 2) |
| 56 |
(dir(cssdir) %==% c("acid1.css", "acid2.css")) |
| 57 |
}) |