|
| 1 | +#' Figure out where code examples start and stop |
| 2 | +#' |
| 3 | +#' Finds the start and stop indices of the lines in `text` that are |
| 4 | +#' code examples in roxygen comments. |
| 5 | +#' @param text |
| 6 | +identify_start_and_stop_of_royxgen_examples_from_text <- function(text) { |
| 7 | + starts <- identify_start_points(text) |
| 8 | + stop_candidates <- identify_stop_candidates(text) |
| 9 | + stops <- map_int(starts, match_stop_to_start, |
| 10 | + stop_candidates = stop_candidates |
| 11 | + ) |
| 12 | + NULL |
| 13 | +} |
| 14 | + |
| 15 | +identify_start_stop_of_royxgen_examples_from_paths <- function(path) { |
| 16 | + content <- enc::read_lines_enc(path) # ensure file can be read |
| 17 | + identify_start_stop_of_royxgen_examples_from_text(content) |
| 18 | + list( |
| 19 | + c(5, 9), |
| 20 | + c(18, 39) |
| 21 | + ) |
| 22 | +} |
| 23 | + |
| 24 | +match_stop_to_start <- function(start, stop_candidates) { |
| 25 | + NULL |
| 26 | +} |
| 27 | + |
| 28 | +#' TODO: |
| 29 | +#' * move to R/ui.R |
| 30 | +#' * same arguments as other stylers |
| 31 | +#' * add include_roxygen_code_examples argument to style_pkg() et al. |
| 32 | +#' * export |
| 33 | +style_roxygen_code_examples <- function(path) { |
| 34 | + map(path, style_roxygen_code_examples_one) |
| 35 | +} |
| 36 | + |
| 37 | +style_roxygen_code_examples_one <- function(path) { |
| 38 | + full_file_content <- enc::read_lines_enc(path) |
| 39 | + start_stop_sequences <- identify_start_and_stop_of_royxgen_examples_from_paths( |
| 40 | + full_file_content |
| 41 | + ) %>% |
| 42 | + start_stop_pairs_to_sequences() |
| 43 | + |
| 44 | + masked_examples <- extract_selected_lines_from_text( |
| 45 | + full_file_content, start_stop_sequences |
| 46 | + ) |
| 47 | + |
| 48 | + plain_examples <- map(start_stop_paris, remove_roxygen_mask, |
| 49 | + text = masked_examples |
| 50 | + ) |
| 51 | + styled_examples <- map(plain_examples, style_text, ...) |
| 52 | + masked_examples <- map(styled_examples, add_roxygen_mask) |
| 53 | + full_file_content <- update_selected_lines_of_text( |
| 54 | + full_file_content, masked_examples, start_stop_sequences |
| 55 | + ) |
| 56 | + enc::write_lines_enc(path, full_file_content) |
| 57 | +} |
| 58 | + |
| 59 | + |
| 60 | +remove_roxygen_mask <- function() { |
| 61 | + NULL |
| 62 | +} |
| 63 | + |
| 64 | +add_roxygen_mask <- function() { |
| 65 | + NULL |
| 66 | +} |
0 commit comments