Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor custom node implementation, add visitor API and stable unqoted text. #44

Merged
merged 14 commits into from
Jan 14, 2024
Merged
28 changes: 17 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
name: ci

on: [push, pull_request]
on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
ci:
Expand All @@ -20,19 +26,19 @@ jobs:
- name: build
run: cargo build

- name: test
run: cargo test -p rstml

- name: clippy
run: cargo clippy --workspace

- name: test on Stable
run: cargo test --workspace

- name: Tests with rawtext hack
run: cargo test -p rstml --features "rawtext-stable-hack-module"

- name: Test extendable feature in rstml-control-flow
run: cargo test -p rstml-control-flow --features "extendable"

- uses: dtolnay/rust-toolchain@nightly

- name: test on Nightly
run: cargo test --workspace

- name: coverage
run: |
cargo install cargo-tarpaulin
cargo tarpaulin --out xml
bash <(curl -s https://codecov.io/bash)
run: cargo test --workspace
33 changes: 33 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: coverage

on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
test:
name: coverage
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@nightly

- name: coverage nightly
run: |
cargo install cargo-tarpaulin
cargo tarpaulin --out xml --output-dir ./nightly --workspace
- uses: dtolnay/rust-toolchain@stable

- name: coverage nightly
run: |
cargo tarpaulin --out xml --output-dir ./stable --workspace
- uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./stable/cobertura.xml,./nightly/cobertura.xml
name: RSTML
8 changes: 8 additions & 0 deletions .tarpaulin.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[unquoted_text_on_stable]
features = "rstml/rawtext-stable-hack"

[custom_node_extendable]
features = "rstml-control-flow/extendable"

[report]
out = ["Xml", "Html"]
25 changes: 17 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "rstml"
description = "Rust templating for XML-based formats (HTML, SVG, MathML) implemented on top of proc-macro::TokenStreams"
version = "0.11.2"
authors = ["vldm <[email protected]>","stoically <[email protected]>"]
authors = ["vldm <[email protected]>", "stoically <[email protected]>"]
keywords = ["syn", "jsx", "rsx", "html", "macro"]
edition = "2018"
repository = "https://github.com/rs-tml/rstml"
Expand All @@ -15,17 +15,22 @@ include = ["/src", "LICENSE"]
bench = false

[dependencies]
proc-macro2 = "1.0.47"
proc-macro2 = { version = "1.0.47", features = ["span-locations"] }
quote = "1.0.21"
syn = { version = "2.0.15", features = ["full", "parsing", "extra-traits"] }
syn = { version = "2.0.15", features = [
"visit-mut",
"full",
"parsing",
"extra-traits",
] }
thiserror = "1.0.37"
syn_derive = "0.1.6"
proc-macro2-diagnostics = { version = "0.10", default-features = false }
derive-where = "1.2.5"

[dev-dependencies]
proc-macro2 = {version = "1.0.47", features = ["span-locations"]}
criterion = "0.4.0"
proc-macro2 = { version = "1.0.47", features = ["span-locations"] }
criterion = "0.5.1"
eyre = "0.6.8"

[[bench]]
Expand All @@ -34,10 +39,14 @@ harness = false
path = "benches/bench.rs"

[workspace]
members = [
"examples/html-to-string-macro"
]
members = ["examples/html-to-string-macro", "rstml-control-flow"]

[features]
default = ["colors"]
# Hack that parse input two times, using `proc-macro2::fallback` to recover spaces, and persist original spans.
# It has no penalty in nightly, but in stable it parses input two times.
# In order to use this feature, one should also set `ParserConfig::macro_call_pattern`.
rawtext-stable-hack = ["rawtext-stable-hack-module"]
# Export inters of rawtext_stable_hack. It is usefull if you need support of `UnquotedText` on stable but your macro is called from other one.
rawtext-stable-hack-module = []
colors = ["proc-macro2-diagnostics/colors"]
17 changes: 17 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use std::{env, process::Command, str::from_utf8};

fn main() {
if is_rustc_nightly() {
println!("cargo:rustc-cfg=rstml_signal_nightly");
}
}

fn is_rustc_nightly() -> bool {
|| -> Option<bool> {
let rustc = env::var_os("RUSTC")?;
let output = Command::new(rustc).arg("--version").output().ok()?;
let version = from_utf8(&output.stdout).ok()?;
Some(version.contains("nightly"))
}()
.unwrap_or_default()
}
9 changes: 7 additions & 2 deletions examples/html-to-string-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "rstml-to-string-macro"
description = "simple html to string macro powered by rstml"
version = "0.1.0"
authors = ["vldm <[email protected]>","stoically <[email protected]>"]
authors = ["vldm <[email protected]>", "stoically <[email protected]>"]
keywords = ["html-to-string", "html", "macro"]
edition = "2021"
repository = "https://github.com/rs-tml/rstml/tree/main/examples/html-to-string-macro"
Expand All @@ -16,8 +16,13 @@ proc-macro = true
proc-macro2 = "1.0.47"
quote = "1.0.21"
syn = "2.0.15"
rstml = { version = "0.11.0", path = "../../" }
syn_derive = "0.1"
rstml = { version = "0.11.0", path = "../../", features = [
"rawtext-stable-hack",
] }
proc-macro2-diagnostics = "0.10"
derive-where = "1.2.5"
rstml-control-flow = { version = "0.1.0", path = "../../rstml-control-flow" }

[dev-dependencies]
trybuild = "1.0"
Loading