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 for
Unreact
Macros
- Construct a
serde_json::Value
from a JSON literal. - Create a json-like ‘object’: A map of string keys to json values
Structs
- Configuration struct for
Unreact
- Unreact app
Enums
- Error type for
Unreact
- Error type for
Unreact
, relating to IO fails - Represents any valid JSON value.
Functions
- Check if
--dev
or-d
argument was passed oncargo run
Type Definitions
- Represents json-like object A map of string keys to json values