Skip to content

Commit

Permalink
fix build tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter John committed Sep 17, 2022
1 parent cff578e commit e3c3a07
Show file tree
Hide file tree
Showing 9 changed files with 1,685 additions and 115 deletions.
1,713 changes: 1,665 additions & 48 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ categories = ["template-engine"]
license = "MIT"

[dependencies]
tide = "0.16.0"
tide-jsx-impl = { path = "impl", version = "0.2.0" }

[dev-dependencies]
pretty_assertions = "0.6"
# trybuild = "1.0.64"
async-std = { version = "1.9.0", features = ["attributes"] }
trybuild = "1.0"
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MIT License

Copyright (c) 2019 Gal Schlezinger
Copyright (c) 2022 pyrossh

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
61 changes: 5 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,10 @@
# render

> 🔏 A safe and simple template engine with the ergonomics of JSX
`render` itself is a combination of traits, structs and macros that together unify and
boost the experience of composing tree-shaped data structures. This works best with HTML and
XML rendering, but can work with other usages as well, like ReasonML's [`Pastel`](https://reason-native.com/docs/pastel/) library for terminal colors.

## How?

A renderable component is a struct that implements the `Render` trait. There
are multiple macros that provide a better experience implementing Renderable:

- `#[component]` for defining components using a function
- `rsx!` for composing elements with JSX ergonomics
- `html!` for composing elements and render them to a string

## Why is this different from...

### `handlebars`?

Handlebars is an awesome spec that lets us devs define templates and work
seemlessly between languages and frameworks. Unfortunately, it does not guarantee any of Rust's
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.

`render` provides the same level of type-safety Rust provides, with no compromises of
ergonomics or speed.

### `typed-html`?

`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.

`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.

## Usage

### Simple HTML rendering
# tide-jsx

In order to render a simple HTML fragment into a `String`, use the `rsx!` macro to generate a
component tree, and call `render` on it:

```rust
use render::{rsx, Render};
use tide_jsx::{rsx, Render};

let tree = rsx! {
<div>
Expand All @@ -62,7 +26,7 @@ use un-escaped values so you can dangerously insert raw HTML, use the `raw!` mac
string:

```rust
use render::{html, raw};
use tide_jsx::{html, raw};

let tree = html! {
<div>
Expand All @@ -83,7 +47,7 @@ In order to build up components from other components or HTML nodes, you can use
macro, which generates a `Render` component tree:

```rust
use render::{component, rsx, html};
use tide_jsx::{component, rsx, html};

#[component]
fn Heading<'title>(title: &'title str) {
Expand Down Expand Up @@ -134,20 +98,9 @@ your libraries.
#### Full example

```rust
// A simple HTML 5 doctype declaration
use render::html::HTML5Doctype;
use render::{
// A macro to create components
component,
// A macro to compose components in JSX fashion
rsx,
// A macro to render components in JSX fashion
html,
// A trait for custom components
Render,
};
use render::{component, rsx, html, Render};

// This can be any layout we want
#[component]
fn Page<'a, Children: Render>(title: &'a str, children: Children) {
rsx! {
Expand All @@ -163,8 +116,6 @@ fn Page<'a, Children: Render>(title: &'a str, children: Children) {
}
}

// This can be a route in Rocket, the web framework,
// for instance.
pub fn some_page(user_name: &str) -> String {
html! {
<Page title={"Home"}>
Expand All @@ -174,5 +125,3 @@ pub fn some_page(user_name: &str) -> String {
}

```

License: MIT
11 changes: 6 additions & 5 deletions tests/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// #[test]
// fn ui() {
// let t = trybuild::TestCases::new();
// t.compile_fail("ui/fail/*.rs");
// }
use pretty_assertions::assert_eq;
use tide_jsx::{html, rsx, component, Render, raw};
use tide_jsx::html::HTML5Doctype;
use std::borrow::Cow;

#[test]
fn ui() {
let t = trybuild::TestCases::new();
t.compile_fail("tests/ui/fail/*.rs");
}

#[test]
fn works_with_dashes() {
use pretty_assertions::assert_eq;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/fail/unclosed-tag-complex.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use render::html;
use tide_jsx::html;

fn main() {
html! {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/unclosed-tag.rs → tests/ui/fail/unclosed-tag.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fn main() {
render::html! {
tide_jsx::html! {
<ul>
<li>
</ul>
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/fail/unclosed-tag.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: Expected closing tag for: <li>
--> $DIR/unclosed-tag.rs:7:9
--> tests/ui/fail/unclosed-tag.rs:5:9
|
7 | </ul>
5 | </ul>
| ^^
2 changes: 1 addition & 1 deletion tests/ui/fail/unexpected-attribute.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use render::{component, html, rsx};
use tide_jsx::{component, html, rsx};

#[component]
fn Heading<'title>(title: &'title str) {
Expand Down

0 comments on commit e3c3a07

Please sign in to comment.