~repos /tide-jsx

#rust#proc-macro#jsx

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

Tide + JSX


77cb4fef Peter John

3 years ago
rename
Cargo.lock CHANGED
@@ -27,24 +27,6 @@ version = "2.0.0"
27
27
  source = "registry+https://github.com/rust-lang/crates.io-index"
28
28
  checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198"
29
29
 
30
- [[package]]
31
- name = "glob"
32
- version = "0.3.0"
33
- source = "registry+https://github.com/rust-lang/crates.io-index"
34
- checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
35
-
36
- [[package]]
37
- name = "itoa"
38
- version = "0.4.6"
39
- source = "registry+https://github.com/rust-lang/crates.io-index"
40
- checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6"
41
-
42
- [[package]]
43
- name = "lazy_static"
44
- version = "1.4.0"
45
- source = "registry+https://github.com/rust-lang/crates.io-index"
46
- checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
47
-
48
30
  [[package]]
49
31
  name = "output_vt100"
50
32
  version = "0.1.2"
@@ -110,72 +92,6 @@ dependencies = [
110
92
  "proc-macro2",
111
93
  ]
112
94
 
113
- [[package]]
114
- name = "render"
115
- version = "0.3.1"
116
- dependencies = [
117
- "pretty_assertions",
118
- "render_macros",
119
- ]
120
-
121
- [[package]]
122
- name = "render_macros"
123
- version = "0.3.1"
124
- dependencies = [
125
- "pretty_assertions",
126
- "proc-macro-error",
127
- "proc-macro2",
128
- "quote",
129
- "render",
130
- "syn",
131
- ]
132
-
133
- [[package]]
134
- name = "render_tests"
135
- version = "0.3.1"
136
- dependencies = [
137
- "pretty_assertions",
138
- "render",
139
- "trybuild",
140
- ]
141
-
142
- [[package]]
143
- name = "ryu"
144
- version = "1.0.5"
145
- source = "registry+https://github.com/rust-lang/crates.io-index"
146
- checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
147
-
148
- [[package]]
149
- name = "serde"
150
- version = "1.0.114"
151
- source = "registry+https://github.com/rust-lang/crates.io-index"
152
- checksum = "5317f7588f0a5078ee60ef675ef96735a1442132dc645eb1d12c018620ed8cd3"
153
- dependencies = [
154
- "serde_derive",
155
- ]
156
-
157
- [[package]]
158
- name = "serde_derive"
159
- version = "1.0.114"
160
- source = "registry+https://github.com/rust-lang/crates.io-index"
161
- checksum = "2a0be94b04690fbaed37cddffc5c134bf537c8e3329d53e982fe04c374978f8e"
162
- dependencies = [
163
- "proc-macro2",
164
- "quote",
165
- "syn",
166
- ]
167
-
168
- [[package]]
169
- name = "serde_json"
170
- version = "1.0.56"
171
- source = "registry+https://github.com/rust-lang/crates.io-index"
172
- checksum = "3433e879a558dde8b5e8feb2a04899cf34fdde1fafb894687e52105fc1162ac3"
173
- dependencies = [
174
- "itoa",
175
- "ryu",
176
- "serde",
177
- ]
178
-
179
95
  [[package]]
180
96
  name = "syn"
181
97
  version = "1.0.35"
@@ -199,35 +115,21 @@ dependencies = [
199
115
  ]
200
116
 
201
117
  [[package]]
202
- name = "termcolor"
118
+ name = "tide-jsx"
203
- version = "1.1.0"
119
+ version = "0.1.0"
204
- source = "registry+https://github.com/rust-lang/crates.io-index"
205
- checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f"
206
120
  dependencies = [
121
+ "pretty_assertions",
207
- "winapi-util",
122
+ "tide-jsx-impl",
208
- ]
209
-
210
- [[package]]
211
- name = "toml"
212
- version = "0.5.6"
213
- source = "registry+https://github.com/rust-lang/crates.io-index"
214
- checksum = "ffc92d160b1eef40665be3a05630d003936a3bc7da7421277846c2613e92c71a"
215
- dependencies = [
216
- "serde",
217
123
  ]
218
124
 
219
125
  [[package]]
