#html #dom #web

sauron-core

An html library for building client side webapps

11 unstable releases (3 breaking)

new 0.33.0 Nov 27, 2020
0.32.6 Nov 1, 2020
0.32.5 Oct 26, 2020
0.32.1 Sep 22, 2020
0.30.1 Aug 15, 2020

#34 in Template engine

Download history 25/week @ 2020-08-11 12/week @ 2020-08-18 12/week @ 2020-08-25 38/week @ 2020-09-01 73/week @ 2020-09-08 159/week @ 2020-09-15 61/week @ 2020-09-22 41/week @ 2020-09-29 75/week @ 2020-10-06 92/week @ 2020-10-13 113/week @ 2020-10-20 109/week @ 2020-10-27 130/week @ 2020-11-03 62/week @ 2020-11-10 63/week @ 2020-11-17 89/week @ 2020-11-24

355 downloads per month
Used in 7 crates (3 directly)

MIT license

250KB
6.5K SLoC

Maintenance

sauron

Latest Version Build Status MIT licensed

sauron

Guide

Sauron is an web framework for creating fast and interactive client side web application, as well as server-side rendering for back-end web applications.

Example

use log::trace;
use sauron::html::attributes::attr;
use sauron::html::text;
use sauron::prelude::*;
use sauron::{Cmd, Component, Node, Program};

#[derive(Debug)]
pub enum Msg {
    Click,
}

pub struct App {
    click_count: u32,
}

impl App {
    pub fn new() -> Self {
        App { click_count: 0 }
    }
}

impl Component<Msg> for App {
    fn view(&self) -> Node<Msg> {
        node! {
            <main>
                <h1>"Minimal example"</h1>
                <div class="some-class" id="some-id" {attr("data-id", 1)}>
                    <input class="client"
                            type="button"
                            value="Click me!"
                            key=1
                            on_click={|_| {
                                trace!("Button is clicked");
                                Msg::Click
                            }}
                    />
                    <div>{text(format!("Clicked: {}", self.click_count))}</div>
                    <input type="text" value={self.click_count}/>
                </div>
            </main>
        }
    }

    fn update(&mut self, msg: Msg) -> Cmd<Self, Msg> {
        trace!("App is updating with msg: {:?}", msg);
        match msg {
            Msg::Click => self.click_count += 1,
        }
        Cmd::none()
    }
}

#[wasm_bindgen(start)]
pub fn main() {
    console_log::init_with_level(log::Level::Trace).unwrap();
    console_error_panic_hook::set_once();
    Program::mount_to_body(App::new());
}

index.html

<html>
  <head>
    <meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
    <title>Minimal sauron app</title>
  </head>
  <body>
    <script type=module>
        import init from './pkg/minimal.js';
        init().catch(console.error);
    </script>
  </body>
</html>

In Cargo.toml, specify the crate-type to be cdylib


[package]
name = "minimal"
version = "0.1.0"
edition = "2018"

[lib]
crate-type = ["cdylib"]


[dependencies]
sauron = "0.33"
console_error_panic_hook = "0.1"
log = "0.4"
console_log = "0.2"

Build using

$> wasm-pack build --target web --release

Look at the examples and the build script for the details.

Demo examples

  • todomvc The todomvc example
  • futuristic-ui - A demo of futuristic-ui showcasing animation, transition and timed Component update.
  • data-viewer - A resizable spreadsheet CSV data viewer
  • svg-clock - A clock drawn using SVG and window tick event.
  • svg-graph - A simple graph using SVG
  • code-editor - A WIP web-base code-editor

Converting HTML into Sauron's syntax

html2sauron - A tool to easily convert html into sauron node tree for your views.

Prerequisite:

cargo install wasm-pack
cargo install basic-http-server

Performance:

Sauron is one of the fastest.

Benchmark Benchmark

Run the benchmark yourself:

Benchmark 1 Benchmark 2

Please support this project:

Become a patron

License: MIT

Dependencies

~1.4–4MB
~83K SLoC