Skip to content

Commit 201dbcc

Browse files
committed
Replace pkgdown with altdoc
1 parent b6eacb0 commit 201dbcc

24 files changed

+2444
-52
lines changed

.github/workflows/altdoc.yaml

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
2+
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
3+
on:
4+
push:
5+
branches: [main, master]
6+
pull_request:
7+
branches: [main, master]
8+
release:
9+
types: [published]
10+
workflow_dispatch: {}
11+
12+
name: altdoc
13+
14+
jobs:
15+
rwasmbuild:
16+
# Only restrict concurrency for non-PR jobs
17+
concurrency:
18+
group: altdoc-webr-${{ github.event_name != 'pull_request' || github.run_id }}
19+
env:
20+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
21+
permissions:
22+
contents: write
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v4
27+
28+
# Build the local R package and structure the CRAN repository
29+
- name: Build WASM R packages
30+
uses: r-wasm/actions/build-rwasm@v1
31+
with:
32+
packages: "."
33+
repo-path: "_site"
34+
35+
# Upload the CRAN repository for use in the next step
36+
# Make sure to set a retention day to avoid running into a cap
37+
- name: Upload build artifact
38+
uses: actions/upload-artifact@v3
39+
with:
40+
name: rwasmrepo
41+
path: |
42+
_site
43+
retention-days: 1
44+
45+
46+
altdoc:
47+
runs-on: ubuntu-latest
48+
# Add a dependency on the prior job completing
49+
needs: rwasmbuild
50+
# Required for the gh-pages deployment action
51+
environment:
52+
name: github-pages
53+
env:
54+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
55+
permissions:
56+
# To download GitHub Packages within action
57+
repository-projects: read
58+
# For publishing to pages environment
59+
pages: write
60+
id-token: write
61+
steps:
62+
- uses: actions/checkout@v4
63+
64+
- uses: quarto-dev/quarto-actions/setup@v2
65+
66+
- name: Get Script
67+
run: curl -OLs https://eddelbuettel.github.io/r-ci/run.sh && chmod 0755 run.sh
68+
69+
- name: Bootstrap
70+
run: ./run.sh bootstrap
71+
72+
- name: Dependencies
73+
run: ./run.sh install_all
74+
75+
- name: Build site
76+
run: |
77+
# If parallel = TRUE in render_docs()
78+
# future::plan(future::multicore)
79+
install.packages(".", repos = NULL, type = "source")
80+
install.packages("pkgload")
81+
pkgload::load_all()
82+
altdoc::render_docs(parallel = FALSE, freeze = FALSE)
83+
shell: Rscript {0}
84+
85+
- name: Copy to new directory
86+
run: |
87+
cp -r docs _site
88+
89+
# New material ---
90+
91+
# Download the built R WASM CRAN repository from the prior step.
92+
# Extract it into the `_site` directory
93+
- name: Download build artifact
94+
uses: actions/download-artifact@v3
95+
with:
96+
name: rwasmrepo
97+
path: _site
98+
99+
# Upload a tar file that will work with GitHub Pages
100+
# Make sure to set a retention day to avoid running into a cap
101+
# This artifact shouldn't be required after deployment onto pages was a success.
102+
- name: Upload Pages artifact
103+
uses: actions/upload-pages-artifact@v2
104+
with:
105+
retention-days: 1
106+
107+
# Use an Action deploy to push the artifact onto GitHub Pages
108+
# This requires the `Action` tab being structured to allow for deployment
109+
# instead of using `docs/` or the `gh-pages` branch of the repository
110+
- name: Deploy to GitHub Pages
111+
id: deployment
112+
uses: actions/deploy-pages@v2

.github/workflows/pkgdown.yaml

-48
This file was deleted.

_pkgdown.yml

