Skip to content

Commit

Permalink
Schema for manifest (#847)
Browse files Browse the repository at this point in the history
* Initial attempt at schema for project.ptx files

* Add Github action to make sure the compiled and compact schemas are
identical

* Test all `project.ptx` template files against the schema

* Updated schema to work on all template documents

* Update schema

* set up folder

* possibly fix tag issue with deploy

* First stab at .rnc version

* fix syntax errors, verify working

---------

Co-authored-by: Jason Siefken <[email protected]>
  • Loading branch information
oscarlevin and siefkenj authored Oct 18, 2024
1 parent 4b508bb commit 03d0641
Show file tree
Hide file tree
Showing 6 changed files with 444 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .github/workflows/deploy-stable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ jobs:
git commit -m "update changelog for release"
git add pyproject.toml
git commit -m "bump version to next patch level for nightly releases"
git tag -d ${{ env.VERSION }}
git tag ${{ env.VERSION }}
git push --set-upstream origin ${{ env.VERSION }}
gh pr create --fill
gh pr merge -s -d -t "Update changelog and bump version to next patch level for nightly releases"
Expand All @@ -114,7 +116,8 @@ jobs:
See the [changelog](CHANGELOG.md) for details.
draft: false
prerelease: false



- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v2
with:
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,19 @@ jobs:
- name: Test with pytest
run: |
python -m poetry run pytest -v --cov
schema:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: jing trang
version: 1.0
- name: Make sure Schema rnc and rng files in sync via TRANG
run: |
trang ./schema/project-ptx.rnc ./tmp-project-ptx.rng
cmp ./schema/project-ptx.rng ./tmp-project-ptx.rng
- name: Verify template `project.ptx` match schema via JING
run: |
for i in $(find ./templates -name "project.ptx"); do jing ./schema/project-ptx.rng "$i"; done
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Instructions: Add a subsection under `[UNRELEASED]` for additions, fixes, change

## [UNRELEASED]


## [2.8.0] - 2024-10-18

### Added
Expand Down
18 changes: 18 additions & 0 deletions schema/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
This directory will contain the RelaxNG schema for the project manifest `project.ptx`.

There are two versions, a compact syntax (`.rnc`) and XML (`.rng`). Edits should be made to the `.rnc` file which can then be converted to the `.rng` version using [trang](https://github.com/relaxng/jing-trang) via
```
> trang project-ptx.rnc project-ptx.rng
```

You can then use [jing](https://github.com/relaxng/jing-trang) to test
whether a `project.ptx` file conforms to the schema.
```
> jing project-ptx.rng path/to/project.ptx
```

If you are running these commands directly from Java `.jar` files, you will
instead run
```
> java -jar path/to/jing.jar [...other arguments...]
```
128 changes: 128 additions & 0 deletions schema/project-ptx.rnc
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# Relax-ng grammar for `project.ptx` files.
# To use this grammar, it must first be converted from
# "compact" form (the `.rnc` file) into XML (the `.rng` file).
# This conversion is accomplished with [trang](https://github.com/relaxng/jing-trang) via
# ```
# > trang project-ptx.rnc project-ptx.rng
# ```
# You can then use [jing](https://github.com/relaxng/jing-trang) to test
# whether a `project.ptx` file conforms to the schema.
# ```
# > jing project-ptx.rng path/to/project.ptx
# ```
#
# If you are running these commands directly from Java `.jar` files, you will
# instead run
# ```
# > java -jar path/to/jing.jar [...other arguments...]
# ```

grammar {

start = Project

Project = element project {
ProjectReqAttributes,
ProjectOptAttributes,
Targets
}

ProjectReqAttributes = attribute ptx-version { "2" }

ProjectOptAttributes = (
attribute source { text }?,
attribute publication { text }?,
attribute output-dir { text }?,
attribute site {text}?,
attribute xsl { text }?,
attribute asy-method { "server" | "local" }?
)

Targets = element targets { Target+ }

Target = element target {
## Unique identifier for this build target. This is the name you pass on the
## command line when building via the `pretext` CLI.
attribute name { text },
## the required format can be `html`, `pdf`, `latex`, `epub`, `kindle`, `braille`, `revealjs`, `webwork`, or `custom`.
(
HtmlAttributes
| PdfAttributes
| LatexAttributes
| EpubAttributes
| BrailleAttributes
| RevealjsAttributes
| WebworkAttributes
| CustomAttributes
),
CommonAttributes,
## Parameters that get passed directly to the XSL processing backend.
## These parameters are rarely used by content authors.
Stringparams*
}

CommonAttributes = (
attribute source { text }?,
attribute publication { text }?,
attribute output-dir { text }?,
attribute deploy-dir { text }?,
attribute site {text}?,
attribute xsl { text }?,
attribute asy-method { "server" | "local" }?
)

HtmlAttributes = (
attribute format { "html" },
(attribute platform { "runestone" }?
| attribute compression { "zip" }?)
)

PdfAttributes = (
attribute format { "pdf" },
attribute latex-engine { "xelatex" | "pdflatex" | "latex" }?,
attribute output-filename { text }?
)

LatexAttributes = (
attribute format { "latex" },
attribute output-filename { text }?
)

EpubAttributes = (
attribute format { "epub"|"kindle" },
attribute output-filename { text }?
)

BrailleAttributes = (
attribute format { "braille" },
attribute braille-mode { "emboss" | "electronic" }?
)

RevealjsAttributes = (
attribute format { "revealjs" },
attribute output-filename { text }?
)

WebworkAttributes = (
attribute format { "webwork" },
attribute compression { "zip" }?
)

CustomAttributes = (
attribute format { "custom" }
)


Stringparams = element stringparams {
# Attributes are the name of the string-param and the value is the value of the string-param.
attribute debug.datedfiles {"yes"|"no"}?,
attribute debug.mathjax4 { "yes" | "no" }?,
attribute debug.react.local { "yes" | "no" }?,
attribute debug.react.global { "yes" | "no" }?,
attribute debug.html.annotate { "yes" | "no" }?,
attribute debug.skip-knowls { "yes" | "no" }?,
attribute author.tools { "yes" | "no" }?,
attribute html.css.extra { text }?
}

}
Loading

0 comments on commit 03d0641

Please sign in to comment.