Skip to content

Commit

Permalink
Refactor getDependency to return *all* necessary dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
jcheng5 committed Aug 4, 2014
1 parent 69d31b6 commit 648433d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
18 changes: 1 addition & 17 deletions R/htmlwidgets.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,23 +121,7 @@ widget_dependencies.htmlwidget <- function(x){
jsfile = attr(x, "jsfile", exact = TRUE) %||% sprintf('%s.js', lib)
config = attr(x, "config", exact = TRUE) %||% sprintf('%s.yaml', lib)
package = attr(x, "package", exact = TRUE) %||% lib
widgetDep <- getDependency(config, package)

# TODO: The binding JS file should really be in its own directory to prevent
# htmltools from picking up the entire package
bindingDep <- htmlDependency(paste0(lib, "-binding"), packageVersion(package),
system.file(package = package),
script = jsfile
)

c(
list(htmlDependency("htmlwidgets", packageVersion("htmlwidgets"),
src = system.file("www", package="htmlwidgets"),
script = "htmlwidgets.js"
)),
widgetDep,
list(bindingDep)
)
getDependency(package, lib, config, jsfile)
}

# Generates a <script type="application/json"> tag with the JSON-encoded data,
Expand Down
22 changes: 19 additions & 3 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
#' @export
getDependency <- function(file, package){
getDependency <- function(package, lib, config, jsfile){
config = yaml::yaml.load_file(
system.file(file, package = package)
system.file(config, package = package)
)
lapply(config$dependencies, function(l){
widgetDep <- lapply(config$dependencies, function(l){
l$src = system.file(l$src, package = package)
do.call(htmlDependency, l)
})

# TODO: The binding JS file should really be in its own directory to prevent
# htmltools from picking up the entire package
bindingDep <- htmlDependency(paste0(lib, "-binding"), packageVersion(package),
system.file(package = package),
script = jsfile
)

c(
list(htmlDependency("htmlwidgets", packageVersion("htmlwidgets"),
src = system.file("www", package="htmlwidgets"),
script = "htmlwidgets.js"
)),
widgetDep,
list(bindingDep)
)
}

`%||%` <- function(x, y){
Expand Down

0 comments on commit 648433d

Please sign in to comment.