diff --git a/.travis.yml b/.travis.yml index 5b7b611..3afc389 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,11 +23,11 @@ matrix: sudo: required env: R_CODECOV=true - os: osx - osx_image: xcode7.2 + osx_image: xcode7.3 brew_packages: hunspell latex: false - os: osx - osx_image: beta-xcode6.1 + osx_image: xcode6.4 latex: false disable_homebrew: true diff --git a/DESCRIPTION b/DESCRIPTION index 4ad4e2f..d5cda47 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: hrbrthemes Type: Package Title: Additional Themes, Theme Components and Utilities for 'ggplot2' -Version: 0.2.0 +Version: 0.3.0 Date: 2017-03-01 Authors@R: c( person("Bob", "Rudis", email = "bob@rud.is", role = c("aut", "cre")), @@ -34,6 +34,11 @@ Imports: grid, scales, extrafont, - purrr + knitr, + rmarkdown, + htmltools, + tools, + magrittr RoxygenNote: 6.0.1 VignetteBuilder: knitr + diff --git a/NAMESPACE b/NAMESPACE index 6957e4f..75dc280 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -6,6 +6,7 @@ export(font_rc) export(font_rc_light) export(gg_check) export(import_roboto_condensed) +export(ipsum) export(ipsum_pal) export(scale_color_ipsum) export(scale_colour_ipsum) @@ -20,7 +21,9 @@ export(update_geom_font_defaults) import(extrafont) import(ggplot2) import(grid) +import(htmltools) +import(knitr) +import(rmarkdown) import(scales) -importFrom(purrr,"%>%") -importFrom(purrr,map) -importFrom(purrr,walk) +importFrom(magrittr,"%>%") +importFrom(tools,file_path_sans_ext) diff --git a/R/check.r b/R/check.r index baaba96..2bf19f5 100644 --- a/R/check.r +++ b/R/check.r @@ -48,7 +48,7 @@ gg_check <- function(gg, dict, ignore) { if (length(lbl) > 0) { - purrr::walk(names(lbl), function(lab) { + tmp <- lapply(names(lbl), function(lab) { words <- stringi::stri_extract_all_words(lbl[[lab]]) words <- unlist(words) diff --git a/R/hrbrthemes-package.R b/R/hrbrthemes-package.R index e1a0023..c4f4f39 100644 --- a/R/hrbrthemes-package.R +++ b/R/hrbrthemes-package.R @@ -21,7 +21,9 @@ #' @docType package #' @author Bob Rudis (bob@@rud.is) #' @import ggplot2 grid scales extrafont -#' @importFrom purrr %>% map walk +#' @importFrom magrittr %>% +#' @import rmarkdown knitr htmltools +#' @importFrom tools file_path_sans_ext NULL #' hrbrthemes exported operators diff --git a/R/ipsum.r b/R/ipsum.r new file mode 100644 index 0000000..8c7c80a --- /dev/null +++ b/R/ipsum.r @@ -0,0 +1,90 @@ +#' ipsum R markdown template +#' +#' Template for creating an R markdown document with an emphasis on typography +#' +#' @inheritParams rmarkdown::html_document +#' @param extra_dependencies,... Additional function arguments to pass to the +#' base R Markdown HTML output formatter +#' @export +ipsum <- function(number_sections = FALSE, + fig_width = 7, + fig_height = 5, + fig_retina = if (!fig_caption) 2, + fig_caption = FALSE, + dev = 'png', + smart = TRUE, + self_contained = TRUE, + highlight = "default", + mathjax = "default", + extra_dependencies = NULL, + css = NULL, + includes = NULL, + keep_md = FALSE, + lib_dir = NULL, + md_extensions = NULL, + pandoc_args = NULL, + ...) { + + toc <- FALSE + toc_depth <- 3 + theme <- NULL + template <- "default" + code_folding <- "none" + + dep <- htmltools::htmlDependency("ipsum", "0.1.0", + system.file("rmarkdown", "templates", "ipsum", "resources", + package = "hrbrthemes"), + stylesheet="ipsum.css") + + extra_dependencies <- append(extra_dependencies, list(dep)) + + + args <- c("--standalone") + args <- c(args, "--section-divs") + args <- c(args, rmarkdown::pandoc_toc_args(toc, toc_depth)) + + args <- c(args, "--template", + rmarkdown::pandoc_path_arg(system.file("rmarkdown", "templates", "ipsum", "base.html", + package = "hrbrthemes"))) + + if (number_sections) + args <- c(args, "--number-sections") + + for (css_file in css) + args <- c(args, "--css", rmarkdown::pandoc_path_arg(css_file)) + + pre_processor <- function(metadata, input_file, runtime, + knit_meta, files_dir, output_dir) { + + if (is.null(lib_dir)) lib_dir <- files_dir + + args <- c() + args <- c(args, pandoc_html_highlight_args(highlight, + template, self_contained, lib_dir, + output_dir)) + args <- c(args, includes_to_pandoc_args(includes = includes, + filter = if (identical(runtime, "shiny")) + normalize_path else identity)) + args + + } + + output_format( + knitr = rmarkdown::knitr_options_html(fig_width, fig_height, + fig_retina, keep_md, dev), + pandoc = rmarkdown::pandoc_options(to = "html", + from = from_rmarkdown(fig_caption, + md_extensions), + args = args), + keep_md = keep_md, clean_supporting = self_contained, + pre_processor = pre_processor, + base_format = rmarkdown::html_document_base(smart = smart, + theme = theme, + self_contained = self_contained, + lib_dir = lib_dir, + mathjax = mathjax, + template = template, + pandoc_args = pandoc_args, + extra_dependencies = extra_dependencies, + ...)) +} diff --git a/R/utils.r b/R/utils.r new file mode 100644 index 0000000..2c2aba3 --- /dev/null +++ b/R/utils.r @@ -0,0 +1,76 @@ +# Most (if not all) from github.com/rstudio/rmarkdown + +from_rmarkdown <- function (implicit_figures = TRUE, extensions = NULL) { + extensions <- paste0(extensions, collapse = "") + extensions <- gsub(" ", "", extensions) + if (!implicit_figures && !grepl("implicit_figures", extensions)) + extensions <- paste0("-implicit_figures", extensions) + rmarkdown_format(extensions) +} + +from_rst <-function (extensions = NULL) { + format <- c("rst") + addExtension <- function(extension) { + if (length(grep(extension, extensions)) == 0) + format <<- c(format, paste0("+", extension)) + } + addExtension("autolink_bare_uris") + addExtension("ascii_identifiers") + addExtension("tex_math_single_backslash") + format <- c(format, extensions, recursive = TRUE) + paste(format, collapse = "") +} + +pandoc_html_highlight_args <- function (highlight, template, self_contained, + files_dir, output_dir) { + args <- c() + if (is.null(highlight)) { + args <- c(args, "--no-highlight") + } + else if (!identical(template, "default")) { + if (identical(highlight, "default")) + highlight <- "pygments" + args <- c(args, "--highlight-style", highlight) + } + else { + highlight <- match.arg(highlight, html_highlighters()) + if (highlight %in% c("default", "textmate")) { + highlight_path <- system.file("rmd/h/highlight", package = "rmarkdown") + if (self_contained) + highlight_path <- pandoc_path_arg(highlight_path) + else { + highlight_path <- normalized_relative_to(output_dir, + render_supporting_files(highlight_path, files_dir)) + } + args <- c(args, "--no-highlight") + args <- c(args, "--variable", paste("highlightjs=", + highlight_path, sep = "")) + if (identical(highlight, "textmate")) { + args <- c(args, "--variable", paste("highlightjs-theme=", + highlight, sep = "")) + } + } + else { + args <- c(args, "--highlight-style", highlight) + } + } + args + +} + +html_highlighters <- function () { c(highlighters(), "textmate") } +highlighters <- function () { + c("default", "tango", "pygments", "kate", "monochrome", "espresso", + "zenburn", "haddock") +} + +normalized_relative_to <- function (dir, file) { + relative_to(normalizePath(dir, winslash = "/", mustWork = FALSE), + normalizePath(file, winslash = "/", mustWork = FALSE)) +} + +normalize_path <- function (path) { + if (is.null(path)) + NULL + else normalizePath(path, winslash = "/", mustWork = FALSE) +} \ No newline at end of file diff --git a/R/zzz.r b/R/zzz.r index c64d58f..dd657f2 100644 --- a/R/zzz.r +++ b/R/zzz.r @@ -1,7 +1,12 @@ -# Suggestion by @alexwhan - .onAttach <- function(libname, pkgname) { + if (interactive()) { + packageStartupMessage(paste0("hrbrthemes is under *active* development. ", + "See https://github.com/hrbrmstr/hrbrthemes for info/news.")) + } + + # Suggestion by @alexwhan + if (.Platform$OS.type == "windows") { # nocov start if (interactive()) packageStartupMessage("Registering Windows fonts with R") extrafont::loadfonts("win", quiet = TRUE) diff --git a/inst/COPYRIGHTS b/inst/COPYRIGHTS index 7c5f78d..a2d0e79 100644 --- a/inst/COPYRIGHTS +++ b/inst/COPYRIGHTS @@ -1,6 +1,7 @@ All R source code files are released under the MIT license. -The Google Roboto Condensed font has the folllowing copyright: +The Google Roboto Condensed & Slab fonts have +the folllowing copyright: Apache License diff --git a/inst/fonts/roboto-slab/RobotoSlab-Bold.ttf b/inst/fonts/roboto-slab/RobotoSlab-Bold.ttf new file mode 100755 index 0000000..df5d1df Binary files /dev/null and b/inst/fonts/roboto-slab/RobotoSlab-Bold.ttf differ diff --git a/inst/fonts/roboto-slab/RobotoSlab-Light.ttf b/inst/fonts/roboto-slab/RobotoSlab-Light.ttf new file mode 100755 index 0000000..ccb99cd Binary files /dev/null and b/inst/fonts/roboto-slab/RobotoSlab-Light.ttf differ diff --git a/inst/fonts/roboto-slab/RobotoSlab-Regular.ttf b/inst/fonts/roboto-slab/RobotoSlab-Regular.ttf new file mode 100755 index 0000000..eb52a79 Binary files /dev/null and b/inst/fonts/roboto-slab/RobotoSlab-Regular.ttf differ diff --git a/inst/fonts/roboto-slab/RobotoSlab-Thin.ttf b/inst/fonts/roboto-slab/RobotoSlab-Thin.ttf new file mode 100755 index 0000000..fee11da Binary files /dev/null and b/inst/fonts/roboto-slab/RobotoSlab-Thin.ttf differ diff --git a/inst/rmarkdown/templates/ipsum/base.html b/inst/rmarkdown/templates/ipsum/base.html new file mode 100644 index 0000000..4a8b13b --- /dev/null +++ b/inst/rmarkdown/templates/ipsum/base.html @@ -0,0 +1,85 @@ + + + + + + + + + + +$if(title)$$title$$endif$ + + + + + +$for(header-includes)$ +$header-includes$ +$endfor$ + +$if(highlightjs)$ + + + + +$endif$ + +$if(highlighting-css)$ + + +$endif$ + +$for(css)$ + +$endfor$ + + + + +
+ +

$if(title)$$title$$endif$

+ +$for(include-before)$ +$include-before$ +$endfor$ + +$if(toc)$ +
+$toc$ +
+$endif$ + +$body$ + +$for(include-after)$ +$include-after$ +$endfor$ + +
+ +$if(mathjax-url)$ + + +$endif$ + + + diff --git a/inst/rmarkdown/templates/ipsum/resources/ipsum.css b/inst/rmarkdown/templates/ipsum/resources/ipsum.css new file mode 100644 index 0000000..8d46dfe --- /dev/null +++ b/inst/rmarkdown/templates/ipsum/resources/ipsum.css @@ -0,0 +1,124 @@ +body { + margin:0; + padding:0; + color: #333; + background: #fff; + font-size: 100%; + text-rendering: optimizeLegibility; + -moz-font-feature-settings:"onum" 1; + -ms-font-feature-settings:"onum" 1; + -o-font-feature-settings:"onum" 1; + -webkit-font-feature-settings:"onum" 1; + font-feature-settings:"onum" 1; +} + + +html>body { + font-size: 1.063em; + font-weight: 300; + font-family: 'Roboto', sans-serif; +} + +.container { + margin: auto; + width: 61.6%; +} + +abbr, acronym, .caps { + -moz-font-feature-settings:"c2sc" 1, "onum" 1; + -ms-font-feature-settings:"c2sc" 1, "onum" 1; + -o-font-feature-settings:"c2sc" 1, "onum" 1; + -webkit-font-feature-settings:"c2sc" 1, "onum" 1; + font-feature-settings:"c2sc" 1, "onum" 1; + font-style: normal; + border-bottom: 0; +} + +blockquote abbr, blockquote acronym, em abbr, em acronym +cite abbr, cite acronym { + font-family: 'Roboto Slab', serif; + font-style: normal; +} + +cite, em { font-style: italic; } + +strong { font-weight: 500; } + +img { border: 0; } + +a, a:visited, a:link, a:active, a:hover { + color: #00408f; + text-decoration: underline; +} + +a:visited { color:#666; } + +html>body a, html>body a:visited, html>body a:link, +html>body a:active, html>body a:hover { + text-decoration: none; + border-bottom: 1px solid #f2ecda; +} + + +h1, h2, h3, h4 { + font-family: 'Roboto Slab', serif; + font-weight: 700; +} + +h1 { + font-size: 1.75em; + line-height: 1.083333333333333em; + margin: 0 0 1.0em 0; +} + +h2, h3 { + font-size: 1.1875em; /* 19px */ + margin: 1.157894736842105em 0; /* 22px */ + text-indent: -0.052631578947368em; /* 1px */ +} + +h4 { + font-size: 1em; + margin: 0.868421053em 0; +} + +blockquote { + margin-left: 0; + margin-right: 0; + font-style: italic; + font-family: 'Roboto Slab', serif; +} + +ul, ol, dl { + margin: 1.375em 0 1.375em 0; +} + +li, dd, dt { + margin: 0; +} + +ul ul, ol ol { + margin-left: 1.375em; +} + +dd { + margin-left: 1.375em; +} + +p { + margin-top: 0.5em;/* 1.375em; */ + line-height: 1.25em; + margin-bottom: 0; +} + +p + p { + margin-top: 0.75em; +} + +html > body q { +font-style:normal; +} + +body blockquote q { + font-style:italic; +} diff --git a/inst/rmarkdown/templates/ipsum/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/ipsum/skeleton/skeleton.Rmd new file mode 100644 index 0000000..edc0fad --- /dev/null +++ b/inst/rmarkdown/templates/ipsum/skeleton/skeleton.Rmd @@ -0,0 +1,40 @@ +--- +title: "INSERT_TITLE_HERE" +output: hrbrthemes::ipsum +--- +Captain John Sheridan: You know, I just had a thought. You've been back and forth to your world so many times since you got here. How do I know you're the same Vorlon? Inside that encounter suit you could be anyone. Kosh Naranek: I have *always* been here. Captain John Sheridan: Oh, yeah? You said that about me too. Kosh Naranek: Yes. [starts to walk away] Captain John Sheridan: I really *hate* it when you do that. Kosh Naranek: [turns around] Good! Delenn: I am Grey. I stand between the candle and the star. We are Grey. We stand between the darkness and the light. + +Lt. Corwin: Do we trust no-one then? Cmdr. Susan Ivanova: No, trust Ivanova, trust yourself, anybody else, shoot'em. Ta'Lon: Congratulations citizen G'Kar. You are now a religious icon. Susan Ivanova: So the next time we find out where the Shadows plan to strike, we can mine the area, and as soon as they come out of hyperspace... Citizen G'Kar: Then, as you so concisely say, Boom! + +## Section Title + +G'Kar: It is said that the future is always born in pain. The history of war is the history of pain. If we are wise, what is born of that pain matures into the promise of a better world, because we learn that we can no longer afford the mistakes of the past. Dr. Stephen Franklin: Doesn't anyone listen to one damn word I say? Captain John Sheridan: No surrender, no retreat. [Opening narration, season 4] Lennier: It was the year of fire, Zack Allan: The year of destruction, Citizen G'Kar: The year we took back what was ours. Lyta Alexander: It was the year of rebirth, Ambassador Vir Cotto: The year of great sadness, Marcus Cole: The year of pain, Delenn: And a year of joy. Ambassador Londo Mollari: It was a new age. Dr. Stephen Franklin: It was the end of history. Susan Ivanova: It was the year everything changed. Michael Garibaldi: The year is 2261. Captain John Sheridan: The place, Babylon 5. Sinclair: They say God works in mysterious ways. Michael Garibaldi: Maybe so, but He's a con-man compared to the Vorlon. + +## Figures + +```{r, fig.show='hold'} +plot(1:10) +plot(10:1) +``` + + +### Level 3 + +Commander Jeffrey David Sinclair: Everyone lies, Michael. The innocent lie because they don't want to be blamed for something they didn't do and the guilty lie because they don't have any other choice. Lt. Corwin: Do we trust no-one then? Cmdr. Susan Ivanova: No, trust Ivanova, trust yourself, anybody else, shoot'em. Susan Ivanova: If I live through this without completely losing my mind, it will be a miracle of Biblical proportions. + +Lt. Corwin: [aside] Well, there goes my faith in the Almighty. [Opening narration, season 3] Susan Ivanova: The Babylon Project was our last, best hope for peace. It failed. But in the year of the Shadow War, it became something greater: our last, best hope for victory. The year is 2260. The place - Babylon 5. Alfred Bester: Being a telepath means you're special and rare and valuable. + + +#### Level 4 + +Delenn: We are star stuff. We are the universe made manifest trying to figure itself out. + +Captain John Sheridan: If more of our so-called leaders would walk the same streets as the people who voted them in, live in the same buildings, eat the same food instead of hiding behind glass and steel and bodyguards, maybe we'd get better leadership and a little more concern for the future. + +Captain John Sheridan: If more of our so-called leaders would walk the same streets as the people who voted them in, live in the same buildings, eat the same food instead of hiding behind glass and steel and bodyguards, maybe we'd get better leadership and a little more concern for the future. Kosh Naranek: Understanding is a three-edged sword. Alfred Bester: Much as it might offend their sense of perspective, not everything is about Babylon 5. + + +```{r bib, include=FALSE} +# KEEP THIS AT THE END OF THE DOCUMENT TO GENERATE A LOCAL bib FILE FOR PKGS USED +knitr::write_bib(sub("^package:", "", grep("package", search(), value=TRUE)), file='skeleton.bib') +``` \ No newline at end of file diff --git a/inst/rmarkdown/templates/ipsum/template.yaml b/inst/rmarkdown/templates/ipsum/template.yaml new file mode 100644 index 0000000..3131062 --- /dev/null +++ b/inst/rmarkdown/templates/ipsum/template.yaml @@ -0,0 +1,4 @@ +name: ipsum Roboto Template +description: > + R Markdown template with an emphais on typograpghy using Roboto family fonts +create_dir: false diff --git a/man/ipsum.Rd b/man/ipsum.Rd new file mode 100644 index 0000000..3df4863 --- /dev/null +++ b/man/ipsum.Rd @@ -0,0 +1,72 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ipsum.r +\name{ipsum} +\alias{ipsum} +\title{ipsum R markdown template} +\usage{ +ipsum(number_sections = FALSE, fig_width = 7, fig_height = 5, + fig_retina = if (!fig_caption) 2, fig_caption = FALSE, dev = "png", + smart = TRUE, self_contained = TRUE, highlight = "default", + mathjax = "default", extra_dependencies = NULL, css = NULL, + includes = NULL, keep_md = FALSE, lib_dir = NULL, + md_extensions = NULL, pandoc_args = NULL, ...) +} +\arguments{ +\item{number_sections}{\code{TRUE} to number section headings} + +\item{fig_width}{Default width (in inches) for figures} + +\item{fig_height}{Default width (in inches) for figures} + +\item{fig_retina}{Scaling to perform for retina displays (defaults to 2, which +currently works for all widely used retina displays). Set to \code{NULL} to +prevent retina scaling. Note that this will always be \code{NULL} when +\code{keep_md} is specified (this is because \code{fig_retina} relies on +outputting HTML directly into the markdown document).} + +\item{fig_caption}{\code{TRUE} to render figures with captions} + +\item{dev}{Graphics device to use for figure output (defaults to png)} + +\item{smart}{Produce typographically correct output, converting straight +quotes to curly quotes, --- to em-dashes, -- to en-dashes, and ... to +ellipses.} + +\item{self_contained}{Produce a standalone HTML file with no external +dependencies, using data: URIs to incorporate the contents of linked +scripts, stylesheets, images, and videos. Note that even for self contained +documents MathJax is still loaded externally (this is necessary because of +it's size).} + +\item{highlight}{Syntax highlighting style. Supported styles include +"default", "tango", "pygments", "kate", "monochrome", "espresso", "zenburn", +"haddock", and "textmate". Pass \code{NULL} to prevent syntax highlighting.} + +\item{mathjax}{Include mathjax. The "default" option uses an https URL from a +MathJax CDN. The "local" option uses a local version of MathJax (which is +copied into the output directory). You can pass an alternate URL or pass +\code{NULL} to exclude MathJax entirely.} + +\item{extra_dependencies, ...}{Additional function arguments to pass to the +base R Markdown HTML output formatter} + +\item{css}{One or more css files to include} + +\item{includes}{Named list of additional content to include within the +document (typically created using the \code{\link{includes}} function).} + +\item{keep_md}{Keep the markdown file generated by knitting.} + +\item{lib_dir}{Directory to copy dependent HTML libraries (e.g. jquery, +bootstrap, etc.) into. By default this will be the name of the document with +\code{_files} appended to it.} + +\item{md_extensions}{Markdown extensions to be added or removed from the +default definition or R Markdown. See the \code{\link{rmarkdown_format}} for +additional details.} + +\item{pandoc_args}{Additional command line options to pass to pandoc} +} +\description{ +Template for creating an R markdown document with an emphasis on typography +}