220
- name = "trybuild"
126
+ name = "tide-jsx-impl"
221
- version = "1.0.30"
127
+ version = "0.1.0"
222
- source = "registry+https://github.com/rust-lang/crates.io-index"
223
- checksum = "bbe777c4e2060f44d83892be1189f96200be8ed3d99569d5c2d5ee26e62c0ea9"
224
128
  dependencies = [
225
- "glob",
129
+ "proc-macro-error",
226
- "lazy_static",
130
+ "proc-macro2",
227
- "serde",
131
+ "quote",
228
- "serde_json",
229
- "termcolor",
230
- "toml",
132
+ "syn",
231
133
  ]
232
134
 
233
135
  [[package]]
@@ -258,15 +160,6 @@ version = "0.4.0"
258
160
  source = "registry+https://github.com/rust-lang/crates.io-index"
259
161
  checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
260
162
 
261
- [[package]]
262
- name = "winapi-util"
263
- version = "0.1.5"
264
- source = "registry+https://github.com/rust-lang/crates.io-index"
265
- checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
266
- dependencies = [
267
- "winapi",
268
- ]
269
-
270
163
  [[package]]
271
164
  name = "winapi-x86_64-pc-windows-gnu"
272
165
  version = "0.4.0"
Cargo.toml CHANGED
@@ -1,7 +1,17 @@
1
- [workspace]
1
+ [package]
2
+ name = "tide-jsx"
3
+ version = "0.1.0"
4
+ authors = ["Gal Schlezinger <gal@spitfire.co.il>"]
5
+ edition = "2021"
6
+ description = "A safe and simple template engine with the ergonomics of JSX"
7
+ readme = "README.md"
8
+ repository = "https://github.com/pyrossh/tide-jsx"
9
+ keywords = ["jsx", "rsx", "html", "render", "template"]
10
+ categories = ["template-engine"]
11
+ license = "MIT"
2
12
 
3
- members = [
13
+ [dependencies]
14
+ tide-jsx-impl = { path = "impl", version = "0.1.0" }
15
+
4
- "render",
16
+ [dev-dependencies]
5
- "render_macros",
6
- "render_tests",
17
+ pretty_assertions = "0.6"
7
- ]
{render_macros → impl}/Cargo.toml RENAMED
@@ -1,17 +1,15 @@
1
1
  [package]
2
- name = "render_macros"
2
+ name = "tide-jsx-impl"
3
- version = "0.3.1"
3
+ version = "0.1.0"
4
4
  authors = ["Gal Schlezinger <gal@spitfire.co.il>"]
5
5
  edition = "2021"
6
6
  description = "The macros needed for `render`"
7
7
  readme = "../README.md"
8
- repository = "https://github.com/Schniz/render.rs"
8
+ repository = "https://github.com/pyrossh/tide-jsx"
9
9
  keywords = ["macro"]
10
10
  categories = []
11
11
  license = "MIT"
12
12
 
13
- # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
14
-
15
13
  [lib]
16
14
  proc-macro = true
17
15
 
@@ -22,5 +20,5 @@ proc-macro2 = "1.0"
22
20
  proc-macro-error = "1.0"
23
21
 
24
22
  [dev-dependencies]
