-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(website): better display of "Usage" section (#626)
Co-authored-by: eitsupi <[email protected]>
- Loading branch information
1 parent
43ad356
commit d528cdf
Showing
7 changed files
with
100 additions
and
864 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,3 +51,5 @@ tools/libr_polars.a | |
altdoc/freeze.rds | ||
docs | ||
.venv_altdoc | ||
altdoc/mkdocs.yml | ||
altdoc/reference_home.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
### To be run after altdoc::render_docs() | ||
|
||
list_man_html = list.files("docs/man", | ||
pattern = "\\.html$", full.names = TRUE, | ||
recursive = TRUE | ||
) | ||
|
||
### Make the "Usage" section prettier (if there is one): | ||
### DataFrame_describe(...) -> <DataFrame>$describe() | ||
|
||
classes = c( | ||
"Series", "DataFrame", "LazyFrame", "GroupBy", | ||
"LazyGroupBy", "IO", "RField", "RThreadHandle", "SQLContext", "S3", | ||
"Expr" | ||
) | ||
|
||
to_modify = grep( | ||
paste0("/", paste(classes, collapse = "|")), | ||
list_man_html, | ||
value = TRUE | ||
) | ||
|
||
for (i in to_modify) { | ||
which_class = gsub("docs/man/([^_]+).*$", "\\1", i, perl = TRUE) | ||
orig = readLines(i, warn = FALSE) | ||
|
||
if (!any(grepl("<h2 id=\"usage\">Usage</h2>", orig))) { | ||
next | ||
} | ||
new = gsub( | ||
paste0("<code class='language-R'>", which_class, "_"), | ||
paste0("<code class='language-R'><", which_class, ">$"), | ||
orig | ||
) | ||
writeLines(new, i) | ||
} | ||
|
||
|
||
### Add a "Usage" section if there is none (which is the case for all Expr) | ||
|
||
# Expr_classes = c("pl", "ExprList", "ExprBin", "ExprCat", "ExprDT", "ExprMeta", | ||
# "ExprName", "ExprStr", "ExprStruct") | ||
# | ||
# to_modify2 = grep( | ||
# paste0("/", paste(Expr_classes, collapse = "|")), | ||
# list_man_html, | ||
# value = TRUE | ||
# ) | ||
# | ||
# for (i in to_modify2) { | ||
# which_class = gsub("docs/man/(.*)_.*$", "\\1", i) | ||
# orig = readLines(i, warn = FALSE) | ||
# | ||
# if (any(grepl("<h2 id=\"usage\">Usage</h2>", orig))) { | ||
# next | ||
# } | ||
# | ||
# before_usage = grep("id=\"description\">", orig) + 1 | ||
# after_usage = grep("id=\"description\">", orig) + 2 | ||
# if (length(before_usage) == 0) { | ||
# next | ||
# } | ||
# | ||
# usage = if (grep("^Expr", which_class)) { | ||
# paste0("<Expr>$", tolower(gsub("^Expr", "", which_class))) | ||
# } else if (which_class == "pl") { | ||
# "pl" | ||
# } | ||
# | ||
# usage = paste0(usage, "$") | ||
# new = c( | ||
# orig[1:before_usage], | ||
# "<h2 id=\"usage\">Usage</h2>", | ||
# paste0("<pre><code class='language-R'>", usage), | ||
# "</code></pre>", | ||
# orig[after_usage:length(orig)] | ||
# ) | ||
# writeLines(new, i) | ||
# } |
Oops, something went wrong.