Skip to content

Commit 4487321

Browse files
author
deepayan
committed
experimental support for package logos in HTML help
git-svn-id: https://svn.r-project.org/R/trunk@88929 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 53078c4 commit 4487321

File tree

6 files changed

+59
-11
lines changed

6 files changed

+59
-11
lines changed

src/library/tools/R/Rd2HTML.R

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,34 @@ createRedirects <- function(file, Rdobj)
361361
}
362362

363363

364+
365+
### Helper function to find a suitable package logo (logo.png, logo.svg); otherwise return R logo
366+
367+
## For an installed package, we can use system.file(). This is what is
368+
## needed for dynamic help. To interpret 'package' as a source
369+
## directory, specify 'dir = TRUE'
370+
371+
372+
staticLogoPath <- function(package, relative = FALSE, Rhome = "../../..", dir = FALSE) {
373+
if (dir) {
374+
file <- file.path(package, "man", "figures", "logo.png")
375+
if (!file.exists(file)) file <- file.path(package, "man", "figures", "logo.svg")
376+
if (!file.exists(file)) file <- R.home("doc/html/Rlogo.svg")
377+
} else {
378+
file <- system.file("help", "figures", "logo.png", package = package)
379+
if (!nzchar(file)) file <- system.file("help", "figures", "logo.svg", package = package)
380+
if (!nzchar(file)) file <- R.home("doc/html/Rlogo.svg")
381+
}
382+
if (relative) {
383+
file <- if (endsWith(file, "/logo.png")) "figures/logo.png"
384+
else if (endsWith(file, "/logo.svg")) "figures/logo.svg"
385+
else file.path(Rhome, "doc/html/Rlogo.svg")
386+
}
387+
file
388+
}
389+
390+
391+
364392
## This gets used two ways:
365393

366394
## 1) With dynamic = TRUE from tools:::httpd()
@@ -1198,6 +1226,8 @@ Rd2HTML <-
11981226

11991227
of0('<nav class="topic" aria-label="Section Navigation">\n',
12001228
'<div class="dropdown-menu">\n',
1229+
if (dynamic) '<img class="toplogo" src="../logo" alt="[logo]">'
1230+
else sprintf('<img class="toplogo" src="%s" alt="[logo]">', staticLogoPath(package, relative = TRUE)),
12011231
'<h1>Contents</h1>\n',
12021232
'<ul class="menu">\n')
12031233

