Skip to content

Commit

Permalink
use S3 dispatch for parsing (#41)
Browse files Browse the repository at this point in the history
* use S3 dispatch for parsing

* use github actions

* add pkgdown action, remove travis
  • Loading branch information
ijlyttle authored Sep 27, 2020
1 parent 37d0479 commit f6cc80a
Show file tree
Hide file tree
Showing 16 changed files with 216 additions and 71 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
^codecov\.yml$
^_pkgdown\.yml$
^docs$
^\.github$
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
81 changes: 81 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -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
46 changes: 46 additions & 0 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -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 "[email protected]"
git config --local user.name "GitHub Actions"
Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE)'
16 changes: 0 additions & 16 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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:
Expand Down
32 changes: 13 additions & 19 deletions R/parse.R
Original file line number Diff line number Diff line change
Expand Up @@ -174,45 +174,39 @@ 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,
start_time = url_parsed$query$t
)
}

.parse_youtube_short <- function(url_parsed) {
.parse.vembedr_youtube_short <- function(url_parsed, ...) {
list(
service = "youtube",
id = url_parsed$path,
start_time = url_parsed$query$t
)
}

.parse_vimeo <- function(url_parsed){
.parse.vembedr_vimeo <- function(url_parsed, ...){

start_time <- NULL
if (!is.null(url_parsed$fragment)){
Expand All @@ -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 %>%
Expand Down Expand Up @@ -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]]
Expand Down
10 changes: 6 additions & 4 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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)

<!-- badges: start -->
[![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)
<!-- badges: end -->

```{r, echo = FALSE}
library("htmltools")
library("vembedr")
Expand Down
70 changes: 54 additions & 16 deletions man/embed.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/iframe.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/pipe.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/use_align.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/use_bs_responsive.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f6cc80a

Please sign in to comment.