#' Sets default print method for timeline
#'
#' This function sets up the default print method
#' for outputs of the timeline function
#'
#' @param x timeline object as generated by timeline function
#' @param ... other options passed to print
#' @return print timeline
#' @method print timeline
#'
#' @export
print.timeline <- function (x, ...) {
n_commits <- nrow(x)
order <- rev(seq_len(n_commits))
template <- " (%i) %s\n %s %s\n %s\n"
# (<record_id>) <message>
# <pipe> <datetime>
# <pipe>
for (i in order) {
commit <- x[i, ]
msg <- gsub("\\n+", ": ", commit$message)
sha <- substr(commit$sha, 1, 7)
datetime <- format(commit$when, format = "%Y-%m-%d %H:%M")
# don't use the pipe for the last one, and pad by the width of the number
pipe <- ifelse(i == 1, " ", "|")
pad <- nchar(commit$record_id) - 1
pipe <- paste0(pipe, rep(" ", pad))
string <- sprintf(template,
commit$record_id,
msg,
pipe,
datetime,
pipe)
cat(string)
}
repo <- attr(x, "repo")
n_total <- number_of_commits(repo, "total")
if (n_commits < n_total) {
n_future <- number_of_commits(repo, "future")
cat(sprintf(" ...plus %i future records (%i in total)\n",
n_future,
n_total))
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.