diff --git a/.Rbuildignore b/.Rbuildignore index 2a0cf9e..918f12e 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -8,3 +8,4 @@ ^codecov\.yml$ ^_pkgdown\.yml$ ^docs$ +^\.github$ diff --git a/.github/.gitignore b/.github/.gitignore new file mode 100644 index 0000000..2d19fc7 --- /dev/null +++ b/.github/.gitignore @@ -0,0 +1 @@ +*.html diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml new file mode 100644 index 0000000..10c51d1 --- /dev/null +++ b/.github/workflows/R-CMD-check.yaml @@ -0,0 +1,81 @@ +# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag. +# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions +on: + push: + branches: + - master + pull_request: + branches: + - master + +name: R-CMD-check + +jobs: + R-CMD-check: + runs-on: ${{ matrix.config.os }} + + name: ${{ matrix.config.os }} (${{ matrix.config.r }}) + + strategy: + fail-fast: false + matrix: + config: + - {os: windows-latest, r: 'release'} + - {os: macOS-latest, r: 'release'} + - {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} + - {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} + + env: + R_REMOTES_NO_ERRORS_FROM_WARNINGS: true + RSPM: ${{ matrix.config.rspm }} + + steps: + - uses: actions/checkout@v2 + + - uses: r-lib/actions/setup-r@master + with: + r-version: ${{ matrix.config.r }} + + - uses: r-lib/actions/setup-pandoc@master + + - name: Query dependencies + run: | + install.packages('remotes') + saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) + writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") + shell: Rscript {0} + + - name: Cache R packages + if: runner.os != 'Windows' + uses: actions/cache@v2 + with: + path: ${{ env.R_LIBS_USER }} + key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} + restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- + + - name: Install system dependencies + if: runner.os == 'Linux' + run: | + while read -r cmd + do + eval sudo $cmd + done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))') + + - name: Install dependencies + run: | + remotes::install_deps(dependencies = TRUE) + remotes::install_cran("rcmdcheck") + shell: Rscript {0} + + - name: Check + env: + _R_CHECK_CRAN_INCOMING_REMOTE_: false + run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check") + shell: Rscript {0} + + - name: Upload check results + if: failure() + uses: actions/upload-artifact@main + with: + name: ${{ runner.os }}-r${{ matrix.config.r }}-results + path: check diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml new file mode 100644 index 0000000..5871380 --- /dev/null +++ b/.github/workflows/pkgdown.yaml @@ -0,0 +1,46 @@ +on: + push: + branches: master + +name: pkgdown + +jobs: + pkgdown: + runs-on: macOS-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v2 + + - uses: r-lib/actions/setup-r@master + + - uses: r-lib/actions/setup-pandoc@master + + - name: Query dependencies + run: | + install.packages('remotes') + saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) + writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") + shell: Rscript {0} + + - name: Cache R packages + uses: actions/cache@v2 + with: + path: ${{ env.R_LIBS_USER }} + key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} + restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- + + - name: Install dependencies + run: | + remotes::install_deps(dependencies = TRUE) + install.packages("pkgdown") + shell: Rscript {0} + + - name: Install package + run: R CMD INSTALL . + + - name: Deploy package + run: | + git config --local user.email "actions@github.com" + git config --local user.name "GitHub Actions" + Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE)' diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b8455a4..0000000 --- a/.travis.yml +++ /dev/null @@ -1,16 +0,0 @@ -# R for travis: see documentation at https://docs.travis-ci.com/user/languages/r - -language: R -sudo: false -cache: packages - -matrix: - include: - - r: devel - - r: release - before_deploy: Rscript -e 'remotes::install_cran("pkgdown")' - deploy: - provider: script - script: Rscript -e 'pkgdown::deploy_site_github()' - skip_cleanup: true - - r: oldrel diff --git a/DESCRIPTION b/DESCRIPTION index d0d643a..63f1da9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: vembedr Title: Embed Video in HTML -Version: 0.1.3.9000 +Version: 0.1.3.9001 Authors@R: c( person( given = "Ian", @@ -27,7 +27,7 @@ Imports: glue, assertthat, utils -RoxygenNote: 6.1.1 +RoxygenNote: 7.1.1 URL: https://github.com/ijlyttle/vembedr BugReports: https://github.com/ijlyttle/vembedr/issues Suggests: diff --git a/R/parse.R b/R/parse.R index 7bce50a..54a9145 100644 --- a/R/parse.R +++ b/R/parse.R @@ -174,29 +174,23 @@ get_service <- function(url) { #' parse_video_url <- function(url) { - list_parse <- list( - channel9 = .parse_channel9, - youtube = .parse_youtube, - youtube_short = .parse_youtube_short, - vimeo = .parse_vimeo, - box = .parse_box - ) - service <- get_service(url) url_parsed <- httr::parse_url(url) + class(url_parsed) <- c(glue::glue("vembedr_{service}")) - # idea: - # - this could be done more-conventionally using S3 dispatch - # - get_service() could return a parsed url with additional class - # - fn_parse <- list_parse[[service]] + .parse(url_parsed) +} - do.call(fn_parse, list(url_parsed = url_parsed)) +.parse <- function(url_parsed, ...) { + UseMethod(".parse") +} +.parse.default <- function(url_parsed, ...) { + stop("no method available") } -.parse_youtube <- function(url_parsed) { +.parse.vembedr_youtube <- function(url_parsed, ...) { list( service = "youtube", id = url_parsed$query$v, @@ -204,7 +198,7 @@ parse_video_url <- function(url) { ) } -.parse_youtube_short <- function(url_parsed) { +.parse.vembedr_youtube_short <- function(url_parsed, ...) { list( service = "youtube", id = url_parsed$path, @@ -212,7 +206,7 @@ parse_video_url <- function(url) { ) } -.parse_vimeo <- function(url_parsed){ +.parse.vembedr_vimeo <- function(url_parsed, ...){ start_time <- NULL if (!is.null(url_parsed$fragment)){ @@ -226,7 +220,7 @@ parse_video_url <- function(url) { ) } -.parse_channel9 <- function(url_parsed){ +.parse.vembedr_channel9 <- function(url_parsed, ...){ path_split <- url_parsed$path %>% @@ -270,7 +264,7 @@ parse_video_url <- function(url) { result } -.parse_box <- function(url_parsed) { +.parse.vembedr_box <- function(url_parsed, ...) { # determine custom-domain by taking apart hostname hostname_split <- stringr::str_split(url_parsed$hostname, "\\.")[[1]] diff --git a/README.Rmd b/README.Rmd index 402ffda..5751ec9 100644 --- a/README.Rmd +++ b/README.Rmd @@ -6,10 +6,12 @@ output: # vembedr -[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/vembedr)](https://cran.r-project.org/package=vembedr) -[![Travis-CI Build Status](https://travis-ci.org/ijlyttle/vembedr.svg?branch=master)](https://travis-ci.org/ijlyttle/vembedr) -[![lifecycle](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://www.tidyverse.org/lifecycle/#maturing) - + + [![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/vembedr)](https://cran.r-project.org/package=vembedr) + [![R build status](https://github.com/ijlyttle/vembedr/workflows/R-CMD-check/badge.svg)](https://github.com/ijlyttle/vembedr/actions) + [![lifecycle](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://www.tidyverse.org/lifecycle/#maturing) + + ```{r, echo = FALSE} library("htmltools") library("vembedr") diff --git a/man/embed.Rd b/man/embed.Rd index f2cc0c8..3245c75 100644 --- a/man/embed.Rd +++ b/man/embed.Rd @@ -10,25 +10,63 @@ \alias{embed_box} \title{Embed a video into an HTML document} \usage{ -embed_vimeo(id, width = NULL, height = 300, ratio = c("16by9", - "4by3"), frameborder = 0, allowfullscreen = TRUE, query = NULL, - fragment = NULL) +embed_vimeo( + id, + width = NULL, + height = 300, + ratio = c("16by9", "4by3"), + frameborder = 0, + allowfullscreen = TRUE, + query = NULL, + fragment = NULL +) -embed_youtube(id, width = NULL, height = 300, ratio = c("16by9", - "4by3"), frameborder = 0, allowfullscreen = TRUE, query = NULL) +embed_youtube( + id, + width = NULL, + height = 300, + ratio = c("16by9", "4by3"), + frameborder = 0, + allowfullscreen = TRUE, + query = NULL +) -embed_user2016(id, width = NULL, height = 300, ratio = c("16by9", - "4by3"), frameborder = 0, allowfullscreen = TRUE) +embed_user2016( + id, + width = NULL, + height = 300, + ratio = c("16by9", "4by3"), + frameborder = 0, + allowfullscreen = TRUE +) -embed_user2017(id, width = NULL, height = 300, ratio = c("16by9", - "4by3"), frameborder = 0, allowfullscreen = TRUE) +embed_user2017( + id, + width = NULL, + height = 300, + ratio = c("16by9", "4by3"), + frameborder = 0, + allowfullscreen = TRUE +) -embed_channel9(id, width = NULL, height = 300, ratio = c("16by9", - "4by3"), frameborder = 0, allowfullscreen = TRUE) +embed_channel9( + id, + width = NULL, + height = 300, + ratio = c("16by9", "4by3"), + frameborder = 0, + allowfullscreen = TRUE +) -embed_box(id, custom_domain = getOption("vembedr.box_custom_domain"), - width = NULL, height = 300, ratio = c("16by9", "4by3"), - frameborder = 0, allowfullscreen = TRUE) +embed_box( + id, + custom_domain = getOption("vembedr.box_custom_domain"), + width = NULL, + height = 300, + ratio = c("16by9", "4by3"), + frameborder = 0, + allowfullscreen = TRUE +) } \arguments{ \item{id}{character, identifier provided by the service} @@ -37,7 +75,7 @@ embed_box(id, custom_domain = getOption("vembedr.box_custom_domain"), \item{height}{numeric, height of iframe (px)} -\item{ratio}{\code{character}, indicates aspect ratio for the \code{