Skip to content

Latest commit

 

History

History
88 lines (64 loc) · 2.2 KB

README.md

File metadata and controls

88 lines (64 loc) · 2.2 KB

Borealis

Build Status

Borealis is a templating engine for HTML5 written in Rust.

Documents

// Enable compiler plugins. Note that this only works in nightly.
#![feature(plugin)]
#![plugin(borealis_codegen)]

// Let the plugin derive `SerializeDocument` for us.
#[template_document(file="template.html")]
struct Template {
    value: String,
}

The template file needs to be in the same directory as the code file.

<!DOCTYPE html>
<html>
    <body>
        {{ self.value }}
    </body>
</html>

You can now call borealis::serializer::serialize on a Template to serialize it to a writer.

use borealis::serializer;

// Create a buffer which we can write too.
// Normally this would be a TCP stream or similar.
let mut writer: Vec<u8> = Vec::new();

// Create a new template.
let template = Template {
    value: "test".into(),
};

// Turn it into a document and serialize it into our buffer.
serializer::serialize(&mut writer, template);

Fragments

#![feature(plugin)]
#![plugin(borealis_codegen)]

#[template_fragment(file="template.html", trim)]
struct Template {
    value: u32,
}

The trim flag means that the plugin will trim any whitespace before parsing the fragment file. (This is done using String::trim) This can be useful if your editor inserts an extra newline at the end of files.

As with the document template, the file needs to be in the same directory as the code.

<ul>
    {{ (0..self.value).map(|v| format!("{}", v)) }}
</ul>

The fragment can now be used inside another fragment or document.

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.