25
- render = { path = "../render", version = "0.3" }
23
+ #render = { path = "../render", version = "0.3" }
26
24
  pretty_assertions = "0.6"
{render_macros → impl}/src/child.rs RENAMED
File without changes
{render_macros → impl}/src/children.rs RENAMED
File without changes
{render_macros → impl}/src/element.rs RENAMED
File without changes
{render_macros → impl}/src/element_attribute.rs RENAMED
File without changes
{render_macros → impl}/src/element_attributes.rs RENAMED
File without changes
{render_macros → impl}/src/function_component.rs RENAMED
File without changes
{render_macros → impl}/src/lib.rs RENAMED
File without changes
{render_macros → impl}/src/tags.rs RENAMED
File without changes
render/Cargo.toml DELETED
@@ -1,19 +0,0 @@
1
- [package]
2
- name = "render"
3
- version = "0.3.1"
4
- authors = ["Gal Schlezinger <gal@spitfire.co.il>"]
5
- edition = "2021"
6
- description = "A safe and simple template engine with the ergonomics of JSX"
7
- readme = "../README.md"
8
- repository = "https://github.com/Schniz/render.rs"
9
- keywords = ["jsx", "rsx", "html", "render", "template"]
10
- categories = ["template-engine"]
11
- license = "MIT"
12
-
13
- # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
14
-
15
- [dependencies]
16
- render_macros = { path = "../render_macros", version = "0.3.1" }
17
-
18
- [dev-dependencies]
19
- pretty_assertions = "0.6"
render/src/lib.rs DELETED
@@ -1,179 +0,0 @@
1
- //! > 🔏 A safe and simple template engine with the ergonomics of JSX
2
- //!
3
- //! `render` itself is a combination of traits, structs and macros that together unify and
4
- //! boost the experience of composing tree-shaped data structures. This works best with HTML and
5
- //! XML rendering, but can work with other usages as well, like ReasonML's [`Pastel`](https://reason-native.com/docs/pastel/) library for terminal colors.
6
- //!
7
- //! # How?
8
- //!
9
- //! A renderable component is a struct that implements the `Render` trait. There
10
- //! are multiple macros that provide a better experience implementing Renderable:
11
- //!
12
- //! * `#[component]` for defining components using a function
13
- //! * `rsx!` for composing elements with JSX ergonomics
14
- //! * `html!` for composing elements and render them to a string
15
- //!
16
- //! # Why is this different from...
17
- //!
18
- //! ## `handlebars`?
19
- //!
20
- //! Handlebars is an awesome spec that lets us devs define templates and work
21
- //! seemlessly between languages and frameworks. Unfortunately, it does not guarantee any of Rust's
22
- //! 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.
23
- //!
24
- //! `render` provides the same level of type-safety Rust provides, with no compromises of
25
- //! ergonomics or speed.
26
- //!
27
- //! ## `typed-html`?
28
- //!
29
- //! `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.
30
- //!
31
- //! `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.
32
- //!
33
- //! # Usage
34
- //!
35
- //! ## Simple HTML rendering
36
- //!
37
- //! In order to render a simple HTML fragment into a `String`, use the `rsx!` macro to generate a
38
- //! component tree, and call `render` on it:
39
- //!
40
- //! ```rust
41
- //! # use pretty_assertions::assert_eq;
42
- //!
43
- //! use render::{rsx, Render};
44
- //!
45
- //! let tree = rsx! {
46
- //! <div>
47
- //! <h1>{"Hello!"}</h1>
48
- //! <p>{"Hello world!"}</p>
49
- //! </div>
50
- //! };
51
- //!
52
- //! assert_eq!(tree.render(), "<div><h1>Hello!</h1><p>Hello world!</p></div>");
53
- //! ```
54
- //!
55
- //! Because this is so common, there's another macro called `html!` that calls `rsx!` to generate
56
- //! a component tree, and then calls `render` on it. Most of the time, you'll find yourself using
57
- //! the `rsx!` macro to compose arbitrary components, and only calling `html!` when you need a
58
- //! String output, when sending a response or generating a Markdown file.
59
- //!
60
- //! In Render, attributes and plain strings are escaped using the `render::html_escaping` module. In order to
61
- //! use un-escaped values so you can dangerously insert raw HTML, use the `raw!` macro around your
62
- //! string:
63
- //!
64
- //! ```rust
65
- //! # use pretty_assertions::assert_eq;
66
- //!
67
- //! use render::{html, raw};
68
- //!
69
- //! let tree = html! {
70
- //! <div>
71
- //! <p>{"<Hello />"}</p>
72
- //! <p>{raw!("<Hello />")}</p>
73
- //! </div>
74
- //! };
75
- //!
76
- //! assert_eq!(tree, "<div><p>&lt;Hello /&gt;</p><p><Hello /></p></div>");
77
- //! ```
78
- //!
79
- //! ## Custom components
80
- //!
81
- //! Render's greatest ability is to provide type-safety along with custom renderable components.
82
- //! Introducing new components is as easy as defining a function that returns a `Render` value.
83
- //!
84
- //! In order to build up components from other components or HTML nodes, you can use the `rsx!`
85
- //! macro, which generates a `Render` component tree:
86
- //!
87
- //! ```rust
88
- //! # use pretty_assertions::assert_eq;
89
- //!
90
- //! use render::{component, rsx, html};
91
- //!
92
- //! #[component]
93
- //! fn Heading<'title>(title: &'title str) {
94
- //! rsx! { <h1 class={"title"}>{title}</h1> }
95
- //! }
96
- //!
97
- //! let rendered_html = html! {
98
- //! <Heading title={"Hello world!"} />
99
- //! };
100
- //!
101
- //! assert_eq!(rendered_html, r#"<h1 class="title">Hello world!</h1>"#);
102
- //! ```
103
- //!
104
- //! If you pay close attention, you see that the function `Heading` is:
105
- //!
106
- //! * declared with an uppercase. Underneath, it generates a struct with the same name, and
107
- //! implements the `Render` trait on it.
108
- //! * does not have a return type. This is because everything is written to a writer, for
109
- //! performance reasons.
110
- //!
111
- //! ### Full example
112
- //!
113
- //! ```rust
114
- //! // A simple HTML 5 doctype declaration
115
- //! use render::html::HTML5Doctype;
116
- //! use render::{
117
- //! // A macro to create components
118
- //! component,
119
- //! // A macro to compose components in JSX fashion
120
- //! rsx,
121
- //! // A macro to render components in JSX fashion
122
- //! html,
123
- //! // A trait for custom components
124
- //! Render,
125
- //! };
126
- //!
127
- //! // This can be any layout we want
128
- //! #[component]
129
- //! fn Page<'a, Children: Render>(title: &'a str, children: Children) {
130
- //! rsx! {
131
- //! <>
132
- //! <HTML5Doctype />
133
- //! <html>
134
- //! <head><title>{title}</title></head>
135
- //! <body>
136
- //! {children}
137
- //! </body>
138
- //! </html>
139
- //! </>
140
- //! }
141
- //! }
142
- //!
143
- //! // This can be a route in Rocket, the web framework,
144
- //! // for instance.
145
- //! pub fn some_page(user_name: &str) -> String {
146
- //! html! {
147
- //! <Page title={"Home"}>
148
- //! {format!("Welcome, {}", user_name)}
149
- //! </Page>
150
- //! }
151
- //! }
152
- //!
153
- //! # use pretty_assertions::assert_eq;
154
- //! # let actual = some_page("Gal");
155
- //! # let expected = concat!(
156
- //! # "<!DOCTYPE html>",
157
- //! # "<html>",
158
- //! # "<head><title>Home</title></head>",
159
- //! # "<body>",
160
- //! # "Welcome, Gal",
161
- //! # "</body>",
162
- //! # "</html>"
163
- //! # );
164
- //! # assert_eq!(actual, expected);
165
- //! ```
166
-
167
- pub mod fragment;
168
- pub mod html;
169
- pub mod html_escaping;
170
- mod numbers;
171
- mod render;
172
- mod simple_element;
173
- mod text_element;
174
-
175
- pub use self::render::Render;
176
- pub use fragment::Fragment;
177
- pub use render_macros::{component, html, rsx};
178
- pub use simple_element::SimpleElement;
179
- pub use text_element::Raw;
{render/src → src}/fragment.rs RENAMED
File without changes
{render/src → src}/html.rs RENAMED
File without changes
{render/src → src}/html_escaping.rs RENAMED
File without changes
src/lib.rs ADDED
@@ -0,0 +1,13 @@
1
+ pub mod fragment;
2
+ pub mod html;
3
+ pub mod html_escaping;
4
+ mod numbers;
5
+ mod render;
6
+ mod simple_element;
7
+ mod text_element;
8
+
9
+ pub use self::render::Render;
10
+ pub use fragment::Fragment;
11
+ pub use tide_jsx_impl::{component, html, rsx};
12
+ pub use simple_element::SimpleElement;
13
+ pub use text_element::Raw;
{render/src → src}/numbers.rs RENAMED
File without changes
{render/src → src}/render.rs RENAMED
File without changes
{render/src → src}/simple_element.rs RENAMED
File without changes
{render/src → src}/text_element.rs RENAMED
File without changes