1
+ render_non_register_tables_html <- function (list_reg_tables , page_type ){
2
+
3
+ output <- switch (page_type ,
4
+ " codecheckers" = render_table_codecheckers_html(list_reg_tables ),
5
+ " venues" = render_tables_venues_html(list_reg_tables ),
6
+ stop(" Unsupported non-register table page type" )
7
+ )
8
+
9
+ # Ensuring output is a list, wrapping it if necessary
10
+ # This is needed when the render function returns a single table which is the
11
+ # case when there are not subcategory tables such as the case for codecheckers
12
+ if (is.data.frame(output )){
13
+ output <- list (page_type = output )
14
+ }
15
+ return (output )
16
+ }
17
+
1
18
# ' Renders non-register pages such as codecheckers or venues page.
2
19
# '
3
20
# ' @param list_reg_tables The list of register tables to link to in this html page
4
21
render_non_register_htmls <- function (list_reg_tables , page_type ){
5
- output_dir <- paste0(" docs/" , page_type , " /" )
6
- extra_text <- " "
22
+ list_tables <- render_non_register_tables_html(list_reg_tables , page_type )
7
23
8
- if (page_type == " codecheckers" ){
9
- table <- render_table_codecheckers_html(list_reg_tables )
10
- # Counting number of codecheckers based of number of codechecker reg tables
11
- # The table is a kable table and hence we cannot count rows
12
- no_codecheckers <- length(list_reg_tables )
13
- # Using number of codechecks from CONFIG instead of "no. of codechecks" column to avoid double count
14
- subtext <- paste(" In total," , no_codecheckers , " codecheckers contributed" , CONFIG $ NO_CODECHECKS , " codechecks*" )
15
-
16
- # Extra text to explain why total_codechecks != SUM(no.of codechecks)
17
- extra_text <- " <i>\\ *Note that the total codechecks is less than the collective sum of
18
- individual codecheckers' number of codechecks.
19
- This is because some codechecks involved more than one codechecker.</i>"
20
- }
24
+ for (table_name in names(list_tables )){
25
+ table <- list_tables [[table_name ]]
21
26
22
- else if (page_type == " venues" ) {
23
- table <- render_table_venues_html(list_reg_tables )
27
+ # Case where we are dealing with venue subcategories
28
+ if (page_type == " venues" & table_name != " all_venues" ){
29
+ output_dir <- paste0(" docs/" , page_type , " /" , table_name , " /" )
30
+ }
31
+
32
+ else {
33
+ output_dir <- paste0(" docs/" , page_type , " /" )
34
+ }
24
35
25
- no_venues <- length( list_reg_tables )
26
- subtext <- paste( " In total, " , CONFIG $ NO_CODECHECKS , " codechecks were completed for " , no_venues , " venues " )
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 )
27
38
}
39
+ }
28
40
29
- # Creating and adjusting the markdown table
41
+ generate_non_reg_html <- function ( table , table_subcategory , page_type , html_header , output_dir ){
30
42
table <- kable(table )
43
+
44
+ # Creating and adjusting the markdown table
31
45
md_table <- load_md_template(CONFIG $ TEMPLATE_DIR [[" non_reg" ]][[" md_template" ]])
32
- title <- paste0(" CODECHECK List of " , page_type )
33
- md_table <- gsub(" \\ $title\\ $" , title , md_table )
34
- md_table <- gsub(" \\ $subtitle\\ $" , subtext , md_table )
46
+ md_table <- gsub(" \\ $title\\ $" , html_header [[" title" ]], md_table )
47
+ md_table <- gsub(" \\ $subtitle\\ $" , html_header [[" subtext" ]], md_table )
35
48
md_table <- gsub(" \\ $content\\ $" , paste(table , collapse = " \n " ), md_table )
36
- md_table <- gsub(" \\ $extra_text\\ $" , extra_text , md_table )
49
+ md_table <- gsub(" \\ $extra_text\\ $" , html_header [[ " extra_text" ]] , md_table )
37
50
38
51
# Saving the table to a temp md file
39
52
temp_md_path <- paste0(output_dir , " temp.md" )
40
53
writeLines(md_table , temp_md_path )
41
54
42
55
# Creating the correct html yaml and index files
43
- create_index_section_files(output_dir , page_type )
56
+ create_index_section_files(output_dir , page_type , table_subcategory , is_reg_table = FALSE )
44
57
generate_html_document_yml(output_dir )
45
58
yaml_path <- normalizePath(file.path(getwd(), paste0(output_dir , " html_document.yml" )))
46
59
@@ -68,19 +81,115 @@ render_non_register_htmls <- function(list_reg_tables, page_type){
68
81
# '
69
82
# ' @param list_reg_tables The list of register tables needed for the information.
70
83
render_non_register_jsons <- function (list_reg_tables , page_type ){
71
- output_dir <- paste0(" docs/" , page_type , " /" )
84
+ if (page_type == " codecheckers" ){
85
+ list_tables <- list (" codecheckers" = render_table_codecheckers_json(list_reg_tables ))
86
+ }
87
+
88
+ else if (page_type == " venues" ) {
89
+ list_tables <- render_tables_venues_json(list_reg_tables )
90
+ }
91
+
92
+ for (table_name in names(list_tables )){
93
+ table <- list_tables [[table_name ]]
94
+ output_dir <- paste0(" docs/" , page_type , " /" )
95
+
96
+ # Case where we are dealing with venue subcategories
97
+ if (page_type == " venues" & table_name != " all_venues" ){
98
+ output_dir <- paste0(" docs/" , page_type , " /" , table_name , " /" )
99
+ }
100
+
101
+ jsonlite :: write_json(
102
+ table ,
103
+ path = paste0(output_dir , " index.json" ),
104
+ pretty = TRUE
105
+ )
106
+ }
107
+ }
72
108
109
+ generate_html_title_non_registers <- function (page_type , table_name ){
110
+ title_base <- " CODECHECK List of"
111
+
112
+ # Adjusting title for venues subcategory
113
+ if (page_type == " venues" & table_name != " all_venues" ){
114
+ # Replacing the word with plural
115
+ plural_subcategory <- switch (table_name ,
116
+ " conference" = " conferences" ,
117
+ " journal" = " journals" ,
118
+ " community" = " communities"
119
+ )
120
+ title <- paste(title_base , plural_subcategory )
121
+ }
122
+
123
+ else {
124
+ # The base title is "CODECHECK List of venues/ codecheckers"
125
+ title <- paste(title_base , page_type )
126
+ }
127
+
128
+ return (title )
129
+ }
130
+
131
+ generate_html_extra_text_non_register <- function (page_type ){
132
+ extra_text <- " "
133
+
134
+ # Extra text to explain why total_codechecks != SUM(no.of codechecks) in the codechecker table
73
135
if (page_type == " codecheckers" ){
74
- table <- render_table_codecheckers_json(list_reg_tables )
136
+ extra_text <- " <i>\\ *Note that the total codechecks is less than the collective sum of
137
+ individual codecheckers' number of codechecks.
138
+ This is because some codechecks involved more than one codechecker.</i>"
139
+ }
140
+
141
+ return (extra_text )
142
+ }
143
+
144
+
145
+ generate_html_subtext_non_register <- function (table , page_type , table_name ){
146
+
147
+ # Setting the codecheck word to be plural or singular
148
+ total_codechecks <- CONFIG $ NO_CODECHECKS
149
+ codecheck_word <- if (total_codechecks == 1 ) " codecheck" else " codechecks"
150
+ extra_text <- " "
151
+
152
+ if (page_type == " codecheckers" ){
153
+ no_codecheckers <- nrow(table )
154
+ # Adding asterik to refer to the extra text at the bottom of the page
155
+ codecheck_word <- paste0(codecheck_word , " *" )
156
+ subtext <- paste(" In total," , no_codecheckers , " codecheckers contributed" , total_codechecks , codecheck_word )
75
157
}
76
158
77
159
else if (page_type == " venues" ){
78
- table <- render_table_venues_json(list_reg_tables )
160
+ # For the general venues list
161
+ if (table_name == " all_venues" ){
162
+ no_venues <- nrow(table )
163
+ subtext <- paste(" In total," , total_codechecks , codecheck_word , " were completed for" , no_venues , " venues" )
164
+ }
165
+
166
+ else {
167
+ no_venues_subcat <- nrow(table )
168
+ venue_name_subtext <- table_name
169
+ total_codechecks <- CONFIG $ NO_CODECHECKS_VENUE_SUBCAT [[venue_name_subtext ]]
170
+ codecheck_word <- if (total_codechecks == 1 ) " codecheck" else " codechecks"
171
+
172
+ if (no_venues_subcat > 1 ){
173
+ venue_name_subtext <- switch (table_name ,
174
+ " conference" = " conferences" ,
175
+ " journal" = " journals" ,
176
+ " community" = " communities"
177
+ )
178
+ }
179
+ subtext <- paste(" In total," , total_codechecks , codecheck_word , " were completed for" , no_venues_subcat , venue_name_subtext )
180
+ }
79
181
}
80
182
81
- jsonlite :: write_json(
82
- table ,
83
- path = paste0(output_dir , " index.json" ),
84
- pretty = TRUE
183
+ return (subtext )
184
+ }
185
+
186
+ generate_html_header <- function (table , page_type , table_name ){
187
+
188
+ html_header <- list (
189
+ " title" = generate_html_title_non_registers(page_type , table_name ),
190
+ " subtext" = generate_html_subtext_non_register(table , page_type , table_name ),
191
+ " extra_text" = generate_html_extra_text_non_register(page_type )
85
192
)
193
+
194
+ return (html_header )
86
195
}
0 commit comments