Skip to content

Commit

Permalink
CSS styles used in termalike, proposal, and keyword/concept help are …
Browse files Browse the repository at this point in the history
…now stored in inst/doc and invoked via the <link> tag, fixing an HTML tidy warning.
  • Loading branch information
krivit committed Nov 5, 2022
1 parent fdafb4b commit 7227a4b
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 9 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Meta
doc
/doc
# History files
.Rhistory
.Rapp.history
Expand Down Expand Up @@ -80,4 +80,3 @@ dkms.conf
*~
*.bak
.Rproj.user
inst/doc
12 changes: 12 additions & 0 deletions R/ergm-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ NULL
#' also available via `vignette('ergm-term-crossRef')` and terms
#' can also be searched via [`search.ergmTerms`].
#'
#' \ergmCSS
#'
#' ## Term index (plain)
#' \if{latex}{\Sexpr[results=rd,stage=render]{ergm:::.formatIndexLatex(ergm:::.buildTermsDataframe("ergmTerm", keywords = ~!"operator"%in%.))}}
#' \if{text}{\Sexpr[results=rd,stage=render]{ergm:::.formatIndexText(ergm:::.buildTermsDataframe("ergmTerm", keywords = ~!"operator"%in%.))}}
Expand Down Expand Up @@ -469,6 +471,8 @@ NULL
#'
#' @section Constraints visible to the package:
#'
#' \ergmCSS
#'
#' \if{latex}{\Sexpr[results=rd,stage=render]{ergm:::.formatIndexLatex(ergm:::.buildTermsDataframe("ergmConstraint"))}}
#' \if{text}{\Sexpr[results=rd,stage=render]{ergm:::.formatIndexText(ergm:::.buildTermsDataframe("ergmConstraint"))}}
#' \if{html}{\Sexpr[results=rd,stage=render]{ergm:::.formatIndexHtml(ergm:::.buildTermsDataframe("ergmConstraint"))}}
Expand Down Expand Up @@ -556,6 +560,8 @@ NULL
#'
#' The following hints are known to \CRANpkg{ergm} at this time:
#'
#' \ergmCSS
#'
#' \if{latex}{\Sexpr[results=rd,stage=render]{ergm:::.formatIndexLatex(ergm:::.buildTermsDataframe("ergmHint"))}}
#' \if{text}{\Sexpr[results=rd,stage=render]{ergm:::.formatIndexText(ergm:::.buildTermsDataframe("ergmHint"))}}
#' \if{html}{\Sexpr[results=rd,stage=render]{ergm:::.formatIndexHtml(ergm:::.buildTermsDataframe("ergmHint"))}}
Expand Down Expand Up @@ -606,6 +612,9 @@ NULL
#' typically as the `reference` argument.
#'
#' @section Reference measures visible to the package:
#'
#' \ergmCSS
#'
#' \if{latex}{\Sexpr[results=rd,stage=render]{ergm:::.formatIndexLatex(ergm:::.buildTermsDataframe("ergmReference"))}}
#' \if{text}{\Sexpr[results=rd,stage=render]{ergm:::.formatIndexText(ergm:::.buildTermsDataframe("ergmReference"))}}
#' \if{html}{\Sexpr[results=rd,stage=render]{ergm:::.formatIndexHtml(ergm:::.buildTermsDataframe("ergmReference"))}}
Expand Down Expand Up @@ -650,6 +659,9 @@ NULL
#' the algorithm, and in other cases to constrain the sample space. Proposals can also be searched via [`search.ergmProposals`], and help for an individual proposal can be obtained with `ergmProposal?<proposal>` or `help("<proposal>-ergmProposal")`.
#'
#' @section Implemented proposals for ergm models:
#'
#' \ergmCSS
#'
#' \if{html}{\Sexpr[results=rd,stage=render]{ergm:::.formatProposalsHtml(ergm:::.buildProposalsList(), keepProposal=TRUE)}}
#' \if{text}{\Sexpr[results=rd,stage=render]{ergm:::.formatProposalsText(ergm:::.buildProposalsList(), keepProposal=TRUE)}}
#' \if{latex}{\Sexpr[results=rd,stage=render]{ergm:::.formatProposalsLatex(ergm:::.buildProposalsList(), keepProposal=TRUE)}}
Expand Down
8 changes: 3 additions & 5 deletions R/ergm-terms-index.R
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,7 @@ PROPOSAL_NOT_IN_TABLE <- "This proposal is not referenced in the lookup table."
df <- df[,colnames(df)!="Proposal"]
}

