sauron 0.7.0

An html library for building client side webapps
docs.rs failed to build sauron-0.7.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: sauron-0.61.8

sauron

Latest Version Build Status MIT licensed

sauron

   One crate to rule the DOM
   One crate to find the elements
   One crate to bring JSON
   And in the Rust code bind Strings

   This code, no other, is made by code elves
   Who'd pawn parent process to get it themselves
   Ruler of net troll and mortal and hacker
   This code is a lib crate for Patreon backers
   If trashed or buggy it cannot be remade
   If found send to Ivan, the bandwidth is prepaid

Sauron is an html web framework for building web-apps with the goal to closely adhere to The Elm Architecture, A true king for elegant design.

As with elm, sauron don't use macro to provide the view, instead just uses plain rust function calls to construct the view.

Example

use sauron::html::attributes::*;
use sauron::html::events::*;
use sauron::html::*;
use sauron::Component;
use sauron::Node;
use sauron::Program;
use wasm_bindgen::prelude::*;

#[derive(Debug, Clone)]
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> {
        div(
            [class("some-class"), id("some-id"), attr("data-id", 1)],
            [
                input(
                    [
                        class("client"),
                        r#type("button"),
                        value("Click me!"),
                        onclick(|_| {
                            sauron::log("Button is clicked");
                            Msg::Click
                        }),
                    ],
                    [],
                ),
                text(format!("Clicked: {}", self.click_count)),
            ],
        )
    }

    fn update(&mut self, msg: Msg) {
        sauron::log!("App is updating from msg: {:?}", msg);
        match msg {
            Msg::Click => self.click_count += 1,
        }
    }

}

#[wasm_bindgen(start)]
pub fn main() {
    Program::new_append_to_mount(App::new(), &sauron::body());
}

index.html

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

Build using

$> wasm-pack build --target no-modules

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

Warning: You need to use the latest nightly compiler in order for this to work.

Prerequisite:

cargo install wasm-pack
cargo install basic-http-server
  • TIP: Use indent_style = "Visual"in your rustfmt.toml This will visually align the view function in your code, which gives it a more pleasant semantic look

This project is based on the existing projects:

Performance: Is not too bad.

Benchmark

Please support this project:

Become a patron

Personal plug:

I'm actively looking for a job that has to do with rust. Please contact me: ivanceras[at]gmail.com

License: MIT