~repos /tide-jsx

#rust#proc-macro#jsx

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

Tide + JSX


0e72dd99 Peter John

3 years ago
v0.1.1
impl/Cargo.lock ADDED
@@ -0,0 +1,147 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 3
4
+
5
+ [[package]]
6
+ name = "ansi_term"
7
+ version = "0.11.0"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
10
+ dependencies = [
11
+ "winapi",
12
+ ]
13
+
14
+ [[package]]
15
+ name = "ctor"
16
+ version = "0.1.23"
17
+ source = "registry+https://github.com/rust-lang/crates.io-index"
18
+ checksum = "cdffe87e1d521a10f9696f833fe502293ea446d7f256c06128293a4119bdf4cb"
19
+ dependencies = [
20
+ "quote",
21
+ "syn",
22
+ ]
23
+
24
+ [[package]]
25
+ name = "difference"
26
+ version = "2.0.0"
27
+ source = "registry+https://github.com/rust-lang/crates.io-index"
28
+ checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198"
29
+
30
+ [[package]]
31
+ name = "output_vt100"
32
+ version = "0.1.3"
33
+ source = "registry+https://github.com/rust-lang/crates.io-index"
34
+ checksum = "628223faebab4e3e40667ee0b2336d34a5b960ff60ea743ddfdbcf7770bcfb66"
35
+ dependencies = [
36
+ "winapi",
37
+ ]
38
+
39
+ [[package]]
40
+ name = "pretty_assertions"
41
+ version = "0.6.1"
42
+ source = "registry+https://github.com/rust-lang/crates.io-index"
43
+ checksum = "3f81e1644e1b54f5a68959a29aa86cde704219254669da328ecfdf6a1f09d427"
44
+ dependencies = [
45
+ "ansi_term",
46
+ "ctor",
47
+ "difference",
48
+ "output_vt100",
49
+ ]
50
+
51
+ [[package]]
52
+ name = "proc-macro-error"
53
+ version = "1.0.4"
54
+ source = "registry+https://github.com/rust-lang/crates.io-index"
55
+ checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
56
+ dependencies = [
57
+ "proc-macro-error-attr",
58
+ "proc-macro2",
59
+ "quote",
60
+ "syn",
61
+ "version_check",
62
+ ]
63
+
64
+ [[package]]
65
+ name = "proc-macro-error-attr"
66
+ version = "1.0.4"
67
+ source = "registry+https://github.com/rust-lang/crates.io-index"
68
+ checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
69
+ dependencies = [
70
+ "proc-macro2",
71
+ "quote",
72
+ "version_check",
73
+ ]
74
+
75
+ [[package]]
76
+ name = "proc-macro2"
77
+ version = "1.0.43"
78
+ source = "registry+https://github.com/rust-lang/crates.io-index"
79
+ checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab"
80
+ dependencies = [
81
+ "unicode-ident",
82
+ ]
83
+
84
+ [[package]]
85
+ name = "quote"
86
+ version = "1.0.21"
87
+ source = "registry+https://github.com/rust-lang/crates.io-index"
88
+ checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179"
89
+ dependencies = [
90
+ "proc-macro2",
91
+ ]
92
+
93
+ [[package]]
94
+ name = "syn"
95
+ version = "1.0.99"
96
+ source = "registry+https://github.com/rust-lang/crates.io-index"
97
+ checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13"
98
+ dependencies = [
99
+ "proc-macro2",
100
+ "quote",
101
+ "unicode-ident",
102
+ ]
103
+
104
+ [[package]]
105
+ name = "tide-jsx-impl"
106
+ version = "0.1.0"
107
+ dependencies = [
108
+ "pretty_assertions",
109
+ "proc-macro-error",
110
+ "proc-macro2",
111
+ "quote",
112
+ "syn",
113
+ ]
114
+
115
+ [[package]]
116
+ name = "unicode-ident"
117
+ version = "1.0.4"
118
+ source = "registry+https://github.com/rust-lang/crates.io-index"
119
+ checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd"
120
+
121
+ [[package]]
122
+ name = "version_check"
123
+ version = "0.9.4"
124
+ source = "registry+https://github.com/rust-lang/crates.io-index"
125
+ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
126
+
127
+ [[package]]
128
+ name = "winapi"
129
+ version = "0.3.9"
130
+ source = "registry+https://github.com/rust-lang/crates.io-index"
131
+ checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
132
+ dependencies = [
133
+ "winapi-i686-pc-windows-gnu",
134
+ "winapi-x86_64-pc-windows-gnu",
135
+ ]
136
+
137
+ [[package]]
138
+ name = "winapi-i686-pc-windows-gnu"
139
+ version = "0.4.0"
140
+ source = "registry+https://github.com/rust-lang/crates.io-index"
141
+ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
142
+
143
+ [[package]]
144
+ name = "winapi-x86_64-pc-windows-gnu"
145
+ version = "0.4.0"
146
+ source = "registry+https://github.com/rust-lang/crates.io-index"
147
+ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
impl/src/element.rs CHANGED
@@ -55,7 +55,7 @@ impl ToTokens for Element {
55
55
  let attrs = self.attributes.for_simple_element();
56
56
  let children_tuple = self.children.as_option_of_tuples_tokens();
57
57
  quote! {
58
- ::render::SimpleElement {
58
+ tide_jsx::SimpleElement {
59
59
  tag_name: stringify!(#name),
60
60
  attributes: #attrs,
61
61
  contents: #children_tuple,
impl/src/function_component.rs CHANGED
@@ -44,13 +44,13 @@ pub fn create_function_component(f: syn::ItemFn) -> TokenStream {
44
44
  #[derive(Debug)]
45
45
  #vis struct #struct_name #impl_generics #inputs_block
46
46
 
47
- impl #impl_generics ::render::Render for #struct_name #ty_generics #where_clause {
47
+ impl #impl_generics tide_jsx::Render for #struct_name #ty_generics #where_clause {
48
48
  fn render_into<W: std::fmt::Write>(self, w: &mut W) -> std::fmt::Result {
49
49
  let result = {
50
50
  #inputs_reading
51
51
  #block
52
52
  };
53
- ::render::Render::render_into(result, w)
53
+ tide_jsx::Render::render_into(result, w)
54
54
  }
55
55
  }
56
56
  })
impl/src/lib.rs CHANGED
@@ -14,106 +14,11 @@ use proc_macro_error::proc_macro_error;
14
14
  use quote::quote;
15
15
  use syn::parse_macro_input;
16
16
 
17
- /// Render a component tree to an HTML string, using XML-like tags.
18
- ///
19
- /// The ergonomics are based on JSX:
20
- ///
21
- /// ### Simple HTML elements start with a lowercase
22
- ///
23
- /// ```rust
24
- /// # use pretty_assertions::assert_eq;
25
- /// # use render_macros::html;
26
- /// let rendered = html! { <div id={"main"}>{"Hello"}</div> };
27
- /// assert_eq!(rendered, r#"<div id="main">Hello</div>"#);
28
- /// ```
29
- ///
30
- /// ### Custom components start with an uppercase
31
- ///
32
- /// ```rust
33
- /// # use pretty_assertions::assert_eq;
34
- /// # use render_macros::{html, rsx};
35
- /// use render::Render;
36
- ///
37
- /// #[derive(Debug)]
38
- /// struct Heading<'t> { title: &'t str }
39
- ///
40
- /// impl<'t> Render for Heading<'t> {
41
- /// fn render_into<W: std::fmt::Write>(self, writer: &mut W) -> std::fmt::Result {
42
- /// Render::render_into(rsx! { <h1>{self.title}</h1> }, writer)
43
- /// }
44
- /// }
45
- ///
46
- /// let rendered = html! { <Heading title={"Hello world!"} /> };
47
- ///
48
- /// assert_eq!(rendered, r#"<h1>Hello world!</h1>"#);
49
- /// ```
50
- ///
51
- /// ### Values are always surrounded by curly braces
52
- ///
53
- /// ```rust
54
- /// # use render_macros::html;
55
- /// # use pretty_assertions::assert_eq;
56
- /// let rendered = html! {
57
- /// <div id={"main"} />
58
- /// };
59
- ///
60
- /// assert_eq!(rendered, r#"<div id="main"/>"#);
61
- /// ```
62
- ///
63
- /// ### HTML entities can accept dashed-separated value
64
- ///
65
- /// ```rust
66
- /// # use render_macros::html;
67
- /// # use pretty_assertions::assert_eq;
68
- /// let rendered = html! {
69
- /// <div data-testid={"sometestid"} />
70
- /// };
71
- ///
72
- /// assert_eq!(rendered, r#"<div data-testid="sometestid"/>"#);
73
- /// ```
74
- ///
75
- /// ### Custom components can't accept dashed-separated values
76
- ///
77
- /// ```compile_fail
78
- /// # use render_macros::html;
79
- /// // This will fail the compilation:
80
- /// let rendered = html! {
81
- /// <MyElement data-testid={"some test id"} />
82
- /// };
83
- /// ```
84
- ///
85
- /// ### Punning is supported
86
- /// but instead of expanding to `value={true}`, it expands to
87
- /// `value={value}` like Rust's punning
88
- ///
89
- /// ```rust
90
- /// # use render_macros::html;
91
- /// # use pretty_assertions::assert_eq;
92
- /// let class = "someclass";
93
- ///
94
- /// let rendered = html! {
95
- /// <div class />
96
- /// };
97
- ///
98
- /// assert_eq!(rendered, r#"<div class="someclass"/>"#);
99
- /// ```
100
- ///
101
- /// ### Punning is not supported for dashed-delimited attributes
102
- ///
103
- /// ```compile_fail
104
- /// # use render_macros::html;
105
- ///
106
- /// let rendered = html! {
107
- /// <div this-wont-work />
108
- /// };
109
- ///
110
- /// assert_eq!(rendered, r#"<div class="some_class"/>"#);
111
- /// ```
112
17
  #[proc_macro]
113
18
  #[proc_macro_error]
114
19
  pub fn html(input: TokenStream) -> TokenStream {
115
20
  let el = proc_macro2::TokenStream::from(rsx(input));
116
- let result = quote! { ::render::Render::render(#el) };
21
+ let result = quote! { ::tide_jsx::Render::render(#el) };
117
22
  TokenStream::from(result)
118
23
  }
119
24
 
@@ -126,52 +31,6 @@ pub fn rsx(input: TokenStream) -> TokenStream {
126
31
  TokenStream::from(result)
127
32
  }
128
33
 
129
- /// A syntactic sugar for implementing [`Render`](../render/trait.Render.html) conveniently
130
- /// using functions.
131
- ///
132
- /// This attribute should be above a stand-alone function definition that returns a
133
- /// [`String`](std::string::String):
134
- ///
135
- /// ```rust
136
- /// # use render_macros::{component, rsx};
137
- /// #
138
- /// #[component]
139
- /// fn UserFn(name: String) {
140
- /// rsx! { <div>{format!("Hello, {}", name)}</div> }
141
- /// }
142
- /// ```
143
- ///
144
- /// Practically, this is exactly the same as using the [Render](../render/trait.Render.html) trait:
145
- ///
146
- /// ```rust
147
- /// # use render_macros::{component, rsx, html};
148
- /// # use render::Render;
149
- /// # use pretty_assertions::assert_eq;
150
- /// #
151
- /// #[derive(Debug)]
152
- /// struct User { name: String }
153
- ///
154
- /// impl render::Render for User {
155
- /// fn render_into<W: std::fmt::Write>(self, writer: &mut W) -> std::fmt::Result {
156
- /// Render::render_into(rsx! { <div>{format!("Hello, {}", self.name)}</div> }, writer)
157
- /// }
158
- /// }
159
- ///
160
- /// # #[component]
161
- /// # fn UserFn(name: String) {
162
- /// # rsx! { <div>{format!("Hello, {}", name)}</div> }
163
- /// # }
164
- /// #
165
- /// # let from_fn = html! {
166
- /// # <UserFn name={String::from("Schniz")} />
167
- /// # };
168
- /// #
169
- /// # let from_struct = html! {
170
- /// # <User name={String::from("Schniz")} />
171
- /// # };
172
- /// #
173
- /// # assert_eq!(from_fn, from_struct);
174
- /// ```
175
34
  #[proc_macro_attribute]
176
35
  #[proc_macro_error]
177
36
  pub fn component(_attr: TokenStream, item: TokenStream) -> TokenStream {
impl/src/tags.rs CHANGED
@@ -12,7 +12,7 @@ pub struct OpenTag {
12
12
  }
13
13
 
14
14
  fn name_or_fragment(maybe_name: Result<syn::Path>) -> syn::Path {
15
- maybe_name.unwrap_or_else(|_| syn::parse_str::<syn::Path>("::render::Fragment").unwrap())
15
+ maybe_name.unwrap_or_else(|_| syn::parse_str::<syn::Path>("tide_jsx::Fragment").unwrap())
16
16
  }
17
17
 
18
18
  fn is_custom_element_name(path: &syn::Path) -> bool {
src/fragment.rs CHANGED
@@ -1,22 +1,7 @@
1
- //! The fragment component
2
1
 
3
2
  use crate::Render;
4
3
  use std::fmt::{Result, Write};
5
4
 
6
- /// A top-level root component to combine a same-level components
7
- /// in a RSX fashion
8
- ///
9
- /// ```rust
10
- /// # use pretty_assertions::assert_eq;
11
- /// # use render_macros::html;
12
- /// let result = html! {
13
- /// <>
14
- /// <a />
15
- /// <b />
16
- /// </>
17
- /// };
18
- /// assert_eq!(result, "<a/><b/>");
19
- /// ```
20
5
  #[derive(Debug)]
21
6
  pub struct Fragment<T: Render> {
22
7
  pub children: T,
src/html.rs CHANGED
@@ -1,25 +1,6 @@
1
- //! HTML utilities
2
-
3
1
  use crate::Render;
4
2
  use std::fmt::{Result, Write};
5
3
 
6
- /// HTML 5 doctype declaration
7
- ///
8
- /// ```rust
9
- /// # use pretty_assertions::assert_eq;
10
- /// # use render::html::HTML5Doctype;
11
- /// # use render::html;
12
- /// # let result =
13
- /// html! {
14
- /// <>
15
- /// <HTML5Doctype />
16
- /// <html>
17
- /// <body />
18
- /// </html>
19
- /// </>
20
- /// };
21
- /// # assert_eq!(result, "<!DOCTYPE html><html><body/></html>");
22
- /// ```
23
4
  #[derive(Debug)]
24
5
  pub struct HTML5Doctype;
25
6
 
src/html_escaping.rs CHANGED
@@ -1,15 +1,5 @@
1
1
  use std::fmt::{Result, Write};
2
2
 
3
- /// Simple HTML escaping, so strings can be safely rendered.
4
- ///
5
- /// ```rust
6
- /// # use pretty_assertions::assert_eq;
7
- /// # use render::html_escaping;
8
- ///
9
- /// let mut buf = String::new();
10
- /// html_escaping::escape_html(r#"<hello world="attribute" />"#, &mut buf).unwrap();
11
- /// assert_eq!(buf, "&lt;hello world=&quot;attribute&quot; /&gt;");
12
- /// ```
13
3
  pub fn escape_html<W: Write>(html: &str, writer: &mut W) -> Result {
14
4
  for c in html.chars() {
15
5
  match c {
src/numbers.rs CHANGED
@@ -1,5 +1,3 @@
1
- //! Render impls for numeric primitives
2
-
3
1
  use crate::Render;
4
2
  use std::fmt::{Result, Write};
5
3