Skip to content

Commit

Permalink
Update semantic 2.3 to fomantic 2.8.3
Browse files Browse the repository at this point in the history
  • Loading branch information
galachad committed Dec 29, 2019
1 parent 275a608 commit 555e673
Show file tree
Hide file tree
Showing 46 changed files with 108,407 additions and 74 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
^readme_assets$
^docs$
^examples$
^index.html
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/inst/www/shared/semantic/semantic.js -merge -diff
/inst/www/shared/semantic/semantic.css -merge -diff
*.min.js -merge -diff
*.min.css -merge -diff
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ Suggests:
testthat,
lintr,
covr
RoxygenNote: 7.0.0
RoxygenNote: 7.0.2.9000
83 changes: 38 additions & 45 deletions R/semanticPage.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,38 @@ SUPPORTED_THEMES <- c("cerulean", "darkly", "paper", "simplex", # nolint
#'
#' @return CDN path of semantic dependencies
get_cdn_path <- function() {
getOption("shiny.custom.semantic.cdn", default = "https://d335w9rbwpvuxm.cloudfront.net")
getOption("shiny.custom.semantic.cdn", default = "https://d335w9rbwpvuxm.cloudfront.net/2.8.3")
}

#' Add dashboard dependencies to html
#'
#' Internal function that adds dashboard dependencies to html.
#'
#' @param theme define theme
#'
#' @return Content with appended dependencies.
get_dependencies <- function() {
if (getOption("shiny.minified", TRUE)) {
javascript_file <- "semantic.min.js"
css_files <- c("semantic.min.css")
} else {
javascript_file <- "semantic.js"
css_files <- c("semantic.css")
}
get_dependencies <- function(theme = NULL) {
minfield <- ifelse(getOption("shiny.minified", TRUE), "min", "")
javascript_file <- paste("semantic", minfield, "js", sep = ".")
css_files <- c(check_semantic_theme(theme, full_url = FALSE))

dep_src <- NULL
if (!is.null(getOption("shiny.custom.semantic", NULL))) {
dep_src <- c(file = getOption("shiny.custom.semantic"))
} else {
} else if (isTRUE(getOption("shiny.semantic.local", FALSE))) {
if(!is.null(theme)) {
warning("It's not posible use local semantic version with themes. Using CDN")
} else {
dep_src <- c(file = system.file("www", "shared", "semantic", package = "shiny.semantic"))
}
}

if (is.null(dep_src)) {
dep_src <- c(href = get_cdn_path())
}
shiny::tagList(
htmltools::htmlDependency("semantic-ui",
"2.2.3",
"2.8.3",
dep_src,
script = javascript_file,
stylesheet = css_files
Expand All @@ -58,47 +65,40 @@ get_range_component_dependencies <- function() { # nolint

#' Get default semantic css
#'
#' @return path to default css semantic file
get_default_semantic_theme <- function() {
if (getOption("shiny.minified", TRUE)) {
path <- file.path(get_cdn_path(), "semantic.min.css", fsep = "/")
} else {
path <- file.path(get_cdn_path(), "semantic.css", fsep = "/")
}
c(path)
}

#' Get default semantic js
#' @param full_url define return output filename or full path. Default TRUE
#'
#' @return path to default js semantic file
get_default_semantic_js <- function() {
if (getOption("shiny.minified", TRUE)) {
path <- file.path(get_cdn_path(), "semantic.min.js", fsep = "/")
} else {
path <- file.path(get_cdn_path(), "semantic.js", fsep = "/")
}
path
#' @return path to default css semantic file or default filename
get_default_semantic_theme <- function(full_url = TRUE) {
minfield <- ifelse(getOption("shiny.minified", TRUE), "min", "")
css_file <- paste("semantic", minfield, "css", sep = ".")
path <- file.path(get_cdn_path(), css_file, fsep = "/")
return(c(ifelse(full_url, path, css_file)))
}

#' Semantic theme path validator
#'
#' @param theme_css it can be either NULL, character with css path, or theme name
#' @param full_url define return output filename or full path. Default TRUE
#'
#' @return path to theme
#' @return path to theme or filename
#' @export
#'
#' @examples
#' check_semantic_theme(NULL)
#' check_semantic_theme("darkly")
check_semantic_theme <- function(theme_css) {
minfield <- ifelse(getOption("shiny.minified", TRUE), ".min", "")
if (is.null(theme_css)) return(get_default_semantic_theme())
#' check_semantic_theme("darkly", full_url = FALSE)
check_semantic_theme <- function(theme_css, full_url = TRUE) {
minfield <- ifelse(getOption("shiny.minified", TRUE), "min", "")
if (is.null(theme_css)) return(get_default_semantic_theme(full_url))
if (tools::file_ext(theme_css) == "css") return(theme_css)
if (theme_css %in% SUPPORTED_THEMES) {
return(file.path(get_cdn_path(), paste0("semantic.", theme_css, minfield, ".css"), fsep = "/"))
if (full_url)
return(file.path(get_cdn_path(), paste("semantic", theme_css, minfield, "css", sep = "."), fsep = "/"))
else
return(paste("semantic", theme_css, minfield, "css", sep = "."))
} else {
warning(paste("Theme ", theme_css, "not recognized. Default used instead!"))
return(get_default_semantic_theme())
return(get_default_semantic_theme(full_url))
}
}

Expand Down Expand Up @@ -128,15 +128,8 @@ semanticPage <- function(..., title = "", theme = NULL){ # nolint
content <- shiny::tags$div(class = "wrapper", ...)
shiny::tagList(
shiny::tags$head(
get_range_component_dependencies(),
if (!is.null(getOption("shiny.custom.semantic", NULL))) {
get_dependencies()
} else {
shiny::tagList(
shiny::tags$link(rel = "stylesheet", href = check_semantic_theme(theme)),
tags$script(src = get_default_semantic_js())
)
},
get_range_component_dependencies(),
get_dependencies(theme),
shiny::tags$title(title),
shiny::tags$meta(name = "viewport", content = "width=device-width, initial-scale=1.0"),
shiny::tags$script(src = "shiny.semantic/shiny-semantic-modal.js"),
Expand Down
Loading

0 comments on commit 555e673

Please sign in to comment.