tide-jsx v0.4.0

#rust#proc-macro#jsx

git clone https://git.pyrossh.dev/tide-jsx

Tide + JSX


e3c3a07 — Peter John 2022-09-17T18:14:08+05:30
fix build tests

Generated files not shown: Cargo.lock

Cargo.toml CHANGED
@@ -11,8 +11,10 @@ categories = ["template-engine"]
11
11
  license = "MIT"
12
12
 
13
13
  [dependencies]
14
+ tide = "0.16.0"
14
15
  tide-jsx-impl = { path = "impl", version = "0.2.0" }
15
16
 
16
17
  [dev-dependencies]
17
18
  pretty_assertions = "0.6"
19
+ async-std = { version = "1.9.0", features = ["attributes"] }
18
- # trybuild = "1.0.64"
20
+ trybuild = "1.0"
LICENSE CHANGED
@@ -1,6 +1,7 @@
1
1
  MIT License
2
2
 
3
3
  Copyright (c) 2019 Gal Schlezinger
4
+ Copyright (c) 2022 pyrossh
4
5
 
5
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
  of this software and associated documentation files (the "Software"), to deal
README.md CHANGED
@@ -1,46 +1,10 @@
1
- # render
2
-
3
- > 🔏 A safe and simple template engine with the ergonomics of JSX
4
-
5
- `render` itself is a combination of traits, structs and macros that together unify and
6
- boost the experience of composing tree-shaped data structures. This works best with HTML and
7
- XML rendering, but can work with other usages as well, like ReasonML's [`Pastel`](https://reason-native.com/docs/pastel/) library for terminal colors.
8
-
9
- ## How?
10
-
11
- A renderable component is a struct that implements the `Render` trait. There
12
- are multiple macros that provide a better experience implementing Renderable:
13
-
14
- - `#[component]` for defining components using a function
15
- - `rsx!` for composing elements with JSX ergonomics
16
- - `html!` for composing elements and render them to a string
17
-
18
- ## Why is this different from...
19
-
20
- ### `handlebars`?
21
-
22
- Handlebars is an awesome spec that lets us devs define templates and work
23
- seemlessly between languages and frameworks. Unfortunately, it does not guarantee any of Rust's
24
- type-safety, due to its spec. This forces you to write tests for validating types for your views, like you would in a dynamically typed language. These tests weren't necessary in a type-safe language like Rust — but Handlebars is JSON-oriented, which doesn't comply Rust's type system.
25
-
26
- `render` provides the same level of type-safety Rust provides, with no compromises of
27
- ergonomics or speed.
28
-
29
- ### `typed-html`?
30
-
31
- `typed-html` is a wonderful library. Unfortunately, it focused its power in strictness of the HTML spec itself, and doesn't allow arbitrary compositions of custom elements.
32
-
33
- `render` takes a different approach. For now, HTML is not typed at all. It can get any key and get any string value. The main focus is custom components, so you can create a composable and declarative template with no runtime errors.
34
-
35
- ## Usage
36
-
37
- ### Simple HTML rendering
1
+ # tide-jsx
38
2
 
39
3
  In order to render a simple HTML fragment into a `String`, use the `rsx!` macro to generate a
40
4
  component tree, and call `render` on it:
41
5
 
42
6
  ```rust
43
- use render::{rsx, Render};
7
+ use tide_jsx::{rsx, Render};
44
8
 
45
9
  let tree = rsx! {
46
10
  <div>
@@ -62,7 +26,7 @@ use un-escaped values so you can dangerously insert raw HTML, use the `raw!` mac
62
26
  string:
63
27
 
64
28
  ```rust
65
- use render::{html, raw};
29
+ use tide_jsx::{html, raw};
66
30
 
67
31
  let tree = html! {
68
32
  <div>
@@ -83,7 +47,7 @@ In order to build up components from other components or HTML nodes, you can use
83
47
  macro, which generates a `Render` component tree:
84
48
 
85
49
  ```rust
86
- use render::{component, rsx, html};
50
+ use tide_jsx::{component, rsx, html};
87
51
 
88
52
  #[component]
89
53
  fn Heading<'title>(title: &'title str) {
@@ -134,20 +98,9 @@ your libraries.
134
98
  #### Full example
135
99
 
136
100
  ```rust
137
- // A simple HTML 5 doctype declaration
138
101
  use render::html::HTML5Doctype;
139
- use render::{
140
- // A macro to create components
102
+ use render::{component, rsx, html, Render};
141
- component,
142
- // A macro to compose components in JSX fashion
143
- rsx,
144
- // A macro to render components in JSX fashion
145
- html,
146
- // A trait for custom components
147
- Render,
148
- };
149
103
 
150
- // This can be any layout we want
151
104
  #[component]
152
105
  fn Page<'a, Children: Render>(title: &'a str, children: Children) {
153
106
  rsx! {
@@ -163,8 +116,6 @@ fn Page<'a, Children: Render>(title: &'a str, children: Children) {
163
116
  }
164
117
  }
165
118
 
166
- // This can be a route in Rocket, the web framework,
167
- // for instance.
168
119
  pub fn some_page(user_name: &str) -> String {
169
120
  html! {
170
121
  <Page title={"Home"}>
@@ -174,5 +125,3 @@ pub fn some_page(user_name: &str) -> String {
174
125
  }
175
126
 
176
127
  ```
177
-
178
- License: MIT
tests/lib.rs CHANGED
@@ -1,13 +1,14 @@
1
- // #[test]
2
- // fn ui() {
3
- // let t = trybuild::TestCases::new();
4
- // t.compile_fail("ui/fail/*.rs");
5
- // }
6
1
  use pretty_assertions::assert_eq;
7
2
  use tide_jsx::{html, rsx, component, Render, raw};
8
3
  use tide_jsx::html::HTML5Doctype;
9
4
  use std::borrow::Cow;
10
5
 
6
+ #[test]
7
+ fn ui() {
8
+ let t = trybuild::TestCases::new();
9
+ t.compile_fail("tests/ui/fail/*.rs");
10
+ }
11
+
11
12
  #[test]
12
13
  fn works_with_dashes() {
13
14
  use pretty_assertions::assert_eq;
tests/ui/fail/unclosed-tag-complex.rs CHANGED
@@ -1,4 +1,4 @@
1
- use render::html;
1
+ use tide_jsx::html;
2
2
 
3
3
  fn main() {
4
4
  html! {
tests/ui/{unclosed-tag.rs → fail/unclosed-tag.rs} RENAMED
@@ -1,5 +1,5 @@
1
1
  fn main() {
2
- render::html! {
2
+ tide_jsx::html! {
3
3
  <ul>
4
4
  <li>
5
5
  </ul>
tests/ui/fail/unclosed-tag.stderr CHANGED
@@ -1,5 +1,5 @@
1
1
  error: Expected closing tag for: <li>
2
- --> $DIR/unclosed-tag.rs:7:9
2
+ --> tests/ui/fail/unclosed-tag.rs:5:9
3
3
  |
4
- 7 | </ul>
4
+ 5 | </ul>
5
5
  | ^^
tests/ui/fail/unexpected-attribute.rs CHANGED
@@ -1,4 +1,4 @@
1
- use render::{component, html, rsx};
1
+ use tide_jsx::{component, html, rsx};
2
2
 
3
3
  #[component]
4
4
  fn Heading<'title>(title: &'title str) {