Skip to content

Commit f07816c

Browse files
Add documentation
1 parent 8b3da7e commit f07816c

18 files changed

+341
-24
lines changed

R/utils_render_table_non_registers.R

Lines changed: 59 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#' Renders non-register tables such as list of venues, codecheckers
2+
#'
3+
#' @param list_reg_tables The list of register tables
4+
#' @param page_type The HTML page type that needs to rendered.
5+
#' @return A list of register tables. The entries in the list are the names of the table
16
render_non_register_tables_html <- function(list_reg_tables, page_type){
27

38
output <- switch(page_type,
@@ -15,9 +20,10 @@ render_non_register_tables_html <- function(list_reg_tables, page_type){
1520
return(output)
1621
}
1722

18-
#' Renders non-register pages such as codecheckers or venues page.
23+
#' Renders non-register html pages such as codecheckers or venues page.
1924
#'
2025
#' @param list_reg_tables The list of register tables to link to in this html page
26+
#' @param page_type The HTML page type that needs to rendered.
2127
render_non_register_htmls <- function(list_reg_tables, page_type){
2228
list_tables <- render_non_register_tables_html(list_reg_tables, page_type)
2329

@@ -33,27 +39,34 @@ render_non_register_htmls <- function(list_reg_tables, page_type){
3339
output_dir <- paste0("docs/", page_type, "/")
3440
}
3541

36-
html_header <- generate_html_header(table, page_type, table_name)
37-
generate_non_reg_html(table, table_name, page_type, html_header, output_dir)
42+
html_data <- generate_html_data(table, page_type, table_name)
43+
generate_non_reg_html(table, table_name, page_type, html_data, output_dir)
3844
}
3945
}
4046

41-
generate_non_reg_html <- function(table, table_subcategory, page_type, html_header, output_dir){
47+
#' Generates non register html page.
48+
#'
49+
#' @param table The table to showcase in the html
50+
#' @param table_name The name of the table
51+
#' @param page_type The HTML page type that needs to rendered.
52+
#' @param html_data A list containing the title, subtext, extra text of the html page
53+
#' @param output_dir The directory where the html needs to be saved
54+
generate_non_reg_html <- function(table, table_name, page_type, html_data, output_dir){
4255
table <- kable(table)
4356

4457
# Creating and adjusting the markdown table
4558
md_table <- load_md_template(CONFIG$TEMPLATE_DIR[["non_reg"]][["md_template"]])
46-
md_table <- gsub("\\$title\\$", html_header[["title"]], md_table)
47-
md_table <- gsub("\\$subtitle\\$", html_header[["subtext"]], md_table)
59+
md_table <- gsub("\\$title\\$", html_data[["title"]], md_table)
60+
md_table <- gsub("\\$subtitle\\$", html_data[["subtext"]], md_table)
4861
md_table <- gsub("\\$content\\$", paste(table, collapse = "\n"), md_table)
49-
md_table <- gsub("\\$extra_text\\$", html_header[["extra_text"]], md_table)
62+
md_table <- gsub("\\$extra_text\\$", html_data[["extra_text"]], md_table)
5063

5164
# Saving the table to a temp md file
5265
temp_md_path <- paste0(output_dir, "temp.md")
5366
writeLines(md_table, temp_md_path)
5467

5568
# Creating the correct html yaml and index files
56-
create_index_section_files(output_dir, page_type, table_subcategory, is_reg_table = FALSE)
69+
create_index_section_files(output_dir, page_type, table_name, is_reg_table = FALSE)
5770
generate_html_document_yml(output_dir)
5871
yaml_path <- normalizePath(file.path(getwd(), paste0(output_dir, "html_document.yml")))
5972

@@ -80,6 +93,7 @@ generate_non_reg_html <- function(table, table_subcategory, page_type, html_head
8093
#' Renders JSON file of non register tables such as list of venues, list of codecheckers
8194
#'
8295
#' @param list_reg_tables The list of register tables needed for the information.
96+
#' @param page_type The HTML page type that needs to rendered.
8397
render_non_register_jsons <- function(list_reg_tables, page_type){
8498
if (page_type == "codecheckers"){
8599
list_tables <- list("codecheckers" = render_table_codecheckers_json(list_reg_tables))
@@ -106,6 +120,11 @@ render_non_register_jsons <- function(list_reg_tables, page_type){
106120
}
107121
}
108122

123+
#' Generates the titles of the HTML pages for non registers
124+
#'
125+
#' @param page_type The HTML page type that needs to rendered
126+
#' @param table_name The name of the table
127+
#' @return The title to put on the html page
109128
generate_html_title_non_registers <- function(page_type, table_name){
110129
title_base <- "CODECHECK List of"
111130

@@ -128,6 +147,13 @@ generate_html_title_non_registers <- function(page_type, table_name){
128147
return(title)
129148
}
130149

150+
#' Generates the extra text of the HTML pages for non registers.
151+
#' This extra text is to be placed under the table.
152+
#' There is only extra text for the codecheckers HTML page to explain
153+
#' the reason for discrepancy between total_codechecks != SUM(no.of codechecks)
154+
#'
155+
#' @param page_type The HTML page type that needs to rendered
156+
#' @return The extra text to place under the table
131157
generate_html_extra_text_non_register <- function(page_type){
132158
extra_text <- ""
133159

@@ -141,7 +167,13 @@ generate_html_extra_text_non_register <- function(page_type){
141167
return(extra_text)
142168
}
143169

144-
170+
#' Generates the subtext of the HTML pages for non registers with a summary of
171+
#' the number of codechecks and number of codechecks/ venues etc.
172+
#'
173+
#' @param table The table to showcase in the html
174+
#' @param page_type The HTML page type that needs to rendered
175+
#' @param table_name The name of the table
176+
#' @return The subtext to put under the html title
145177
generate_html_subtext_non_register <- function(table, page_type, table_name){
146178

147179
# Setting the codecheck word to be plural or singular
@@ -183,22 +215,34 @@ generate_html_subtext_non_register <- function(table, page_type, table_name){
183215
return(subtext)
184216
}
185217

186-
generate_html_header <- function(table, page_type, table_name){
218+
#' Generates a list of data for the html. The list contains the html
219+
#' title, subtext and extra text.
220+
#'
221+
#' @param table The table to showcase in the html
222+
#' @param page_type The HTML page type that needs to rendered
223+
#' @param table_name The name of the table
224+
#' @return A list of the html data such as title, subtext etc
225+
generate_html_data <- function(table, page_type, table_name){
187226

188-
html_header <- list(
227+
html_data <- list(
189228
"title" = generate_html_title_non_registers(page_type, table_name),
190229
"subtext" = generate_html_subtext_non_register(table, page_type, table_name),
191230
"extra_text" = generate_html_extra_text_non_register(page_type)
192231
)
193232

194-
return(html_header)
233+
return(html_data)
195234
}
196235

197-
generate_html_postfix_hrefs_non_reg <- function(filter, register_table_name){
236+
#' Generates postfix hrefs for the venues/ codecheckers list pages
237+
#'
238+
#' @param filter The filter being used such as "venues" or "codecheckers"
239+
#' @param table_name The name of the table
240+
#' @return A list of the hrefs.
241+
generate_html_postfix_hrefs_non_reg <- function(filter, table_name){
198242

199243
# For register tables that arent of subcategories of a filter type, the
200244
# json url link is register/filter/index.json
201-
if (register_table_name %in% list("all_venues", "codecheckers")){
245+
if (table_name %in% list("all_venues", "codecheckers")){
202246
hrefs <- list(
203247
json_href = paste0("https://codecheck.org.uk/register/", filter, "/index.json")
204248
)
@@ -208,7 +252,7 @@ generate_html_postfix_hrefs_non_reg <- function(filter, register_table_name){
208252
# filter/register_table_name/index.json where register_table_name is the subcategory name
209253
else{
210254
hrefs <- list(
211-
json_href = paste0("https://codecheck.org.uk/register/", filter, "/", register_table_name,"/index.json")
255+
json_href = paste0("https://codecheck.org.uk/register/", filter, "/", table_name,"/index.json")
212256
)
213257
}
214258

R/utils_render_table_venues.R

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#' Renders table for all venues and venue subcategories in JSON format.
2+
#'
3+
#' @param list_venue_reg_tables The list of venue register tables. The indices are the venue names.
4+
#' @return Returns list of the json tables with the names of the list being the table names.
15
render_tables_venues_json <- function(list_venue_reg_tables){
26
all_venues_table <- render_table_all_venues_json(list_venue_reg_tables)
37
list_venues_subcat_tables <- render_table_venues_subcat(all_venues_table)
@@ -8,9 +12,10 @@ render_tables_venues_json <- function(list_venue_reg_tables){
812
}
913

1014

11-
#' Renders venues table in JSON format.
15+
#' Renders table for all venues in JSON format.
1216
#'
1317
#' @param list_venue_reg_tables The list of venue register tables. The indices are the venue names.
18+
#' @return Returns a JSON table for the all venues
1419
render_table_all_venues_json <- function(list_venue_reg_tables){
1520
col_names <- CONFIG$NON_REG_TABLE_COL_NAMES[["venues_table"]]
1621
list_venue_names <- names(list_venue_reg_tables)
@@ -57,6 +62,10 @@ render_table_all_venues_json <- function(list_venue_reg_tables){
5762
return(table_venues)
5863
}
5964

65+
#' Renders table for all venues and venue subcategories for HTML.
66+
#'
67+
#' @param list_venue_reg_tables The list of venue register tables. The indices are the venue names.
68+
#' @return Returns list of the html tables with the names of the list being the table names.
6069
render_tables_venues_html <- function(list_venue_reg_tables){
6170
all_venues_table <- render_table_all_venues_html(list_venue_reg_tables)
6271
list_venues_subcat_tables <- render_table_venues_subcat(all_venues_table)
@@ -66,11 +75,12 @@ render_tables_venues_html <- function(list_venue_reg_tables){
6675
return(list_tables)
6776
}
6877

69-
#' Renders venues table in HTML format.
78+
#' Renders table for all venues in HTML format.
7079
#' Each venue name links to the register table for that specific
7180
#' venue. The ORCID IDs link to their ORCID pages.
7281
#'
7382
#' @param list_venue_reg_tables The list of venue register tables. The indices are the ORCID IDs.
83+
#' @return Returns the html table of all the venues.
7484
render_table_all_venues_html <- function(list_venue_reg_tables){
7585
col_names <- CONFIG$NON_REG_TABLE_COL_NAMES[["venues_table"]]
7686

@@ -130,9 +140,14 @@ render_table_all_venues_html <- function(list_venue_reg_tables){
130140
return(table_venues)
131141
}
132142

133-
# This function can be used for both the html and json table since it works on the
134-
# table for all venues. If the all_venues table is of html format then this creates
135-
# a html table and if it is of json format, this creates a json table.
143+
#' Renders table for venue subcategories
144+
#' This function can be used for both the html and json table since it works on the
145+
#' table for all venues. If the all_venues table is of html format then this creates
146+
#' a html table and if it is of json format, this creates a json table.
147+
#'
148+
#' @param venues_table The table of all venues
149+
#' @return Returns a list of the html tables of venue subcategories.
150+
#' The names in the list are the names of the subcategories
136151
render_table_venues_subcat <- function(venues_table){
137152
CONFIG$NO_CODECHECKS_VENUE_SUBCAT <- c()
138153
list_tables <- c()

man/create_index_postfix_html.Rd

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/create_index_section_files.Rd

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/generate_html_data.Rd

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/generate_html_extra_text_non_register.Rd

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/generate_html_postfix_hrefs_non_reg.Rd

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/generate_html_subtext_non_register.Rd

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/generate_html_title_non_registers.Rd

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/generate_non_reg_html.Rd

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)