css <- '<style>th,td {padding:3px 10px}</style>'
sprintf("\\out{%s%s}", css, knitr::kable(df, 'html', escape=FALSE, row.names=FALSE))
sprintf("\\out{%s}", knitr::kable(df, 'html', escape=FALSE, row.names=FALSE, table.attr='class="proptable"'))
}

.formatProposalsLatex <- function(df, keepProposal=FALSE) {
Expand Down Expand Up @@ -524,8 +523,7 @@ PROPOSAL_NOT_IN_TABLE <- "This proposal is not referenced in the lookup table."
sprintf('<div id="%s">%s</div>', df$Link, .)
df$Link <- NULL

css <- '<style>.striped th,.striped td {padding:3px 10px} .striped tbody tr:nth-child(odd) {background: #eee} .striped .code {font-family: monospace} .matrix td {align: center} .matrix th,.matrix td {padding-right:5px; width: 75px}</style>'
sprintf('\\out{%s%s}', css, knitr::kable(df, 'html', escape=FALSE, row.names=FALSE, table.attr='class="striped"'))
sprintf('\\out{%s}', knitr::kable(df, 'html', escape=FALSE, row.names=FALSE, table.attr='class="termtable"'))
}

.formatMatrixHtml <- function(df, wrapRdTags=TRUE) {
Expand All @@ -537,7 +535,7 @@ PROPOSAL_NOT_IN_TABLE <- "This proposal is not referenced in the lookup table."
df[[c]] <- ifelse(df[[c]], '&#10004;', '')
}

out <- knitr::kable(df, 'html', escape=FALSE, row.names=FALSE, table.attr='class="matrix"')
out <- knitr::kable(df, 'html', escape=FALSE, row.names=FALSE, table.attr='class="termmatrix"')
if(wrapRdTags) {
out <- sprintf('\\out{%s}', out)
}
Expand Down
6 changes: 4 additions & 2 deletions R/ergm_keyword.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ ergm_keyword <- local({
}

.formatKeywordsHtml <- function(df) {
css <- '<style>.striped th,.striped td {padding:3px 10px} .striped tbody tr:nth-child(odd) {background: #eee}</style>'
sprintf('\\out{%s%s}', css, knitr::kable(df, 'html', escape=FALSE, table.attr='class="striped"'))
sprintf('\\out{%s}', knitr::kable(df, 'html', escape=FALSE, table.attr='class="termtable"'))
}

#' Keywords defined for Exponential-Family Random Graph Models
Expand All @@ -109,6 +108,9 @@ ergm_keyword <- local({
#' @description This collects all defined keywords defined for the ERGM and derived packages
#'
#' @section Possible keywords defined by the ERGM and derived packages:
#'
#' \ergmCSS
#'
#' \if{latex}{\Sexpr[results=rd,stage=render]{ergm:::.formatKeywordsLatex(ergm::ergm_keyword())}}
#' \if{text}{\Sexpr[results=rd,stage=render]{ergm:::.formatKeywordsText(ergm::ergm_keyword())}}
#' \if{html}{\Sexpr[results=rd,stage=render]{ergm:::.formatKeywordsHtml(ergm::ergm_keyword())}}
Expand Down
24 changes: 24 additions & 0 deletions inst/doc/ergm.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.proptable th, .proptable td {
padding: 3px 10px;
}

.termtable th, .termtable td {
padding: 3px 10px;
}

.termtable tbody tr:nth-child(odd), .termmatrix tbody tr:nth-child(odd) {
background: #eee;
}

.termtable .code {
font-family: monospace;
}

.termmatrix td {
align: center;
}

.termmatrix th, .termmatrix td {
padding-right:5px;
width: 75px;
}
2 changes: 2 additions & 0 deletions man/ergmConstraint.Rd

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

2 changes: 2 additions & 0 deletions man/ergmHint.Rd

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

3 changes: 3 additions & 0 deletions man/ergmKeyword.Rd

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

3 changes: 3 additions & 0 deletions man/ergmProposal.Rd

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

3 changes: 3 additions & 0 deletions man/ergmReference.Rd

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

2 changes: 2 additions & 0 deletions man/ergmTerm.Rd

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

1 change: 1 addition & 0 deletions man/macros/ergmCSS.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
\newcommand{\ergmCSS}{\if{html}{\out{<link rel="stylesheet" type="text/css" href="../doc/ergm.css">}}}

0 comments on commit 7227a4b

Please sign in to comment.