Skip to content

Commit

Permalink
Merge package history from monorepo into new template
Browse files Browse the repository at this point in the history
  • Loading branch information
SillyFreak committed Jun 9, 2024
2 parents 264d07e + 78e2b32 commit a20d823
Show file tree
Hide file tree
Showing 18 changed files with 297 additions and 51 deletions.
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
target = ["wasm32-unknown-unknown"]
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
7 changes: 7 additions & 0 deletions .typstignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ docs/*
!docs/*.pdf
gallery/*
!gallery/*.pdf

# ignore plugin-related files
.cargo
plugin
target
Cargo.lock
Cargo.toml
111 changes: 111 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[workspace]
resolver = "2"

members = [
"plugin",
]

[profile.release]
lto = true # Enable link-time optimization
strip = true # Strip symbols from binary*
opt-level = 'z' # Optimize for size
codegen-units = 1 # Reduce number of codegen units to increase optimizations
panic = 'abort' # Abort on panic
7 changes: 6 additions & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ default:
# generate manual
doc:
typst compile docs/manual.typ docs/manual.pdf
for f in $(find gallery -maxdepth 1 -name '*.typ'); do typst c "$f"; done
# for f in $(find gallery -maxdepth 1 -name '*.typ'); do typst c "$f"; done

# run test suite
test *args:
Expand All @@ -19,6 +19,11 @@ test *args:
update *args:
typst-test update {{ args }}

# build the PlantUML URL encoding WASM plugin
plugin:
cargo build --release
cp target/wasm32-unknown-unknown/release/plantuml_url.wasm src/

# package the library into the specified destination folder
package target:
./scripts/package "{{target}}"
Expand Down
30 changes: 4 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,15 @@
# The `my-package` Package
# pre-plantuml

A short description about the project and/or client.

## Template adaptation checklist

- [ ] Fill out `README.md`
- Change the `my-package` package name, including code snippets
- Check section contents and/or delete sections that don't apply
- [ ] Check and/or replace `LICENSE` by something that suits your needs
- [ ] Fill out `typst.toml`
- See also the [typst/packages README](https://github.com/typst/packages/?tab=readme-ov-file#package-format)
- [ ] Adapt Repository URLs in `CHANGELOG.md`
- Consider only committing that file with your first release, or removing the "Initial Release" part in the beginning
- [ ] Adapt or deactivate the release workflow in `.github/workflows/release.yml`
- to deactivate it, delete that file or remove/comment out lines 2-4 (`on:` and following)
- to use the workflow
- [ ] check the values under `env:`, particularly `REGISTRY_REPO`
- [ ] if you don't have one, [create a fine-grained personal access token](https://github.com/settings/tokens?type=beta) with [only Contents permission](https://stackoverflow.com/a/75116350/371191) for the `REGISTRY_REPO`
- [ ] on this repo, create a secret `REGISTRY_TOKEN` (at `https://github.com/[user]/[repo]/settings/secrets/actions`) that contains the so created token

if configured correctly, whenever you create a tag `v...`, your package will be pushed onto a branch on the `REGISTRY_REPO`, from which you can then create a pull request against [typst/packages](https://github.com/typst/packages/)
- [ ] remove/replace the example test case
- [ ] (add your actual code, docs and tests)
- [ ] remove this section from the README
This package provides a [prequery](https://typst.app/universe/package/prequery) for UML diagrams specified using [PlantUML](https://www.plantuml.com/) syntax. The diagrams can be extracted either as source code, or as URLs to a specific PlantUML Webservice.

## Getting Started

To add this package to your project, use this:

```typ
#import "@preview/typst-package-template:0.1.0": *
#import "@preview/pre-plantuml:0.1.0": *
#id[Hello World]
...
```

## Usage
Expand Down
22 changes: 10 additions & 12 deletions docs/manual.typ
Original file line number Diff line number Diff line change
@@ -1,38 +1,36 @@
#import "@preview/tidy:0.3.0"
#import "@preview/crudo:0.1.0"
// #import "@preview/crudo:0.1.0"

#import "template.typ": *

#import "/src/lib.typ" as template
#import "/src/lib.typ" as pre-plantuml

#let package-meta = toml("/typst.toml").package
#let date = none
// #let date = datetime(year: ..., month: ..., day: ...)

#show: project.with(
title: "Template",
title: "pre-plantuml",
// subtitle: "...",
authors: package-meta.authors.map(a => a.split("<").at(0).trim()),
abstract: [
A template for typst packages
Extract PlantUML diagrams from Typst documents to be rendered into images.
],
url: package-meta.repository,
version: package-meta.version,
date: date,
)

// the scope for evaluating expressions and documentation
#let scope = (template: template)
#let scope = (pre-plantuml: pre-plantuml)

= Introduction

This is a template for typst packages. It provides the #ref-fn("template.id()") function:
This package provides two #link("https://typst.app/universe/package/prequery")[prequeries] for using PlantUML in Typst:
- #ref-fn("plantuml-url()") provides the encoded diagram URL to preprocessors for downloading the diagram file;
- #ref-fn("plantuml-source()") provides the diagram source code to preprocessors for generating the diagram image locally.

#{
let lib = raw(block: true, lang: "typ", read("/src/lib.typ").trim())
lib = crudo.slice(lib, 4)
lib
}
See the Prequery library documentation for more general information on how this can be used.

= Module reference

Expand All @@ -41,7 +39,7 @@ This is a template for typst packages. It provides the #ref-fn("template.id()")
#{
let module = tidy.parse-module(
read("/src/lib.typ"),
label-prefix: "template.",
// label-prefix: "pre-plantuml.",
scope: scope,
)
tidy.show-module(
Expand Down
1 change: 1 addition & 0 deletions gallery/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
assets/
Binary file added gallery/test-fallback.pdf
Binary file not shown.
Binary file added gallery/test.pdf
Binary file not shown.
25 changes: 25 additions & 0 deletions gallery/test.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// make the PDF reproducible to ease version control
#set document(date: none)

#import "/src/lib.typ": plantuml-url, plantuml-source
#import "@preview/prequery:0.1.0"
// #import "@preview/pre-plantuml:0.0.1": plantuml-url, plantuml-source

// toggle this comment or pass `--input prequery-fallback=true` to enable fallback
// #prequery.fallback.update(true)

#let plantuml = plantuml-url.with("https://www.plantuml.com/plantuml/png/")

= Test

#plantuml("assets/uml.png", ```
@startuml
PUML -> RUST: HELLO
@enduml
```)

#plantuml-source("assets/uml.png", ```
@startuml
PUML -> RUST: HELLO
@enduml
```)
11 changes: 11 additions & 0 deletions plugin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "plantuml-url"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["cdylib"]

[dependencies]
wasm-minimal-protocol = { git = "https://github.com/astrale-sharp/wasm-minimal-protocol" }
plantuml_encoding = "2.0.3"
29 changes: 29 additions & 0 deletions plugin/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use std::str;

use wasm_minimal_protocol::*;
use plantuml_encoding::encode_plantuml_deflate;

initiate_protocol!();

#[wasm_func]
pub fn encode(source: &[u8]) -> Vec<u8> {
match encode_impl(source) {
Ok(result) => {
let mut result = result.into_bytes();
result.insert(0, 1u8);
result
}
Err(result) => {
let mut result = result.into_bytes();
result.insert(0, 0u8);
result
}
}
}

fn encode_impl(source: &[u8]) -> Result<String, String> {
let source = str::from_utf8(source).map_err(|err| format!("{:?}", err))?;
let encoded = encode_plantuml_deflate(source).map_err(|err| err.0)?;

Ok(encoded)
}
Loading

0 comments on commit a20d823

Please sign in to comment.