Skip to content

Commit

Permalink
removed purrr dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
hrbrmstr committed May 10, 2017
1 parent 52539bf commit 4ed7590
Show file tree
Hide file tree
Showing 18 changed files with 519 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 7 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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")),
Expand Down Expand Up @@ -34,6 +34,11 @@ Imports:
grid,
scales,
extrafont,
purrr
knitr,
rmarkdown,
htmltools,
tools,
magrittr
RoxygenNote: 6.0.1
VignetteBuilder: knitr

9 changes: 6 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
2 changes: 1 addition & 1 deletion R/check.r
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion R/hrbrthemes-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
90 changes: 90 additions & 0 deletions R/ipsum.r
Original file line number Diff line number Diff line change
@@ -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,
...))
}
76 changes: 76 additions & 0 deletions R/utils.r
Original file line number Diff line number Diff line change
@@ -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)
}
9 changes: 7 additions & 2 deletions R/zzz.r
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
3 changes: 2 additions & 1 deletion inst/COPYRIGHTS
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
All R source code files are released under the MIT license.

The Google Roboto Condensed font <https://github.com/google/roboto/> has the folllowing copyright:
The Google Roboto Condensed & Slab fonts <https://github.com/google/roboto/> have
the folllowing copyright:


Apache License
Expand Down
Binary file added inst/fonts/roboto-slab/RobotoSlab-Bold.ttf
Binary file not shown.
Binary file added inst/fonts/roboto-slab/RobotoSlab-Light.ttf
Binary file not shown.
Binary file added inst/fonts/roboto-slab/RobotoSlab-Regular.ttf
Binary file not shown.
Binary file added inst/fonts/roboto-slab/RobotoSlab-Thin.ttf
Binary file not shown.
85 changes: 85 additions & 0 deletions inst/rmarkdown/templates/ipsum/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"$if(lang)$ lang="$lang$" xml:lang="$lang$"$endif$>

<head>

<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>$if(title)$$title$$endif$</title>

<link href="https://fonts.googleapis.com/css?family=Roboto+Slab:100,300,400,700" rel="stylesheet"/>
<link href="https://fonts.googleapis.com/css?family=Roboto+Condensed:300,300i,400,400i,700,700i" rel="stylesheet"/>
<link href="https://fonts.googleapis.com/css?family=Roboto:100,100i,300,300i,400,400i,500,500i,700,700i,900,900i" rel="stylesheet"/>

$for(header-includes)$
$header-includes$
$endfor$

$if(highlightjs)$
<style type="text/css">code{white-space: pre;}</style>
<link rel="stylesheet"
href="$highlightjs$/$if(highlightjs-theme)$$highlightjs-theme$$else$default$endif$.css"
$if(html5)$$else$type="text/css" $endif$/>
<script src="$highlightjs$/highlight.js"></script>
<script type="text/javascript">
if (window.hljs && document.readyState && document.readyState === "complete") {
window.setTimeout(function() {
hljs.initHighlighting();
}, 0);
}
</script>
$endif$

$if(highlighting-css)$
<style type="text/css">code{white-space: pre;}</style>
<style type="text/css">
$highlighting-css$
</style>
$endif$

$for(css)$
<link rel="stylesheet" href="$css$" $if(html5)$$else$type="text/css" $endif$/>
$endfor$

</head>

<body>
<div class="container">

<h1>$if(title)$$title$$endif$</h1>

$for(include-before)$
$include-before$
$endfor$

$if(toc)$
<div id="$idprefix$TOC">
$toc$
</div>
$endif$

$body$

$for(include-after)$
$include-after$
$endfor$

</div>

$if(mathjax-url)$
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "$mathjax-url$";
document.getElementsByTagName("head")[0].appendChild(script);
})();
</script>
$endif$

</body>
</html>
Loading

0 comments on commit 4ed7590

Please sign in to comment.