-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch_md_def.R
60 lines (54 loc) · 2 KB
/
fetch_md_def.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#'@export
#'@title Fetch Markdown Default Format from onbrand Object
#'@description Used to extract the formatting elements for a given style from
#'an onbrand object.
#'
#'@param obnd onbrand report object
#'@param style name of style in md_def for the report type in obnd to fetch (\code{"default"})
#'@param verbose Boolean variable when set to TRUE (default) messages will be
#'displayed on the terminal; Messages will be included in the returned onbrand
#'object.
#'
#'@return list with the following elements
#' \itemize{
#' \item{isgood}: Boolean variable indicating success or failure
#' \item{md_def}: List with the default format for the specified style
#' \item{msgs}: Vector of messages
#'}
#'@examples
#' obnd = read_template(
#' template = file.path(system.file(package="onbrand"), "templates", "report.docx"),
#' mapping = file.path(system.file(package="onbrand"), "templates", "report.yaml"))
#' obnd = fetch_md_def(obnd, style="default")
#' md_def = obnd[["md_def"]]
fetch_md_def = function(obnd, style = "default", verbose=TRUE){
isgood = TRUE
msgs = c()
md_def = NULL
if(obnd[[isgood]]){
# Figuring out if we have a rpptx or rdocx object:
meta_section = obnd[["rptobj"]]
if(style %in% names(obnd[["meta"]][[meta_section]][["md_def"]])){
md_def = obnd[["meta"]][[meta_section]][["md_def"]][[style]]
} else {
isgood = FALSE
msgs = c(msgs, paste0("The specified style >", style,"< was not found."))
msgs = c(msgs, paste0("The following styles are avaialble:"))
msgs = c(msgs, paste0(" ",paste(names(obnd[["meta"]][[meta_section]][["md_def"]]), collapse=", ")))
}
} else {
isgood = FALSE
msgs = c(msgs, "Bad onbrand object supplied")
}
if(!isgood){
obnd[["isgood"]] = FALSE
msgs = c(msgs, "onbrand::fetch_md_def()")
}
# Dumping the messages if verbose is turned on:
if(verbose & !is.null(msgs)){
message(paste(msgs, collapse="\n"))
}
res = list(isgood = isgood,
msgs = msgs,
md_def = md_def)
res}