Pull out bootstrapLib into separate function

This commit is contained in:
Winston Chang
2016-01-05 11:16:32 -06:00
parent 8e89a1f154
commit 6c5f0c5379
3 changed files with 60 additions and 21 deletions

View File

@@ -39,6 +39,7 @@ export(addResourcePath)
export(animationOptions)
export(as.shiny.appobj)
export(basicPage)
export(bootstrapLib)
export(bootstrapPage)
export(br)
export(browserViewer)

View File

@@ -33,26 +33,6 @@ bootstrapPage <- function(..., title = NULL, responsive = NULL, theme = NULL) {
shinyDeprecated("The 'responsive' argument is no longer used with Bootstrap 3.")
}
# required head tags for boostrap
importBootstrap <- function() {
list(
htmlDependency("bootstrap", "3.3.5",
c(
href = "shared/bootstrap",
file = system.file("www/shared/bootstrap", package = "shiny")
),
script = c(
"js/bootstrap.min.js",
# These shims are necessary for IE 8 compatibility
"shim/html5shiv.min.js",
"shim/respond.min.js"
),
stylesheet = if (is.null(theme)) "css/bootstrap.min.css",
meta = list(viewport = "width=device-width, initial-scale=1")
)
)
}
attachDependencies(
tagList(
if (!is.null(title)) tags$head(tags$title(title)),
@@ -63,7 +43,41 @@ bootstrapPage <- function(..., title = NULL, responsive = NULL, theme = NULL) {
# remainder of tags passed to the function
list(...)
),
importBootstrap()
bootstrapDependency()
)
}
#' Bootstrap libraries
#'
#' This function returns a set of web dependencies necessary for using Bootstrap
#' components in a web page.
#'
#' It isn't necessary to call this function if you use
#' \code{\link{bootstrapPage}} or others which use \code{bootstrapPage}, such
#' \code{\link{basicPage}}, \code{\link{fluidPage}}, \code{\link{fillPage}},
#' \code{\link{pageWithSidebar}}, and \code{\link{navbarPage}}, because they
#' already include the Bootstrap web dependencies.
#'
#' @inheritParams bootstrapPage
#' @export
bootstrapLib <- function(theme = NULL) {
attachDependencies(tagList(), bootstrapDependency(theme))
}
bootstrapDependency <- function(theme = NULL) {
htmlDependency("bootstrap", "3.3.5",
c(
href = "shared/bootstrap",
file = system.file("www/shared/bootstrap", package = "shiny")
),
script = c(
"js/bootstrap.min.js",
# These shims are necessary for IE 8 compatibility
"shim/html5shiv.min.js",
"shim/respond.min.js"
),
stylesheet = if (is.null(theme)) "css/bootstrap.min.css",
meta = list(viewport = "width=device-width, initial-scale=1")
)
}

24
man/bootstrapLib.Rd Normal file
View File

@@ -0,0 +1,24 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/bootstrap.R
\name{bootstrapLib}
\alias{bootstrapLib}
\title{Bootstrap libraries}
\usage{
bootstrapLib(theme = NULL)
}
\arguments{
\item{theme}{Alternative Bootstrap stylesheet (normally a css file within the
www directory, e.g. \code{www/bootstrap.css})}
}
\description{
This function returns a set of web dependencies necessary for using Bootstrap
components in a web page.
}
\details{
It isn't necessary to call this function if you use
\code{\link{bootstrapPage}} or others which use \code{bootstrapPage}, such
\code{\link{basicPage}}, \code{\link{fluidPage}}, \code{\link{fillPage}},
\code{\link{pageWithSidebar}}, and \code{\link{navbarPage}}, because they
already include the Bootstrap web dependencies.
}