├── .Rbuildignore ├── .gitignore ├── DESCRIPTION ├── LICENSE ├── LICENSE.md ├── NAMESPACE ├── R ├── 00-utils.R ├── alpinejs.R ├── imports.R └── tachyons.R ├── README.md ├── inst ├── alpinejs │ ├── alpine-ie11.js │ ├── alpine.js │ └── alpine.min.js ├── package-lock.json ├── package.json └── tachyons │ ├── tachyons.css │ └── tachyons.min.css ├── man ├── alpinejs.Rd ├── style_colors.Rd ├── style_tachyons.Rd └── tachyons.Rd ├── sprinkles.Rproj └── tests ├── testthat.R └── testthat ├── test-alpinejs.R └── test-tachyons.R /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^sprinkles\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^inst/node_modules$ 4 | ^LICENSE\.md$ 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | inst/node_modules 2 | 3 | # ---- Default .gitignore From grkmisc ---- 4 | .Rproj.user 5 | .Rhistory 6 | .RData 7 | .DS_Store 8 | README.html 9 | 10 | # vscode 11 | .history/ 12 | 13 | # Directories that start with _ 14 | _*/ 15 | 16 | ## https://github.com/github/gitignore/blob/master/R.gitignore 17 | # History files 18 | .Rhistory 19 | .Rapp.history 20 | 21 | # Session Data files 22 | .RData 23 | 24 | # Example code in package build process 25 | *-Ex.R 26 | 27 | # Output files from R CMD build 28 | /*.tar.gz 29 | 30 | # Output files from R CMD check 31 | /*.Rcheck/ 32 | 33 | # RStudio files 34 | .Rproj.user/ 35 | 36 | # produced vignettes 37 | vignettes/*.html 38 | vignettes/*.pdf 39 | 40 | # OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3 41 | .httr-oauth 42 | 43 | # knitr and R markdown default cache directories 44 | /*_cache/ 45 | /cache/ 46 | 47 | # Temporary files created by R markdown 48 | *.utf8.md 49 | *.knit.md 50 | 51 | # Shiny token, see https://shiny.rstudio.com/articles/shinyapps.html 52 | rsconnect/ 53 | 54 | ## https://github.com/github/gitignore/blob/master/Global/macOS.gitignore 55 | # General 56 | .DS_Store 57 | .AppleDouble 58 | .LSOverride 59 | 60 | # Icon must end with two \r 61 | Icon 62 | 63 | 64 | # Thumbnails 65 | ._* 66 | 67 | # Files that might appear in the root of a volume 68 | .DocumentRevisions-V100 69 | .fseventsd 70 | .Spotlight-V100 71 | .TemporaryItems 72 | .Trashes 73 | .VolumeIcon.icns 74 | .com.apple.timemachine.donotpresent 75 | 76 | # Directories potentially created on remote AFP share 77 | .AppleDB 78 | .AppleDesktop 79 | Network Trash Folder 80 | Temporary Items 81 | .apdisk 82 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: sprinkles 2 | Title: Utility CSS and JavaScript for 'R Markdown' 3 | Version: 0.0.0.9000 4 | Authors@R: 5 | c(person(given = "Garrick", 6 | family = "Aden-Buie", 7 | role = c("aut", "cre"), 8 | email = "garrick@adenbuie.com", 9 | comment = c(ORCID = "0000-0002-7111-0077")), 10 | person(family = "Tachyons authors", 11 | role = "ctb"), 12 | person(family = "Caleb Porzio and contributors", 13 | role = "ctb")) 14 | Description: Utility CSS and JavaScript for 'R Markdown', using 15 | 'Tachyons' and 'AlpineJS'. 16 | License: MIT + file LICENSE 17 | URL: https://github.com/gadenbuie/sprinkles 18 | BugReports: https://github.com/gadenbuie/sprinkles/issues 19 | Imports: 20 | glue, 21 | htmltools (>= 0.5.1), 22 | jsonlite 23 | Suggests: 24 | testthat (>= 3.0.0) 25 | Config/testthat/edition: 3 26 | Encoding: UTF-8 27 | LazyData: true 28 | Roxygen: list(markdown = TRUE) 29 | RoxygenNote: 7.1.1 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2021 2 | COPYRIGHT HOLDER: sprinkles authors 3 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2021 sprinkles authors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(html_dependency_alpinejs) 4 | export(html_dependency_tachyons) 5 | export(style_colors) 6 | export(style_tachyons) 7 | export(use_alpinejs) 8 | export(use_tachyons) 9 | importFrom(glue,glue) 10 | importFrom(glue,glue_collapse) 11 | -------------------------------------------------------------------------------- /R/00-utils.R: -------------------------------------------------------------------------------- 1 | `%||%` <- function(x, y) if (is.null(x)) y else x 2 | 3 | pkg_file <- function(...) { 4 | system.file(..., package = "sprinkles", mustWork = TRUE) 5 | } 6 | 7 | glue_chr <- function(..., .envir = parent.frame(), collapse = "\n") { 8 | paste(as.character(glue::glue(..., .envir = .envir)), collapse = collapse) 9 | } 10 | 11 | pkg_lock_deps <- function(dep = NULL) { 12 | deps <- jsonlite::read_json(pkg_file("package-lock.json")) 13 | if (is.null(dep)) { 14 | deps 15 | } else { 16 | deps$dependencies[[dep]] 17 | } 18 | } 19 | 20 | src_href <- function(local, cdn = NULL, use_both = FALSE) { 21 | if (!is.null(cdn)) { 22 | x <- c(href = cdn, file = local) 23 | if (isTRUE(use_both)) return(x) 24 | x["href"] 25 | } else { 26 | c(file = local) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /R/alpinejs.R: -------------------------------------------------------------------------------- 1 | #' Alpine.js 2 | #' 3 | #' Alpine.js is a rugged, minimal framework for composing JavaScript behavior in 4 | #' your markup. . 5 | #' 6 | #' @return An `htmltools::tagList()` with the Alpine.js dependencies, or an 7 | #' [htmltools::htmlDependency()]. 8 | #' 9 | #' @references [Alpine.js](https://github.com/alpinejs/alpine/) 10 | #' @name alpinejs 11 | NULL 12 | 13 | #' @describeIn alpinejs Adds Alpine.js dependencies to your document. 14 | #' @param minified Use the minified Alpine.js file? Default is `TRUE`. 15 | #' @export 16 | use_alpinejs <- function(minified = TRUE) { 17 | htmltools::tagList( 18 | html_dependency_alpinejs(minified) 19 | ) 20 | } 21 | 22 | #' @describeIn alpinejs Returns an [htmltools::htmlDependency()] with the 23 | #' alpinejs dependencies. Most users will want to use `use_alpinejs()`. 24 | #' @param cdn The URL to an online location for Alpine.js, typically a CDN. 25 | #' Include the URL, without the CSS file, e.g. the full URL minus the 26 | #' `alpine.js` or `alpine.min.js`. 27 | #' @param version The version of the Alpine.js resource hosted at the URL in 28 | #' `cdn`. 29 | #' @export 30 | html_dependency_alpinejs <- function(minified = TRUE, cdn = NULL, version = NULL) { 31 | if (!is.null(cdn) && is.null(version)) { 32 | stop("If using a CDN, you must specify the version of Alpine.js") 33 | } 34 | htmltools::htmlDependency( 35 | name = "alpinejs", 36 | version = version %||% pkg_lock_deps("alpinejs")$version, 37 | src = src_href(pkg_file("alpinejs"), cdn), 38 | script = paste0("alpine", if (minified) ".min", ".js"), 39 | all_files = FALSE 40 | ) 41 | } 42 | -------------------------------------------------------------------------------- /R/imports.R: -------------------------------------------------------------------------------- 1 | #' @importFrom glue glue glue_collapse 2 | NULL 3 | -------------------------------------------------------------------------------- /R/tachyons.R: -------------------------------------------------------------------------------- 1 | #' Tachyons 2 | #' 3 | #' Tachyons is a collection of CSS utility classes that works beautifully with 4 | #' \pkg{xaringan} presentations using the `remarkjs`` class syntax. 5 | #' 6 | #' @return An `htmltools::tagList()` with the tachyons dependencies, or an 7 | #' [htmltools::htmlDependency()]. 8 | #' @section Usage: To add tachyons to your xaringan presentation, add the 9 | #' following code chunk to your slides' R Markdown file. 10 | #' 11 | #' ````markdown 12 | #' ```{r xaringan-tachyons, echo=FALSE} 13 | #' xaringanExtra::use_tachyons() 14 | #' ``` 15 | #' ```` 16 | #' 17 | #' Tachyons provides small, single-purpose CSS classes that are easily composed 18 | #' to achieve larger functionality and styles. In the [remarkjs content classes 19 | #' syntax](https://github.com/gnab/remark/wiki/Markdown#content-classes), you 20 | #' can compose classes by chaining them together. For example, the following 21 | #' markdown produces a box with a washed green background (`.bg-washed-green`), 22 | #' a dark green border (`.b--dark-green`) on all sides (`.ba`) with line width 23 | #' 2 (`.bw2`) and border radius (`.br3`). The box has a shadow (`.shadow-5`) 24 | #' and medium-large horizontal padding (`.ph4`) with a large top margin 25 | #' (`.mt5`). 26 | #' 27 | #' ```markdown 28 | #' .bg-washed-green.b--dark-green.ba.bw2.br3.shadow-5.ph4.mt5[ 29 | #' The only way to write good code is to write tons of bad code first. 30 | #' Feeling shame about bad code stops you from getting to good code 31 | #' 32 | #' .tr[ 33 | #' — Hadley Wickham 34 | #' ]] 35 | #' ``` 36 | #' 37 | #' @references [tachyons](http://tachyons.io/), 38 | #' [Tachyons Cheat Sheet](https://roperzh.github.io/tachyons-cheatsheet/) 39 | #' @family tachyons 40 | #' @name tachyons 41 | NULL 42 | 43 | #' @describeIn tachyons Adds tachyons to your xaringan slides. 44 | #' @param minified Use the minified Tachyons css file? Default is `TRUE`. 45 | #' @export 46 | use_tachyons <- function(minified = TRUE) { 47 | htmltools::tagList( 48 | html_dependency_tachyons(minified) 49 | ) 50 | } 51 | 52 | #' @describeIn tachyons Returns an [htmltools::htmlDependency()] with the tile 53 | #' view dependencies. Most users will want to use `use_tachyons()`. 54 | #' @param cdn The URL to an online location for Tachyons, typically a CDN. 55 | #' Include the URL, without the CSS file, e.g. the full URL minus the 56 | #' `tachyons.min.css` or `tachyons.css`. 57 | #' @param version The version of the Tachyons resource hosted at the URL in 58 | #' `cdn`. 59 | #' @export 60 | html_dependency_tachyons <- function(minified = TRUE, cdn = NULL, version = NULL) { 61 | if (!is.null(cdn) && is.null(version)) { 62 | stop("If using a CDN, you must specify the version of Tachyons") 63 | } 64 | tachyons_lock <- pkg_lock_deps("tachyons") 65 | htmltools::htmlDependency( 66 | name = "tachyons", 67 | version = version %||% tachyons_lock$version, 68 | src = src_href(pkg_file("tachyons"), cdn), 69 | stylesheet = paste0("tachyons", if (minified) ".min", ".css"), 70 | all_files = FALSE 71 | ) 72 | } 73 | 74 | 75 | list_tachyons_vars <- function() { 76 | tc <- pkg_file("tachyons", "tachyons.css") 77 | tc <- readLines(tc) 78 | tc <- gsub(";", "&;", tc) 79 | tc <- unlist(strsplit(tc, ";")) 80 | m <- regexec("--([[:graph:]]+): ([^;]+)&$", tc) 81 | m <- regmatches(tc, m) 82 | m <- m[vapply(m, length, integer(1)) > 0] 83 | m <- do.call(rbind, m)[,2:3] 84 | vars <- as.list(m[, 2]) 85 | names(vars) <- m[, 1] 86 | vars 87 | } 88 | 89 | args_tachyons_vars <- function() { 90 | vars <- lapply(list_tachyons_vars(), function(...) NULL) 91 | names(vars) <- gsub("-", "_", names(vars)) 92 | vars 93 | } 94 | 95 | params_tachyons_vars <- function() { 96 | vars <- unlist(list_tachyons_vars()) 97 | vars_names <- names(vars) 98 | vars_underscore <- gsub("-", "_", names(vars)) 99 | glue_collapse( 100 | glue( 101 | "\\item{[vars_underscore]}{\\code{--[vars_names]}, default is \\code{[vars]}}", 102 | .open = "[", 103 | .close = "]" 104 | ), 105 | sep = "\n" 106 | ) 107 | } 108 | 109 | #' Style Tachyons 110 | #' 111 | #' Creates a `")) 60 | }) 61 | }) 62 | --------------------------------------------------------------------------------