Crate unreact

Source
Expand description

§Unreact

Unreact is a simple static site generation framework

§Quick Start

See also: examples and unreact template

Create an site with a single index page

use unreact::prelude::*;

fn main() -> Result<(), Error> {
   // Create the app
   // Using default config, not in dev mode, and an example url
   let mut app = Unreact::new(Config::default(), false, "https://example.com")?;
   // Create an index route
   // This uses the template 'page.hbs' in 'templates/'
   // A json object with a value for 'foo' is passed into the template
   app.index("page", object! { foo: "World!" });
   // Compile it!
   app.run()
}

Your workspace should look something like this:

unreact-app/
  ├─ Cargo.toml
  ├─ src/
  │  └─ main.rs
  │
  └─ assets/
     ├─ templates/
     │  └─ page.hbs
     │
     ├─ styles/
     └─ public/

This is the contents of assets/templates/page.hbs:

<h1> Hello {{foo}} </h1>

This will render build/index.html:

<h1> Hello World! </h1>

A larger project could look something like this:

unreact-app/
  ├─ Cargo.toml
  ├─ src/
  │  └─ main.rs
  │
  └─ assets/
     ├─ templates/
     │  ├─ boilerplate.hbs
     │  ├─ hello.hbs
     │  ├─ other/
     │  │  ├─ another/
     │  │  │  └─ something.hbs
     │  │  └─ article.hbs
     │  └─ page.hbs
     │
     ├─ styles/
     │  ├─ global.scss
     │  └─ scoped/
     │     └─ stylish.scss
     │
     └─ public/
        └─ favicon.ico

Re-exports§

pub use handlebars;

Modules§

prelude
Prelude for Unreact

Macros§

json
Construct a serde_json::Value from a JSON literal.
object
Create a json-like ‘object’: A map of string keys to json values

Structs§

Config
Configuration struct for Unreact
Unreact
Unreact app

Enums§

Error
Error type for Unreact
IoError
Error type for Unreact, relating to IO fails
Value
Represents any valid JSON value.

Functions§

is_dev
Check if --dev or -d argument was passed on cargo run

Type Aliases§

Object
Represents json-like object A map of string keys to json values