Skip to content

Commit

Permalink
Ajout fonction use_favicon_dsfr #131
Browse files Browse the repository at this point in the history
  • Loading branch information
jengelaere committed Aug 23, 2023
1 parent ae7bfd5 commit 1675dbc
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 0 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ $run_dev.*
docs
^inst/test.convert.dsfr/\.Rbuildignore$
^deliverables$
^dev/tools/$
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export(updateRadioButtons_dsfr)
export(updateRadioGroupButtons_dsfr)
export(updateSelectInput_dsfr)
export(updateTabsetPanel_dsfr)
export(use_favicon_dsfr)
export(withSpinner_dsfr)
import(htmltools)
import(shiny)
Expand All @@ -57,6 +58,7 @@ importFrom(golem,activate_js)
importFrom(golem,add_resource_path)
importFrom(golem,bundle_resources)
importFrom(golem,favicon)
importFrom(golem,use_favicon)
importFrom(golem,with_golem_options)
importFrom(htmltools,HTML)
importFrom(htmltools,htmlDependency)
Expand Down
34 changes: 34 additions & 0 deletions R/use_favicon_dsfr.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# WARNING - Generated by {fusen} from dev/tools/flat_favicon.Rmd: do not edit by hand

#' use_favicon_dsfr
#'
#' @description
#' use_favicon_dsfr() est une fonction a lancer dans la console pour enregistrer le fichier de favicon marianne dans votre projet shiny.
#'
#'
#' @param path_app chaine de texte indiquant le chemin vers votre application shiny
#' @param golem_app booleen, TRUE pour une app golem, FALSE sinon
#' @importFrom golem use_favicon
#'
#' @return NULL
#' @export
#'
#' @examples
#' \dontrun{
#' # A lancer dans la console pour rapatrier le fichier dans votre repertoire de travail
#' use_favicon_dsfr(path_app = "", golem_app = TRUE)
#' }

use_favicon_dsfr <- function(path_app = '', golem_app = TRUE) {
path_favicon_dsfr <- system.file(paste0("dsfr-v", get_dsfr_version(), "/dist/favicon/favicon.ico"), package = "shinygouv")
if(golem_app) {
golem::use_favicon(path = path_favicon_dsfr, pkg = path_app)
} else {
dest_favic = paste0(path_app, "/www")
dir.create(path = dest_favic, showWarnings = TRUE)
file.copy(from = path_favicon_dsfr, to = dest_favic, overwrite = TRUE, recursive = FALSE)
cat("La favicon Marianne est dans `", dest_favic, "`.", sep = "", fill = TRUE)
cat("Il vous reste a l'introduire dans votre corps de page UI, par exemple avec", fill = TRUE)
cat('tags$head(tags$link(rel = "shortcut icon", type = "image/x-icon", href = "favicon.ico")\n')
}
}
2 changes: 2 additions & 0 deletions dev/01_start.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
########################################

## Fill the DESCRIPTION ----
usethis::use_description()
## Add meta data about your application
##
## /!\ Note: if you want to change the name of your app during development,
Expand Down Expand Up @@ -49,6 +50,7 @@ usethis::use_git()
golem::use_recommended_tests()

## Favicon ----
shingouv::use_favicon_dsfr()
# If you want to change the favicon (default is golem's one)
golem::use_favicon() # path = "path/to/ico". Can be an online file.
# golem::remove_favicon() # Uncomment to remove the default favicon
Expand Down
13 changes: 13 additions & 0 deletions dev/config_fusen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ flat_convert_to_dsfr.Rmd:
check: false
document: true
overwrite: ask
flat_favicon.Rmd:
path: dev/tools/flat_favicon.Rmd
state: active
R: R/use_favicon_dsfr.R
tests: tests/testthat/test-use_favicon_dsfr.R
vignettes: []
inflate:
flat_file: dev/tools/flat_favicon.Rmd
vignette_name: .na
open_vignette: true
check: false
document: true
overwrite: ask
flat_fluidpage.Rmd:
path: dev/flat_composants/flat_fluidpage.Rmd
state: active
Expand Down
72 changes: 72 additions & 0 deletions dev/tools/flat_favicon.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
title: "favicon"
output: html_document
editor_options:
chunk_output_type: console
---

```{r development, include=FALSE}
library(testthat)
```

```{r development-load}
# Load already included functions if relevant
pkgload::load_all(export_all = FALSE)
```

# flat_favicon_rmd

```{r function-flat_favicon_rmd}
#' use_favicon_dsfr
#'
#' @description
#' use_favicon_dsfr() est une fonction a lancer dans la console pour enregistrer le fichier de favicon marianne dans votre projet shiny.
#'
#'
#' @param path_app chaine de texte indiquant le chemin vers votre application shiny
#' @param golem_app booleen, TRUE pour une app golem, FALSE sinon
#' @importFrom golem use_favicon
#'
#' @return NULL
#' @export
#'
#' @examples
#' \dontrun{
#' # A lancer dans la console pour rapatrier le fichier dans votre repertoire de travail
#' use_favicon_dsfr(path_app = "", golem_app = TRUE)
#' }
use_favicon_dsfr <- function(path_app = '', golem_app = TRUE) {
path_favicon_dsfr <- system.file(paste0("dsfr-v", get_dsfr_version(), "/dist/favicon/favicon.ico"), package = "shinygouv")
if(golem_app) {
golem::use_favicon(path = path_favicon_dsfr, pkg = path_app)
} else {
dest_favic = paste0(path_app, "/www")
dir.create(path = dest_favic, showWarnings = TRUE)
file.copy(from = path_favicon_dsfr, to = dest_favic, overwrite = TRUE, recursive = FALSE)
cat("La favicon Marianne est dans `", dest_favic, "`.", sep = "", fill = TRUE)
cat("Il vous reste a l'introduire dans votre corps de page UI, par exemple avec", fill = TRUE)
cat('tags$head(tags$link(rel = "shortcut icon", type = "image/x-icon", href = "favicon.ico")\n')
}
}
```


```{r tests-flat_favicon_rmd}
test_that("use_favicon_dsfr works", {
# version shiny basique
path_shiny_base <- paste0(app, "/www/favicon.ico")
use_favicon_dsfr(path_app = app, golem_app = FALSE)
expect_true(file.exists(path_shiny_base))
})
```


```{r development-inflate, eval=FALSE}
# Run but keep eval=FALSE to avoid infinite loop
# Execute in the console directly
fusen::inflate(flat_file = "dev/tools/flat_favicon.Rmd", vignette_name = NA, check = FALSE)
```

22 changes: 22 additions & 0 deletions man/use_favicon_dsfr.Rd

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

10 changes: 10 additions & 0 deletions tests/testthat/test-use_favicon_dsfr.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# WARNING - Generated by {fusen} from dev/tools/flat_favicon.Rmd: do not edit by hand

test_that("use_favicon_dsfr works", {

# version shiny basique
path_shiny_base <- paste0(app, "/www/favicon.ico")
use_favicon_dsfr(path_app = app, golem_app = FALSE)
expect_true(file.exists(path_shiny_base))

})

0 comments on commit 1675dbc

Please sign in to comment.