-4
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: panelize
2+
title: Panelize code cells
3+
author: Carlos Scheidegger and James Joseph Balamuta
4+
version: 0.0.0-dev.1
5+
quarto-required: ">=1.4.554"
6+
contributes:
7+
filters:
8+
- panelize.lua
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
-- Function to process code blocks
2+
local function clean_code_block(el, language)
3+
4+
-- Check if the code block contains R code
5+
if el.text:match("^```{{"..language) then
6+
-- Remove the ```{{<language>}} and ``` lines
7+
local cleaned_text = el.text:gsub("```{{".. language .."}}\n", ""):gsub("\n```", "")
8+
9+
-- Remove lines starting with #| (options)
10+
cleaned_text = cleaned_text:gsub("#|.-\n", "")
11+
12+
-- Add 'language' to the class list if not already present
13+
if not el.attr.classes:includes(language) then
14+
table.insert(el.attr.classes, 1, language)
15+
end
16+
17+
-- Return the modified code block
18+
return pandoc.CodeBlock(cleaned_text, el.attr)
19+
end
20+
21+
-- If not an R code block, return unchanged
22+
return el
23+
end
24+
25+
-- Helper function to clone and update code block attributes
26+
local function clone_and_update_code_block(code_block, new_classes)
27+
local new_attr = code_block.attr:clone()
28+
new_attr.classes = pandoc.List(new_classes)
29+
return pandoc.CodeBlock(code_block.text, new_attr)
30+
end
31+
32+
function Div(div)
33+
local to_webr = div.classes:includes("to-webr")
34+
local to_pyodide = div.classes:includes("to-pyodide")
35+
36+
-- Check if the `div` has the class "to-source"/"to-webr"/"to-pyodide"
37+
if not (div.classes:includes("to-source") or to_webr or to_pyodide) then
38+
return
39+
end
40+
41+
-- Initialize local variables for code block, cell output, and language
42+
local code_block = nil
43+
local cell_output = nil
44+
local language = nil
45+
46+
-- Walk through the content of the `div` to find `CodeBlock` and `Div` elements
47+
div:walk({
48+
CodeBlock = function(code)
49+
-- If a `CodeBlock` with the class "cell-code" is found, assign it to `code_block`
50+
if code.classes:includes("cell-code") then
51+
code_block = code
52+
-- Determine the language of the code block
53+
if code.classes:includes("r") or code.text:match("^```{{r") then
54+
language = "r"
55+
elseif code.classes:includes("python") or code.text:match("^```{{python") then
56+
language = "python"
57+
else
58+
quarto.log.error("Please only specify either R or Python code cells inside of the `to-panel` div.")
59+
end
60+
end
61+
end,
62+
Div = function(div)
63+
-- If a `Div` with the class "cell-output" is found, assign it to `cell_output`
64+
if div.classes:includes("cell-output") then
65+
cell_output = div
66+
end
67+
end
68+
})
69+
70+
local cleaned_code_cell = clean_code_block(code_block, language)
71+
72+
-- Determine the type of Tab to use
73+
local tabs = nil
74+
75+
-- Check if the language matches the required condition
76+
if to_webr or to_pyodide then
77+
-- Create a tab for the Result
78+
local result_tab = quarto.Tab({ title = "Result", content = pandoc.List({code_block, cell_output}) })
79+
80+
-- Pick attribute classes
81+
local code_block_attr_classes = to_webr and {"{webr-r}", "cell-code"} or {"{pyodide-python}", "cell-code"}
82+
83+
-- Create a tab for the Source
84+
local interactive_tab = quarto.Tab({ title = "Interactive", content = clone_and_update_code_block(code_block, code_block_attr_classes) })
85+
86+
-- Combine the tabs into a list
87+
tabs = pandoc.List({ result_tab, interactive_tab })
88+
else
89+
-- Create a tab for the Rendered
90+
local rendered_tab = quarto.Tab({ title = "Result", content = pandoc.List({cleaned_code_cell, cell_output}) })
91+
92+
-- Create a tab for the Source
93+
local source_tab = quarto.Tab({ title = "Source", content = clone_and_update_code_block(code_block, {"md", "cell-code"}) })
94+
95+
-- Combine the tabs into a list
96+
tabs = pandoc.List({ rendered_tab, source_tab })
97+
end
98+
99+
-- Return a `quarto.Tabset` with the created tabs and specific attributes
100+
return quarto.Tabset({
101+
level = 3,
102+
tabs = tabs,
103+
attr = pandoc.Attr("", {"panel-tabset"}) -- This attribute assignment shouldn't be necessary but addresses a known issue. Remove when using Quarto 1.5 or greater as required version.
104+
})
105+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: webr
2+
title: Embedded webr code cells
3+
author: James Joseph Balamuta
4+
version: 0.4.2-dev.6
5+
quarto-required: ">=1.4.554"
6+
contributes:
7+
filters:
8+
- webr.lua

0 commit comments

Comments
 (0)