Skip to content

Commit

Permalink
Add support for themes and png-output
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaslueg committed Jul 26, 2024
1 parent 9f6571e commit a4e272d
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 5,088 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo run --example example_diagrams
- uses: actions/upload-artifact@v4
with:
name: examples
path: examples/*.html
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

/target
**/*.rs.bk
Cargo.lock
examples/example_diagrams.html
examples/example_diagrams_light.html
examples/example_diagrams_dark.html
examples/*.png
examples/*.svg
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.2.1"
authors = ["Lukas Lueg <lukas.lueg@gmail.com>"]
license = "MIT"
description = "A small DSL to generate syntax-diagrams"
exclude = ["examples/*.html", "examples/*.jpeg"]
exclude = ["examples/*.html", "examples/*.jpeg", "examples/*.png", "examples/*.svg"]
repository = "/~https://github.com/lukaslueg/railroad_dsl"
readme = "README.md"
edition = "2021"
Expand All @@ -13,4 +13,4 @@ edition = "2021"
pest = "2.6"
pest_derive = "2.6"
clap = { version = "4.3", features = ["derive"]}
railroad = "0.3"
railroad = { version="0.3.2", features = [ "resvg" ]}
57 changes: 52 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ A small DSL to generate syntax diagrams using [this library](/~https://github.com/
[![Crates.io Version](https://img.shields.io/crates/v/railroad_dsl.svg)](https://crates.io/crates/railroad_dsl)
[![Build status](/~https://github.com/lukaslueg/railroad_dsl/actions/workflows/check.yml/badge.svg)](/~https://github.com/lukaslueg/railroad_dsl/actions/workflows/check.yml)

**[Some examples](https://htmlpreview.github.io/?/~https://github.com/lukaslueg/railroad_dsl/blob/master/examples/example_diagrams.html)**


* `{...}` is a horizontal stack of connected elements
* `[...]` is a vertical sequence of connected elements
* `<...>` is a choice of multiple options, exactly one of which has to be picked
Expand All @@ -20,7 +17,7 @@ Quotes (and backslashes) can be escaped using backslashes.

For example:

```
```raw
{["CONSTRAINT" "name"]?,
<["PRIMARY" "KEY" <!, "ASC", "DESC"> 'conflict-clause' <!, "AUTOINCREMENT">],
["NOT" "NULL" 'conflict-clause'],
Expand All @@ -33,6 +30,56 @@ For example:

![diagram for constraint syntax](https://raw.githubusercontent.com/lukaslueg/railroad_dsl/master/examples/column_constraint.jpeg)

```raw
{[`create-table-stmt` "CREATE" <!, <"TEMP", "TEMPORARY">#`Table will be dropped when connection closes`> "TABLE"],
[[["IF" "NOT" "EXISTS"]#`If table exists, do nothing`]? [[["schema-name" "."]#`...in a foreign database`]? "table-name"]#`The table's name`],
[<["(" ['column-def'*","]#`One or more column-definitions` [!*[['table-constraint' ","]#`primary key and stuff`]]#`Zero or more table-constraints` ")" <!, ["WITHOUT" "ROWID"]>],
["AS" 'select-stmt']#`Create table definition and content directly from a query`>]}
```

![diagram for create-table syntax](https://raw.githubusercontent.com/lukaslueg/railroad_dsl/master/examples/create_table_stmt.jpeg)


Run `cargo run --example example_diagrams` for more examples.

---

Use the `--css` option to provide an alternative CSS scheme; the library's [default CSS](https://docs.rs/railroad/latest/railroad/constant.DEFAULT_CSS.html#) is used if none is provided.
```raw
A small DSL to generate syntax-diagrams.
If no input files are given, act as a pipe from stdin to stdout. Otherwise, process each input file into an output file with the file extension replaced
Usage: railroad [OPTIONS] [INPUTS]...
Arguments:
[INPUTS]...
Options:
--css <CSS>
Alternative CSS file
--format <FORMAT>
Output format
[default: svg]
[possible values: svg, png]
--max-width <MAX_WIDTH>
Maximum width of the final image
--max-height <MAX_HEIGHT>
Maximum height of the final image
--theme <THEME>
Theme to use
[default: light]
[possible values: light, dark]
-h, --help
Print help (see a summary with '-h')
-V, --version
Print version
```
Binary file added examples/create_table_stmt.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit a4e272d

Please sign in to comment.