Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
.Rproj.user
googleauthr-auth-key.json
client_secret_312765454551-lslmrvger7rh9o7ldq1nl384t3ubfu8t.apps.googleusercontent.com.json
.Renviron
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Imports:
dbplyr,
dplyr,
fs,
googleCloudStorageR,
rlang,
stringr,
withr
Expand Down
66 changes: 66 additions & 0 deletions R/publish.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
ojo_publish <- function(path, ..., draft = TRUE, public = FALSE, platform = "google") {
publish_to_google(path = path, bucket = "publishr", public = public)
}

publish_to_google <- function(path, bucket, public) {
if (!fs::file_exists(path)) {
cli::cli_abort("`{path}` doesn't exist")
}

file_type <- dplyr::case_when(
fs::is_file(path) ~ "file",
fs::is_dir(path) ~ "dir",
TRUE ~ NA_character_
)

if (is.na(file_type)) {
cli::cli_abort("`{path}` is not recognized as a valid file or directory")
}

file_name <- fs::path_file(path)
dir_name <- file_name |>
fs::path_ext_remove()

if (gcs_dir_exists(dir_name)) {
cli::cli_abort("A Google Cloud Storage folder with the name `{dir_name}` already exists in bucket `{bucket}`")
}

if (file_type == "file") {
res <- googleCloudStorageR::gcs_upload(
path,
bucket = bucket,
name = stringr::str_glue("{dir_name}/{file_name}")
)
} else if (file_type == "dir") {
cli::cli_abort("Not implemented") # TODO: Handle bulk upload of a directory
}

res_url <- googleCloudStorageR::gcs_download_url(
object_name = res$name,
bucket = res$bucket,
public = public # TODO: Replace with signed_url?
)

cli::cli_alert_success("{.url {res_url}}")

invisible(res)
}

gcs_object_exists <- function(object, bucket = "publishr") {
x <- googleCloudStorageR::gcs_list_objects(bucket = bucket) |>
dplyr::mutate(
name = stringr::str_remove(name, "/$") # Remove trailing slash from object names
)

object %in% x$name
}

gcs_dir_exists <- function(object, bucket = "publishr") {
x <- googleCloudStorageR::gcs_list_objects(bucket = bucket) |>
dplyr::filter(stringr::str_detect(name, "/$")) |> # Only keep directories
dplyr::mutate(
name = stringr::str_remove(name, "/$") # Remove trailing slash from object names
)

object %in% x$name
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
title: ojo-report-template
author: andrewjbe
version: 1.0.0
quarto-required: ">=1.2.0"
contributes:
formats:
html:
template-partials:
- title-block.html
embed-resources: true
theme: [yeti, custom.scss]

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* Additional formatting options: */
/*-- scss:defaults --*/

$title-color: #fdbc60 !default;
/*
#fdbc60 = OKPI yellow
#F6BE00 = OJO yellow
*/

$subtitle-color: #ffffff !default;

/* Don't edit this part unless you know what you're doing! */
/*-- scss:rules --*/
.quarto-title.column-body {
display: flex;
}

/* Logo spacing */
#title-block-header > div.quarto-title-banner.page-columns.page-full > div > div.quarto-title.column-body > img {
margin-left: 25px;
margin-right: 25px;
margin-top: auto;
margin-bottom: auto;
/*
margin-right: auto;
margin-left: 0px;
*/
}

.description {
padding-top: 10px;
}

#title-block-header > div.quarto-title-banner.page-columns.page-full > div > div.quarto-title.column-body > div > h1 {
color: $title-color;
}

#title-block-header > div.quarto-title-banner.page-columns.page-full > div > div.quarto-title.column-body > div > p {
color: $subtitle-color;
}

/* This removes the top margin only on the first page, for the title banner */
@page :first {
margin-top: 0;
}

/* This adds a little top padding to the title banner, just an aesthetic improvement */
.quarto-title-banner{
padding-top: 0.5in;
padding-bottom: 0.5in;
}

/* Adds the vertical line next to the title / subtitle and spaces it out a bit */
.quarto-title .title-subtitle-div {
padding-left: 10px;
border-left: 5px solid $title-color;
}

/* This sets the default page margins, which again, are different on the first page */
@page {
margin-top: 0.5in;
margin-bottom: 0.5in;
margin-left: 0in;
margin-right: 0in;
}

