Skip to content

Commit

Permalink
pdf_report(), gitbook() and pdf_report() gain a public_report option
Browse files Browse the repository at this point in the history
  • Loading branch information
ThierryO committed Nov 23, 2023
1 parent d453a1d commit e7ee320
Show file tree
Hide file tree
Showing 10 changed files with 207 additions and 137 deletions.
20 changes: 19 additions & 1 deletion R/ebook.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ epub_book <- function() {
yaml_front_matter() |>
validate_persons(reviewer = TRUE) |>
validate_rightsholder() -> fm
assert_that(
!has_name(fm, "nocolophon"), msg = "Legacy option `nocolophon` detected.
Please use the `public_report` option."
)
style <- ifelse(has_name(fm, "style"), fm$style, "INBO")
assert_that(length(style) == 1)
assert_that(style %in% c("INBO", "Vlaanderen", "Flanders"),
Expand All @@ -40,7 +44,6 @@ epub_book <- function() {
style == "Flanders" || lang == "nl",
msg = "Use style: Flanders when the language is not nl"
)
validate_doi(ifelse(has_name(fm, "doi"), fm$doi, "1.1/1"))

pandoc_args <- c(
"--csl",
Expand All @@ -50,6 +53,21 @@ epub_book <- function() {
"--lua-filter",
system.file(file.path("pandoc", "translations.lua"), package = "INBOmd")
)
validate_doi(ifelse(has_name(fm, "doi"), fm$doi, "1.1/1"))
if (has_name(fm, "public_report") && !fm$public_report) {
c(
nl = "onuitgeven rapport", en = "unpublished report",
fr = "rapport non publi\u00e9"
)[lang] |>
pandoc_variable_arg(name = "doi") |>
c(pandoc_variable_arg("nocolophon", "true")) |>
c(pandoc_args) -> pandoc_args
} else {
c(fm$doi, "!!! missing DOI !!!") |>
head(1) |>
pandoc_variable_arg(name = "doi") |>
c(pandoc_args) -> pandoc_args
}
file.path("css_styles", c("fonts", "img")) |>
system.file(package = "INBOmd") |>
list.files(full.names = TRUE) -> fonts
Expand Down
20 changes: 17 additions & 3 deletions R/gitbook.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ gitbook <- function(code_folding = c("none", "show", "hide")) {
yaml_front_matter() |>
validate_persons(reviewer = TRUE) |>
validate_rightsholder() -> fm
assert_that(
!has_name(fm, "nocolophon"), msg = "Legacy option `nocolophon` detected.
Please use the `public_report` option."
)
style <- ifelse(has_name(fm, "style"), fm$style, "INBO")
assert_that(length(style) == 1)
assert_that(
Expand Down Expand Up @@ -53,7 +57,6 @@ gitbook <- function(code_folding = c("none", "show", "hide")) {
split_by %in% c("chapter+number", "section+number"),
msg = "`split_by` must be either 'chapter+number' or `section+number`"
)
validate_doi(ifelse(has_name(fm, "doi"), fm$doi, "1.1/1"))

pandoc_args <- c(
"--csl",
Expand All @@ -63,6 +66,17 @@ gitbook <- function(code_folding = c("none", "show", "hide")) {
"--lua-filter",
system.file(file.path("pandoc", "translations.lua"), package = "INBOmd")
)
validate_doi(ifelse(has_name(fm, "doi"), fm$doi, "1.1/1"))
if (has_name(fm, "public_report") && !fm$public_report) {
c(
nl = "onuitgeven rapport", en = "unpublished report",
fr = "rapport non publi\u00e9"
)[lang] |>
pandoc_variable_arg(name = "doi") |>
c(pandoc_variable_arg("nocolophon", "true")) |>
c(pandoc_args) -> pandoc_args
}

assert_that(
getwd() |>
path("index.Rmd") |>
Expand Down Expand Up @@ -110,7 +124,7 @@ gitbook <- function(code_folding = c("none", "show", "hide")) {
template = template, extra_dependencies = list(inbomd_dep),
code_folding = code_folding
)
post <- config$post_processor # in case a post processor have been defined
old_post <- config$post_processor # in case a post processor have been defined
config$post_processor <- function(metadata, input, output, clean, verbose) {
file(output, encoding = "UTF-8") |>
readLines() -> x
Expand All @@ -119,7 +133,7 @@ gitbook <- function(code_folding = c("none", "show", "hide")) {
x <- c(head(x, i - 1), "", tail(x, -i + 1))
}
writeLines(x, output)
post(metadata, input, output, clean, verbose)
old_post(metadata, input, output, clean, verbose)
}
config$clean_supporting <- TRUE
return(config)
Expand Down
30 changes: 20 additions & 10 deletions R/pdf_report.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ pdf_report <- function(
yaml_front_matter() |>
validate_persons(reviewer = TRUE) |>
validate_rightsholder() -> fm
assert_that(
!has_name(fm, "nocolophon"), msg = "Legacy option `nocolophon` detected.
Please use the `public_report` option."
)
floatbarrier <- ifelse(has_name(fm, "floatbarrier"), fm$floatbarrier, NA)
assert_that(length(floatbarrier) == 1)
assert_that(
Expand Down Expand Up @@ -68,15 +72,6 @@ pdf_report <- function(
paste(sprintf("'%s' (%s)", names(languages), languages), collapse = ", ")
)
)
validate_doi(ifelse(has_name(fm, "doi"), fm$doi, "1.1/1"))
fm$doi <- ifelse(
has_name(fm, "nocolophon") && fm$nocolophon,
c(
nl = "onuitgeven rapport", en = "unpublished report",
fr = "rapport non publi\u00e9"
)[lang],
head(c(fm$doi, "!!! missing DOI !!!"), 1)
)

path("pandoc", "inbo_rapport.tex") |>
system.file(package = "INBOmd") -> template
Expand All @@ -97,7 +92,6 @@ pdf_report <- function(
),
pandoc_variable_arg("corresponding", fm$corresponding),
pandoc_variable_arg("shortauthor", gsub("\\&", "\\\\&", fm$shortauthor)),
pandoc_variable_arg("doi", fm$doi),
pandoc_variable_arg(
"babel", paste(languages[c(other_lang, lang)], collapse = ",")
),
Expand All @@ -109,6 +103,22 @@ pdf_report <- function(
includes_to_pandoc_args(includes)
)
args <- args[args != ""]
validate_doi(ifelse(has_name(fm, "doi"), fm$doi, "1.1/1"))
if (has_name(fm, "public_report") && !fm$public_report) {
c(
nl = "onuitgeven rapport", en = "unpublished report",
fr = "rapport non publi\u00e9"
)[lang] |>
pandoc_variable_arg(name = "doi") |>
c(pandoc_variable_arg("nocolophon", "true")) |>
c(args) -> args
} else {
c(fm$doi, "!!! missing DOI !!!") |>
head(1) |>
pandoc_variable_arg(name = "doi") |>
c(args) -> args
}


if (has_name(fm, "lof") && isTRUE(fm$lof)) {
args <- c(args, pandoc_variable_arg("lof", TRUE))
Expand Down
3 changes: 3 additions & 0 deletions inst/pandoc/translations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ local function translation(lang)
ordernr = "Opdrachtnummer",
reviewer = "Nagelezen door",
series = "Rapporten van het",
unpublished = "Onuitgegeven rapport",
vu = "Verantwoordelijke uitgever",
year = "Gepubliceerd in"
}
Expand All @@ -43,6 +44,7 @@ local function translation(lang)
ordernr = "Numéro de commande",
reviewer = "Examiné par",
series = "Rapports de",
unpublished = "Rapport non publié",
vu = "Éditeur responsable",
year = "Publié en"
}
Expand All @@ -66,6 +68,7 @@ local function translation(lang)
ordernr = "Order number",
reviewer = "Reviewed by",
series = "Reports of the",
unpublished = "Unpublished report",
vu = "Responsible publisher",
year = "Published during"
}
Expand Down
4 changes: 4 additions & 0 deletions inst/template/report.epub3
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ $if(titlepage)$
$if(ordernr)$
<h4 class ="ordernr">$ordernr$</h4>
$endif$
$if(nocolophon)$
<h4>$translation.unpublished$</h4>
$else$
<h1>$translation.colophon$</h1>
$if(reviewer)$
<p><b>Reviewers:</b><br>
Expand Down Expand Up @@ -160,6 +163,7 @@ $if(titlepage)$

<p><a rel="license" href="http://creativecommons.org/licenses/by/4.0/"><img alt="Creative Commons-Licentie" style="border-width:0" src="../fonts/cc-by.svg" /></a><br />$translation.license_pre$ <a rel="license" href="http://creativecommons.org/licenses/by/4.0/">$translation.license$</a>.
</div>
$endif$
</section>
$else$
$if(coverpage)$
Expand Down
Loading

0 comments on commit e7ee320

Please sign in to comment.