@@ -1294,10 +1324,11 @@ Rd2HTML <-
12941324
## Create HTML header and footer
12951325
if (standalone) {
12961326
hfcomps <- # should we be able to specify static URLs here?
1297-
HTMLcomponents(title = headtitle, logo = FALSE,
1327+
HTMLcomponents(title = "", logo = FALSE,
12981328
up = NULL,
12991329
top = NULL,
13001330
css = stylesheet,
1331+
headerTitle = headtitle,
13011332
outputEncoding = outputEncoding,
13021333
dynamic = dynamic, prism = enhancedHTML,
13031334
doTexMath = doTexMath, texmath = texmath,

src/library/tools/R/dynamicHelp.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ httpd <- function(path, query, ...)
392392
ExampleRegexp <- "^/library/([^/]*)/Example/([^/]*)$"
393393
newsRegexp <- "^/library/([^/]*)/NEWS([.](Rd|md))?$"
394394
figureRegexp <- "^/library/([^/]*)/(help|html)/figures/([^/]*)$"
395+
logoRegexp <- "^/library/([^/]*)/logo$"
395396
sessionRegexp <- "^/session/"
396397
packageIndexRegexp <- "^/library/([^/]*)$"
397398
packageLicenseFileRegexp <- "^/library/([^/]*)/(LICEN[SC]E$)"
@@ -658,7 +659,11 @@ httpd <- function(path, query, ...)
658659
fig <- sub(figureRegexp, "\\3", path)
659660
file <- system.file("help", "figures", fig, package=pkg)
660661
return( list(file=file, "content-type" = mime_type(fig)) )
661-
} else if (grepl(sessionRegexp, path)) {
662+
} else if (grepl(logoRegexp, path)) {
663+
pkg <- sub(logoRegexp, "\\1", path)
664+
file <- staticLogoPath(pkg)
665+
return( list(file=file, "content-type" = mime_type(basename(file))) )
666+
} else if (grepl(sessionRegexp, path)) {
662667
tail <- sub(sessionRegexp, "", path)
663668
file <- file.path(tempdir(), tail)
664669
return( list(file=file, "content-type" = mime_type(tail)) )

src/library/tools/R/install.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2857,7 +2857,9 @@ if(FALSE) {
28572857

28582858
html_header <- function(pkg, title, version, encoding, conn)
28592859
{
2860-
cat(paste(HTMLheader(title, Rhome="../../..",
2860+
cat(paste(HTMLheader(title,
2861+
logo = staticLogoPath(dir, relative = TRUE, Rhome = "../../..", dir = TRUE),
2862+
Rhome="../../..",
28612863
up="../../../doc/html/packages.html",
28622864
css = "R.css"),
28632865
collapse = "\n"),

src/library/tools/R/pkg2HTML.R

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
db <-
4949
if (!missing(package) && isTRUE(isPkgTarball(package)))
5050
{
51+
src.type <- "tarball"
5152
## If URL, download first
5253
if (isURL(package)) {
5354
destdir <- tempfile("dir")
@@ -71,7 +72,7 @@
7172
Rd_db(dir = pkgdir, stages = stages)
7273
}
7374
else {
74-
## FIXME: needs cleanup
75+
src.type <- if (is.null(dir)) "installed" else "source"
7576
pkgdir <- if (is.null(dir)) find.package(package, lib.loc) else dir
7677
if (is.null(dir)) Rd_db(package, , lib.loc, stages = stages)
7778
else Rd_db(, dir, lib.loc, stages = stages)
@@ -96,6 +97,7 @@
9697
list(outlines = outlines, info = attr(h, "info"))
9798
}
9899
structure(lapply(db, rd2lines, standalone = FALSE, ...),
100+
pkgdir = pkgdir, src.type = src.type,
99101
descfile = file.path(pkgdir, "DESCRIPTION"))
100102

101103
}
@@ -121,6 +123,8 @@ pkg2HTML <- function(package, dir = NULL, lib.loc = NULL,
121123
Rhtml = Rhtml, hooks = hooks,
122124
texmath = "katex", prism = prism, ...)
123125
descfile <- attr(hcontent, "descfile")
126+
src.type <- attr(hcontent, "src.type")
127+
pkgdir <- attr(hcontent, "pkgdir")
124128
descmeta <- .read_description(descfile)
125129
pkgname <- descmeta["Package"]
126130
if (is.null(out)) {
@@ -182,6 +186,9 @@ pkg2HTML <- function(package, dir = NULL, lib.loc = NULL,
182186
## pkgname))
183187
writeHTML('<nav class="package" aria-label="Topic Navigation">',
184188
'<div class="dropdown-menu">',
189+
sprintf('<img class="toplogo" src="%s" alt="[logo]">',
190+
if (src.type == "installed") staticLogoPath(pkgname, relative = FALSE)
191+
else staticLogoPath(pkgdir, relative = FALSE, dir = TRUE)),
185192
sprintf('<h1>Package {%s}</h1>', pkgname),
186193
'<h2>Contents</h2>',
187194
'<ul class="menu">',

src/library/tools/R/toHTML.R

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ function(title="R", logo=TRUE,
2424
paste0('<link rel="stylesheet" type="text/css" href="', css, '">'),
2525
'</head><body><div class="container">',
2626
paste('<h1>', title))
27-
if (logo)
27+
if (!isFALSE(logo))
2828
result <- c(result,
2929
paste0('<img class="toplogo" src="',
30-
file.path(Rhome, 'doc/html/Rlogo.svg'),
30+
if (isTRUE(logo)) file.path(Rhome, 'doc/html/Rlogo.svg')
31+
else logo,
3132
'" alt="[R logo]">'))
3233
result <- c(result, '</h1>', '<hr>')
3334
if (!is.null(up) || !is.null(top)) {
@@ -525,12 +526,13 @@ HTMLcomponents <- function(title = "R", logo = FALSE,
525526

526527
## Optional part of header (title + logo, up, top)
527528

528-
if (!nzchar(title)) {
529+
if (nzchar(title)) {
529530
addh('<h1>', title)
530-
if (logo)
531+
if (!isFALSE(logo))
531532
addh(paste0('<img class="toplogo" src="',
532-
file.path(Rhome, 'doc/html/Rlogo.svg'),
533-
'" alt="[R logo]">'))
533+
if (isTRUE(logo)) file.path(Rhome, 'doc/html/Rlogo.svg')
534+
else logo,
535+
'" alt="[logo]">'))
534536
addh('</h1>', '<hr>')
535537
}
536538
if (!is.null(up) || !is.null(top)) {

src/library/tools/man/HTMLheader.Rd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ The title to display and use in the HTML headers. Should have had any
2323
HTML escaping already done.
2424
}
2525
\item{logo}{
26-
Whether to display the \R{} logo after the title.
26+
Logical indicating whether to display the \R{} logo after the title, or
27+
a character string giving the path of the logo to be displayed.
2728
}
2829
\item{up}{
2930
Which page (if any) to link to on the \dQuote{up} button.

0 commit comments

Comments
 (0)