/* Replaces the left and right margins with equal padding */
.quarto-title-banner, .quarto-title-meta, .abstract, .content{
padding-left: 0.5in;
padding-right: 0.5in;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<header id="title-block-header" class="quarto-title-block default$if(quarto-template-params.banner-header-class)$ $quarto-template-params.banner-header-class$$endif$">
<div class="quarto-title-banner">

<div>

<div class="quarto-title column-body">
$if(logo)$<img src="$logo$", height = '100vh', >$endif$
<div class="quarto-title title-subtitle-div">
$if(title)$<h1 class="title">$title$</h1>$endif$
$if(subtitle)$
<p class="subtitle lead">$subtitle$</p>
$endif$
</div>
</div>

$if(description)$
<div>
<div class="description">
$description$
</div>
</div>
$endif$
$if(categories)$
$if(quarto-template-params.title-block-categories)$
<div class="quarto-categories">
$for(categories)$
<div class="quarto-category">$categories$</div>
$endfor$
</div>
$endif$
$endif$
</div>
</div>

$title-metadata.html()$

</header>
988 changes: 988 additions & 0 deletions reports/demo-publishr/demo-publishr.html

Large diffs are not rendered by default.

108 changes: 108 additions & 0 deletions reports/demo-publishr/demo-publishr.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
---
title: Open Justice Oklahoma Report Template
subtitle: A generic OJO template for HTML and PDF reports
format:
ojo-report-template-html: default
# Formatting options -----------------------------------------------------------
logo: "www/okpi-square-bw-text.png" # Other options are in the /www/ directory
number-sections: true
smooth-scroll: true
title-block-banner: "black" # The background color for the header banner
# Common values:
# - "#2f507f" is "OK Policy Blue"
title-block-banner-color: "white" # The text color for the header banner
fontcolor: "black" # Default text color for the body
linkcolor: "black" # Default link color for the body
toc: false # This should be 'false' if your end goal is a PDF
knitr:
opts_chunk:
fig.align: center # These are the default chunk options
echo: false
warning: false
# Remember that there are other formatting options in /_extensions/ojo-report-template/custom.scss
# You can also edit the header structure in /_extensions/ojo-report-template/title-block.html
# Document info ----------------------------------------------------------------
author: Analyst Name
date: last-modified
description: |
This is where you can write a brief description of the publication if needed.
If you don't need it for your current project, you can just delete this parameter.
abstract-title: "Executive Summary"
abstract: |
This is where we'd write an abstract / executive summary. You can change the title
for this section by changing the `abstract-title` parameter, and you can
delete the parameter if you don't need it.
---

```{r}

# To render to PDF after you've rendered your .html document:
# pagedown::chrome_print("./report.html", "./report.pdf", format = "pdf")

# We'll build this into the YAML header so you don't have to take this extra step
# once the {pagedown} people get around to adding quarto support.

```

## Introduction

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum pharetra turpis feugiat sem euismod interdum. Sed ultrices eget turpis ut malesuada. Donec vel nibh a arcu placerat sodales. Donec sagittis metus vitae placerat finibus. Curabitur a augue finibus nisl scelerisque molestie ac nec arcu. Vivamus lorem ligula, efficitur at scelerisque ac, bibendum a enim. Quisque non leo nibh. Sed non ante vel lacus ultricies fringilla. Maecenas ut massa tempor, ultrices lectus mollis, lobortis nisi. Donec dapibus magna nec suscipit vulputate. Sed placerat purus felis, eget egestas arcu ultricies eget.

This is a [link to some url](https://github.com/openjusticeok/ojo-report-template).

## Data

### Data source

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum pharetra turpis feugiat sem euismod interdum. Sed ultrices eget turpis ut malesuada. Donec vel nibh a arcu placerat sodales. Donec sagittis metus vitae placerat finibus. Curabitur a augue finibus nisl scelerisque molestie ac nec arcu. Vivamus lorem ligula, efficitur at scelerisque ac, bibendum a enim. Quisque non leo nibh. Sed non ante vel lacus ultricies fringilla. Maecenas ut massa tempor, ultrices lectus mollis, lobortis nisi. Donec dapibus magna nec suscipit vulputate. Sed placerat purus felis, eget egestas arcu ultricies eget. Curabitur leo ante, ultrices non elit vitae, sodales facilisis lacus. Nulla quis velit sollicitudin dolor laoreet porta. Mauris mauris orci, lacinia ac commodo non, vehicula nec metus. Integer imperdiet laoreet diam eu blandit.

### Data overview

Here's a sample plot:

```{r}

plot(rnorm(n = 1000, mean = 0, sd = 3))

```

Here's a table, too:

```{r}

# {gt} is our preferred table manager:
mtcars |>
head(5) |>
gt::gt()

# Knitr has some more basic options:
# mtcars |>
# head(8) |>
# knitr::kable()

```

<!-- This is how you insert a page break. -->
<!-- It will only appear in the PDF version; the html version will ignore it. -->
{{< pagebreak >}}

## Methods

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum pharetra turpis feugiat sem euismod interdum. Sed ultrices eget turpis ut malesuada. Donec vel nibh a arcu placerat sodales. Donec sagittis metus vitae placerat finibus. Curabitur a augue finibus nisl scelerisque molestie ac nec arcu. Vivamus lorem ligula, efficitur at scelerisque ac, bibendum a enim. Quisque non leo nibh. Sed non ante vel lacus ultricies fringilla. Maecenas ut massa tempor, ultrices lectus mollis, lobortis nisi. Donec dapibus magna nec suscipit vulputate. Sed placerat purus felis, eget egestas arcu ultricies eget. Curabitur leo ante, ultrices non elit vitae, sodales facilisis lacus. Nulla quis velit sollicitudin dolor laoreet porta. Mauris mauris orci, lacinia ac commodo non, vehicula nec metus. Integer imperdiet laoreet diam eu blandit.

- List item A
- List item B
- List item C

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum pharetra turpis feugiat sem euismod interdum. Sed ultrices eget turpis ut malesuada. Donec vel nibh a arcu placerat sodales. Donec sagittis metus vitae placerat finibus.

## Results

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum pharetra turpis feugiat sem euismod interdum. Sed ultrices eget turpis ut malesuada. Donec vel nibh a arcu placerat sodales. Donec sagittis metus vitae placerat finibus. Curabitur a augue finibus nisl scelerisque molestie ac nec arcu. Vivamus lorem ligula, efficitur at scelerisque ac, bibendum a enim. Quisque non leo nibh. Sed non ante vel lacus ultricies fringilla.

```{r}
for(i in 1:5){
print(i)
}

```
Loading