Skip to content

Commit 0dccd7d

Browse files
committed
chore: Refactor custom node visitor.
1 parent 24c3d64 commit 0dccd7d

File tree

12 files changed

+382
-154
lines changed

12 files changed

+382
-154
lines changed

Diff for: .github/workflows/ci.yml

+9-3
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,18 @@ jobs:
2020
- name: build
2121
run: cargo build
2222

23-
- name: test
24-
run: cargo test -p rstml --features "rawtext-stable-hack-module"
25-
2623
- name: clippy
2724
run: cargo clippy --workspace
2825

26+
- name: test on Stable
27+
run: cargo test --workspace
28+
29+
- name: Tests with rawtext hack
30+
run: cargo test -p rstml --features "rawtext-stable-hack-module"
31+
32+
- name: Test extendable feature in rstml-control-flow
33+
run: cargo test -p rstml-control-flow --features "extendable"
34+
2935
- uses: dtolnay/rust-toolchain@nightly
3036

3137
- name: test on Nightly

Diff for: Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ harness = false
3939
path = "benches/bench.rs"
4040

4141
[workspace]
42-
members = ["examples/html-to-string-macro", "rstml-controll-flow"]
42+
members = ["examples/html-to-string-macro", "rstml-control-flow"]
4343

4444
[features]
4545
default = ["colors"]

Diff for: examples/html-to-string-macro/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ rstml = { version = "0.11.0", path = "../../", features = [
2222
] }
2323
proc-macro2-diagnostics = "0.10"
2424
derive-where = "1.2.5"
25-
rstml-controll-flow = { version = "0.1.0", path = "../../rstml-controll-flow" }
25+
rstml-control-flow = { version = "0.1.0", path = "../../rstml-control-flow" }
2626

2727
[dev-dependencies]
2828
trybuild = "1.0"

Diff for: examples/html-to-string-macro/src/lib.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use quote::{quote, quote_spanned, ToTokens};
55
use rstml::{
66
node::{Node, NodeAttribute, NodeName},
77
visitor::{visit_attributes, visit_nodes, Visitor},
8-
Infallible, Parser, ParserConfig,
8+
Parser, ParserConfig,
99
};
1010
use syn::spanned::Spanned;
1111
// mod escape;
@@ -46,9 +46,10 @@ impl WalkNodesOutput {
4646
}
4747
impl<'a> syn::visit_mut::VisitMut for WalkNodes<'a> {}
4848

49-
impl<'a> Visitor for WalkNodes<'a> {
50-
type Custom = Infallible;
51-
49+
impl<'a, C> Visitor<C> for WalkNodes<'a>
50+
where
51+
C: rstml::node::CustomNode + 'static,
52+
{
5253
fn visit_doctype(&mut self, doctype: &mut rstml::node::NodeDoctype) -> bool {
5354
let value = &doctype.value.to_token_stream_string();
5455
self.output
@@ -67,7 +68,7 @@ impl<'a> Visitor for WalkNodes<'a> {
6768
self.output.static_format.push_str(&node.to_string_best());
6869
false
6970
}
70-
fn visit_fragment(&mut self, fragment: &mut rstml::node::NodeFragment<Self::Custom>) -> bool {
71+
fn visit_fragment(&mut self, fragment: &mut rstml::node::NodeFragment<C>) -> bool {
7172
let visitor = self.child_output();
7273
let child_output = visit_nodes(&mut fragment.children, visitor);
7374
self.output.extend(child_output.output);
@@ -85,7 +86,7 @@ impl<'a> Visitor for WalkNodes<'a> {
8586
self.output.values.push(block.to_token_stream());
8687
false
8788
}
88-
fn visit_element(&mut self, element: &mut rstml::node::NodeElement<Self::Custom>) -> bool {
89+
fn visit_element(&mut self, element: &mut rstml::node::NodeElement<C>) -> bool {
8990
let name = element.name().to_string();
9091
self.output.static_format.push_str(&format!("<{}", name));
9192
self.output

Diff for: rstml-controll-flow/Cargo.toml renamed to rstml-control-flow/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "rstml-controll-flow"
2+
name = "rstml-control-flow"
33
version = "0.1.0"
44
edition = "2021"
55

Diff for: rstml-controll-flow/README.md renamed to rstml-control-flow/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ let nodes = parse2_with_config(template, Default::default().with_custom_nodes::<
8383
## Using multiple `CustomNode`s at once
8484
It is also possible to use more than one `CustomNode` at once.
8585
For example, if you want to use both `Conditions` and `EscapedCode` custom nodes.
86-
`rstml-controll-flow` crate provides an `ExtendableCustomNode` struct that can be used to combine multiple `CustomNode`s into one. Check out `extendable.rs` docs and tests in `lib.rs` for more details.
86+
`rstml-control-flow` crate provides an `ExtendableCustomNode` struct that can be used to combine multiple `CustomNode`s into one. Check out `extendable.rs` docs and tests in `lib.rs` for more details.
8787

8888

8989
```rust

0 commit comments

Comments
 (0)