Skip to content

HTML5 template engine for Rust.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

martinrlilja/borealis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

HTML5 template engine for Rust.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages