diff --git a/.Rbuildignore b/.Rbuildignore index 6053f04..bf07379 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -15,3 +15,4 @@ ^tmp$ ^notes$ ^\.gitlab-ci\.yml$ +^LICENSE\.md$ diff --git a/DESCRIPTION b/DESCRIPTION index ca2b8a2..822900c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,25 +1,23 @@ Package: widgetcard Type: Package Title: Tools to Enable Easier Content Embedding in Tweets -Version: 0.1.1 -Date: 2019-04-04 +Version: 0.2.0 +Date: 2019-08-14 Authors@R: c( person("Bob", "Rudis", email = "bob@rud.is", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-5670-2640")) ) Maintainer: Bob Rudis -Description: Tools to enable rasier content embedding in tweets. +Description: Tools to enable easier content embedding in tweets. URL: https://gitlab.com/hrbrmstr/widgetcard BugReports: https://gitlab.com/hrbrmstr/widgetcard/issues Encoding: UTF-8 -License: AGPL +License: MIT + file LICENSE Suggests: ssh, plotly, testthat, - covr, - knitr, - rmarkdown + covr Depends: R (>= 3.2.0) Imports: @@ -28,7 +26,9 @@ Imports: widgetframe, ggplot2, shiny, - jsonlite + jsonlite, + knitr, + rmarkdown Roxygen: list(markdown = TRUE) RoxygenNote: 6.1.1 VignetteBuilder: knitr diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b6a10f1 --- /dev/null +++ b/LICENSE @@ -0,0 +1,2 @@ +YEAR: 2019 +COPYRIGHT HOLDER: Bob Rudis diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..c36552c --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +# MIT License + +Copyright (c) 2019 Bob Rudis + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/NAMESPACE b/NAMESPACE index 9530a13..ca8cde2 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,6 +2,7 @@ export(card_widget) export(gg_preview) +export(twitter_document) import(htmltools) import(htmlwidgets) import(widgetframe) diff --git a/R/twitter-doc.R b/R/twitter-doc.R new file mode 100644 index 0000000..9c626db --- /dev/null +++ b/R/twitter-doc.R @@ -0,0 +1,46 @@ +#' Standard HTML Document with Twitter Tags +#' +#' @inheritParams rmarkdown::html_document +#' @export +twitter_document <- function ( + toc = FALSE, toc_depth = 3, toc_float = FALSE, number_sections = FALSE, + section_divs = TRUE, fig_width = 7, fig_height = 5, fig_retina = 2, + fig_caption = TRUE, dev = "png", df_print = "default", + code_folding = c("none", "show", "hide"), code_download = FALSE, smart = TRUE, + self_contained = TRUE, theme = "default", highlight = "default", + mathjax = "default", extra_dependencies = NULL, + css = NULL, includes = NULL, keep_md = FALSE, lib_dir = NULL, + md_extensions = NULL, pandoc_args = NULL, ...) { + + + rmarkdown::html_document( + template = system.file('rmarkdown/templates/twittercard/default.html', package = 'widgetcard'), + toc = toc, + toc_depth = toc_depth, + toc_float = toc_float, + number_sections = number_sections, + section_divs = section_divs, + fig_width = fig_width, + fig_height = fig_height, + fig_retina = fig_retina, + fig_caption = fig_caption, + dev = dev, + df_print = df_print, + code_folding = code_folding, + code_download = code_download, + smart = smart, + self_contained = self_contained, + theme = theme, + highlight = highlight, + mathjax = mathjax, + extra_dependencies = extra_dependencies, + css = css, + includes = includes, + keep_md = keep_md, + lib_dir = lib_dir, + md_extensions = md_extensions, + pandoc_args = pandoc_args, + ... + ) + +} \ No newline at end of file diff --git a/README.Rmd b/README.Rmd index 49bac53..a58cf1f 100644 --- a/README.Rmd +++ b/README.Rmd @@ -1,42 +1,32 @@ --- -output: rmarkdown::github_document -editor_options: - chunk_output_type: inline +output: + rmarkdown::github_document: + df_print: kable --- ```{r pkg-knitr-opts, include=FALSE} -knitr::opts_chunk$set(collapse=TRUE, fig.retina=2, message=FALSE, warning=FALSE) -options(width=120) +hrbrpkghelpr::global_opts() ``` -[![Travis-CI Build Status](https://travis-ci.org/hrbrmstr/widgetcard.svg?branch=master)](https://travis-ci.org/hrbrmstr/widgetcard) -[![Coverage Status](https://codecov.io/gh/hrbrmstr/widgetcard/branch/master/graph/badge.svg)](https://codecov.io/gh/hrbrmstr/widgetcard) -[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/widgetcard)](https://cran.r-project.org/package=widgetcard) - -# widgetcard - -Tools to Enable Easier Content Embedding in Tweets - -## Description +```{r badges, results='asis', echo=FALSE, cache=FALSE} +hrbrpkghelpr::stinking_badges() +``` -Tools to Enable Easier Content Embedding in Tweets +```{r description, results='asis', echo=FALSE, cache=FALSE} +hrbrpkghelpr::yank_title_and_description() +``` ## What's Inside The Tin The following functions are implemented: -- `card_widget`: Turn an htmlwidget into a web deployable, interactive Twitter card -- `gg_preview`: Generate a Twitter Player card preview image from a ggplot2 plot +```{r ingredients, results='asis', echo=FALSE, cache=FALSE} +hrbrpkghelpr::describe_ingredients() +``` ## Installation -```{r install-ex, eval=FALSE} -install.packages("widgetcard", repos = "https://cinc.rud.is/") -# or -devtools::install_git("https://git.sr.ht/~hrbrmstr/widgetcard") -# or -devtools::install_gitlab("hrbrmstr/widgetcard") -# or (if you must) -devtools::install_github("hrbrmstr/widgetcard") +```{r install-ex, results='asis', echo=FALSE, cache=FALSE} +hrbrpkghelpr::install_block() ``` ## Usage @@ -51,5 +41,4 @@ cloc::cloc_pkg_md() ## Code of Conduct -Please note that this project is released with a [Contributor Code of Conduct](CONDUCT.md). -By participating in this project you agree to abide by its terms. +Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. diff --git a/README.md b/README.md index e78c0dc..0b8d4d7 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,18 @@ -[![Travis-CI Build +[![Project Status: Active – The project has reached a stable, usable +state and is being actively +developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) +[![Signed +by](https://img.shields.io/badge/Keybase-Verified-brightgreen.svg)](https://keybase.io/hrbrmstr) +![Signed commit +%](https://img.shields.io/badge/Signed_Commits-87.5%25-lightgrey.svg) +[![Linux build Status](https://travis-ci.org/hrbrmstr/widgetcard.svg?branch=master)](https://travis-ci.org/hrbrmstr/widgetcard) [![Coverage Status](https://codecov.io/gh/hrbrmstr/widgetcard/branch/master/graph/badge.svg)](https://codecov.io/gh/hrbrmstr/widgetcard) -[![CRAN\_Status\_Badge](https://www.r-pkg.org/badges/version/widgetcard)](https://cran.r-project.org/package=widgetcard) +![Minimal R +Version](https://img.shields.io/badge/R%3E%3D-3.2.0-blue.svg) +![License](https://img.shields.io/badge/License-MIT-blue.svg) # widgetcard @@ -11,7 +20,7 @@ Tools to Enable Easier Content Embedding in Tweets ## Description -Tools to Enable Easier Content Embedding in Tweets +Tools to enable easier content embedding in tweets. ## What’s Inside The Tin @@ -21,19 +30,27 @@ The following functions are implemented: Twitter card - `gg_preview`: Generate a Twitter Player card preview image from a ggplot2 plot + - `twitter_document`: Standard HTML Document with Twitter Tags ## Installation ``` r -install.packages("widgetcard", repos = "https://cinc.rud.is/") +install.packages("widgetcard", repos = "https://cinc.rud.is") +# or +remotes::install_git("https://git.rud.is/hrbrmstr/widgetcard.git") +# or +remotes::install_git("https://git.sr.ht/~hrbrmstr/widgetcard") # or -devtools::install_git("https://git.sr.ht/~hrbrmstr/widgetcard") -# or -devtools::install_gitlab("hrbrmstr/widgetcard") -# or (if you must) -devtools::install_github("hrbrmstr/widgetcard") +remotes::install_gitlab("hrbrmstr/widgetcard") +# or +remotes::install_bitbucket("hrbrmstr/widgetcard") +# or +remotes::install_github("hrbrmstr/widgetcard") ``` +NOTE: To use the ‘remotes’ install options you will need to have the +[{remotes} package](https://github.com/r-lib/remotes) installed. + ## Usage See [the @@ -43,12 +60,12 @@ vignette](https://rud.is/dl/creating-interactive-player-cards.html). | Lang | \# Files | (%) | LoC | (%) | Blank lines | (%) | \# Lines | (%) | | :--- | -------: | ---: | --: | ---: | ----------: | ---: | -------: | ---: | -| HTML | 1 | 0.09 | 370 | 0.47 | 31 | 0.20 | 1 | 0.00 | -| R | 7 | 0.64 | 327 | 0.41 | 66 | 0.42 | 168 | 0.48 | -| Rmd | 3 | 0.27 | 93 | 0.12 | 61 | 0.39 | 182 | 0.52 | +| HTML | 1 | 0.08 | 370 | 0.44 | 31 | 0.19 | 1 | 0.00 | +| R | 8 | 0.67 | 370 | 0.44 | 70 | 0.44 | 172 | 0.49 | +| Rmd | 3 | 0.25 | 92 | 0.11 | 58 | 0.36 | 175 | 0.50 | ## Code of Conduct -Please note that this project is released with a [Contributor Code of -Conduct](CONDUCT.md). By participating in this project you agree to -abide by its terms. +Please note that this project is released with a Contributor Code of +Conduct. By participating in this project you agree to abide by its +terms. diff --git a/inst/rmarkdown/templates/twittercard/default.html b/inst/rmarkdown/templates/twittercard/default.html new file mode 100644 index 0000000..2f8763d --- /dev/null +++ b/inst/rmarkdown/templates/twittercard/default.html @@ -0,0 +1,668 @@ + + + + + + + + + + + + + +$if(theme)$ +$else$ + +$endif$ + +$for(author-meta)$ + +$endfor$ + +$if(date-meta)$ + +$endif$ + +$if(twitter-meta)$ +TWITTER META +$endif$ + +$if(twitter)$ + +$if(twitter.site)$$endif$ +$if(twitter.creator)$$endif$ +$if(title)$$endif$ +$if(twitter.description)$$endif$ +$if(twitter.image)$$endif$ +$endif$ + +$if(title-prefix)$$title-prefix$ - $endif$$pagetitle$ + +$for(header-includes)$ +$header-includes$ +$endfor$ + +$if(highlightjs)$ + +$if(theme)$ + +$endif$ + +$endif$ + +$if(highlighting-css)$ + + + +$if(theme)$ + +$endif$ +$endif$ + +$if(abstract)$ + +$endif$ + +$if(theme)$ + +$endif$ + +$for(css)$ + +$endfor$ + + + +$if(theme)$ + + +$if(kable-scroll)$ + +$endif$ + +$if(navbar)$ + + + +$endif$ + + + + + + +$if(code_menu)$ + +$endif$ + + +$if(toc_float)$ + + + +$endif$ + +$endif$ + + + + + +$if(theme)$ + +
+ +$if(toc_float)$ + + +
+
+
+
+
+ +
+ +$endif$ + +$endif$ + +$for(include-before)$ +$include-before$ +$endfor$ + +$if(theme)$ +
+ +$if(code_menu)$ +
+ + +
+ +$endif$ + +$endif$ + +$if(title)$ +

$title$

+$if(subtitle)$ +

$subtitle$

+$endif$ +$for(author)$ +$if(author.name)$ +

$author.name$

+$if(author.affiliation)$ +
+$author.affiliation$
$endif$ +$if(author.email)$ +$author.email$ +
+$endif$ +$else$ +

$author$

+$endif$ +$endfor$ +$if(date)$ +

$date$

+$endif$ +$if(abstract)$ +
+

Abstract

+$abstract$ +
+$endif$ +$endif$ + +$if(theme)$ +
+$endif$ + +$if(toc_float)$ +$else$ +$if(toc)$ +
+$toc$ +
+$endif$ +$endif$ + +$body$ + +$for(include-after)$ +$include-after$ +$endfor$ + +$if(theme)$ + +$if(toc_float)$ +
+
+$endif$ + +
+ + + + + + +$endif$ + + +$if(code_menu)$ + +$endif$ + +$if(toc_float)$ + +$endif$ + +$if(mathjax-url)$ + + +$endif$ + + + diff --git a/inst/rmarkdown/templates/twittercard/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/twittercard/skeleton/skeleton.Rmd new file mode 100644 index 0000000..64194a5 --- /dev/null +++ b/inst/rmarkdown/templates/twittercard/skeleton/skeleton.Rmd @@ -0,0 +1,11 @@ +--- +title: "Doc title which will also get passed to the twitter card" +twitter: + description: "Description for Twitter" + site: "\\@handle" + creator: "\\@handle" + image: "https\\:\\/\\/some.image\\/link\\.png" +output: widgetcard::twitter_document +--- + +NOTE That the backslash escapes in the `description`, `site`, `creator`, and `image` metadata params are required to prevent pandoc from turning them into unwanted HTML. diff --git a/inst/rmarkdown/templates/twittercard/template.yaml b/inst/rmarkdown/templates/twittercard/template.yaml new file mode 100644 index 0000000..8dea55e --- /dev/null +++ b/inst/rmarkdown/templates/twittercard/template.yaml @@ -0,0 +1,4 @@ +name: Standard HTML Document with Twitter Tags +description: > + Standard HTML Document with Twitter Tags +create_dir: false \ No newline at end of file diff --git a/man/twitter_document.Rd b/man/twitter_document.Rd new file mode 100644 index 0000000..9def367 --- /dev/null +++ b/man/twitter_document.Rd @@ -0,0 +1,117 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/twitter-doc.R +\name{twitter_document} +\alias{twitter_document} +\title{Standard HTML Document with Twitter Tags} +\usage{ +twitter_document(toc = FALSE, toc_depth = 3, toc_float = FALSE, + number_sections = FALSE, section_divs = TRUE, fig_width = 7, + fig_height = 5, fig_retina = 2, fig_caption = TRUE, dev = "png", + df_print = "default", code_folding = c("none", "show", "hide"), + code_download = FALSE, smart = TRUE, self_contained = TRUE, + theme = "default", 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{toc}{\code{TRUE} to include a table of contents in the output} + +\item{toc_depth}{Depth of headers to include in table of contents} + +\item{toc_float}{\code{TRUE} to float the table of contents to the left of the +main document content. Rather than \code{TRUE} you may also pass a list of +options that control the behavior of the floating table of contents. See the +\emph{Floating Table of Contents} section below for details.} + +\item{number_sections}{\code{TRUE} to number section headings} + +\item{section_divs}{Wrap sections in
tags (or
tags in HTML5), +and attach identifiers to the enclosing
(or
) rather than the +header itself.} + +\item{fig_width}{Default width (in inches) for figures} + +\item{fig_height}{Default height (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{df_print}{Method to be used for printing data frames. Valid values +include "default", "kable", "tibble", and "paged". The "default" method uses +\code{print.data.frame}. The "kable" method uses the +\code{\link[knitr:kable]{knitr::kable}} function. The "tibble" method uses +the \pkg{tibble} package to print a summary of the data frame. The "paged" +method creates a paginated HTML table (note that this method is only valid +for formats that produce HTML). In addition +to the named methods you can also pass an arbitrary function to be used +for printing data frames. You can disable the \code{df_print} behavior entirely +by setting the option \code{rmarkdown.df_print} to \code{FALSE}.} + +\item{code_folding}{Enable document readers to toggle the display of R code +chunks. Specify \code{"none"} to display all code chunks (assuming +they were knit with \code{echo = TRUE}). Specify \code{"hide"} to hide all R +code chunks by default (users can show hidden code chunks either +individually or document-wide). Specify \code{"show"} to show all R code +chunks by default.} + +\item{code_download}{Embed the Rmd source code within the document and provide +a link that can be used by readers to download the code.} + +\item{smart}{Produce typographically correct output, converting straight +quotes to curly quotes, \code{---} to em-dashes, \code{--} to en-dashes, and +\code{...} 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 +its size).} + +\item{theme}{Visual theme ("default", "cerulean", "journal", "flatly", +"darkly", "readable", "spacelab", "united", "cosmo", "lumen", "paper", +"sandstone", "simplex", or "yeti"). Pass \code{NULL} for no theme (in this +case you can use the \code{css} parameter to add your own styles).} + +\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 \code{\link{html_document_base}}} + +\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} + +\item{...}{Additional function arguments to pass to the +base R Markdown HTML output formatter \code{\link{html_document_base}}} +} +\description{ +Standard HTML Document with Twitter Tags +}